3 ms·
Thanks for the example. In all my life I never actually wanted to do something like this, but well... It's neat that go allows this.
by zubspace 7y ago
Thanks for the example. In all my life I never actually wanted to do something like this, but well... It's neat that go allows this.
- naikrovek 7y agoYou will if you ever do concurrency stuff in go. The way goroutines capture their working variables in a closure make things like `x := x` useful and clear (once you know why you do it in the first place )
- zemo 7y agothat's likely not true. Every time you do this: if err := fn(); err != nil { } // the result of fn does not affect the identifier err // in the enclosing scope you're scoping err just to that if block. that's ... just about the most common phrase in all of Go. it won't affect any err defined prior and it won't exist outside of the if block. You'd have to do this to make the value stick around or affect the enclosing block: var err error if err = fn(); err != nil { } // err has the result of fn here