News for hackers. Stuff that matters.
Re:Anti-If: The missing patterns (2016) by reificator on Wednesday June 27, 2018 @04:09PM (#17411377)
Golang's defer statement gives some of that power, (and some extra guarantees) but doesn't as far as I know allow return statements.

You can however give named return values and reference those names, and I believe it will work.

I've not seen any other constructs in any language that would come close, and I still maintain `goto fail` is a reasonable construct.

Re:Anti-If: The missing patterns (2016) by mjevans on Wednesday June 27, 2018 @05:53PM (#17412153)
Deferred statements (in go) are really useful for delaying the runtime of blocks of code to the end of a context, but leaving them in the logical context where you're setting up a resource.

I'm actually not sure offhand how multiple deferred statements are handled. I could envision that the specification might make no explicit guarantee about the runtime order or it might create and pop off of a stack (at least in behavior).

Re:Anti-If: The missing patterns (2016) by sago on Wednesday June 27, 2018 @06:08PM (#17412283)
Thank you. For clarity, here would be the GP example:

   Foo foo = acquireFoo()
   defer releaseFoo(foo)

   if !isValid(foo) {
      return FAIL
   }

   moreWork(foo)
   return SUCCESS
That is impressively clear. I don't use go, myself.

I agree, I am quite comfortable using goto in C/C++ in this context. Though it may be better in C++ to use RAII in this specific example.