Re:Golang landmines
by Vendan on Saturday September 17, 2016 @09:31PM
(#12523483)
People coming from highly dynamic languages, like python and such, most likely
[ Parent
| on HN ]
How would this make any sense, though? In the case of "range" I can see the confusion, but when you explicitly declare a variable and increment it for each iteration of the loop, the only way it can work is if there's one instance of the variable.
It's the disparity between how a human thinks and how a machine thinks. Systems languages tend to care less about humans think, which I prefer because humans don't have consistently defined logic.
I don't think so. As programmers, we have to think logically, and in this situation there really is no other logical way of thinking about how that code might work.
Only C and its direct descendants.
There are saner alternatives, more human friendly, to systems programming.
Python's behavior is the same as Go's. For example, this code:
l = []
for i in xrange(3):
l.append(lambda: i)
print [f() for f in l]
prints [2, 2, 2].