Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's readable if you're familiar with the RAII pattern which is used in languages like C++ and Go.


It's also similar to C#'s "using ...;" without a block. Syntax sugar there rather than RAII, but looks the same.


C#'s using can be used without a block. It disposes the resource at the end of a current scope.


I always felt that pattern was a bit too clever than it was a good design.


Makes me wonder what part of the pattern you think is "too clever"? I think it is fairly easy to reason about when the lock is restricted to the encompassing block and automatically dropped when you leave the block.


It’s kind of a weird design that some of your variables (which you can define anywhere in the scope FWIW) just randomly define a critical section. I strongly prefer languages that do a

  with lock {
      // do stuff 
  }
design. This could be C++ too to be honest because lambdas exist but RAII is just too common for people to design their locks like this.


Well, Go doesn't quite support RAII.

This syntax looks more like Python or Rust.


It's not RAII, but closer to dynamic-wind.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: