2 ms·
Yeah, so what my "problem" is is that in the code item := item item := item the two lines doing different things even though looking exactly the same.
by valenterry 4y ago
Yeah, so what my "problem" is is that in the code
item := item
item := item
the two lines doing different things even though looking exactly the same.
I'm a Scala dev and in Scala we have a similar thing, where a new import or definition in the middle of the code can change line semantics between two equal lines.
But the difference is that this is not a mistake but a concious design to switch "contexts" and is heavily guarded by the typesystem, where GOs typesystem is incredibly weak in comparison, which is not an inherent drawback, but here it is.
I do feel that I'll stick to my feelings that this design is confusing and should have been avoided from the beginning. Ku
udos to the go team for breaking compatibility here. This is necessary for a language to not become another COBOL.
- ithkuil 4y agoThis code is illegal in Go item := item item := item "no new variables on left side of :=" You can't declare the same variable twice in the same scope. item := item works only because it declares a new variable in the current scope, initialized with a variable with the same name (but different variable) from the outer scope. Go distinguishes declarations from assignments. In this example, the second assignment is a no-op indeed. item := item item = item
- valenterry 4y agoOkay fair enough, thx for the explanation. Doesn't make it good, but better!