News for hackers. Stuff that matters.
Re:Golang landmines by catnaroek on Sunday September 18, 2016 @05:01AM (#12524505)
The problem isn't shadowing. The problem is capturing by reference. It's utterly confusing, because it means that all closures that you create in the same environment share the same mutable state - delicious action at a distance!

Languages where closures capture by value (ML, Haskell) or where the programmer explicitly chooses between capturing by value and by reference (C++, Rust) are free of these complications.

Re:Golang landmines by eternalban on Sunday September 18, 2016 @12:19PM (#12525848)
That terminal '}()' is there for a reason.

https://play.golang.org/p/zyMbmJsnUz // minor mod of donatj's example.

Re:Golang landmines by catnaroek on Sunday September 18, 2016 @01:35PM (#12526185)
This is reminiscent of the common Python hack `lambda n=n: whatever`. Well, it's a hack.
Re:Golang landmines by Peaker on Sunday September 18, 2016 @03:33PM (#12526774)
Haskell doesn't necessarily capture by value or by reference since you cannot distinguish between the two when all values are immutable.
Re:Golang landmines by catnaroek on Sunday September 18, 2016 @03:36PM (#12526786)
When I say ”by value”, I mean the abstraction the programmer is exposed to, not the internal implementation detail. In a Haskell implementation, the environment may well be internally represented as a pointer, but the programmer doesn't need to worry about that. On the other hand, a Go, Python or Lisp programmer is constantly and painfully reminded of the difference between copying an object and pointing to a pre-existing object.
Re:Golang landmines by Peaker on Sunday September 18, 2016 @03:47PM (#12526845)
Haskell programmers do have to think about it as being by-reference if they want to understand the performance/memory-use due to sharing.

But for correctness, yeah, you just don't have to think about it. So you don't think "by value" or "by reference", it just becomes something obvious that you don't need to think about.

Re:Golang landmines by catnaroek on Sunday September 18, 2016 @03:49PM (#12526856)
> Haskell programmers do have to think about it as being by-reference if they want to understand the performance/memory-use due to sharing.

Oh, right.