3 ms·
The Use requirement is related to Go's refusal to have compiler warnings. It is a well-intentioned step in the wrong direction, overtaking even Bondage and Disc
by Evbn 14y ago
The Use requirement is related to Go's refusal to have compiler warnings. It is a well-intentioned step in the wrong direction, overtaking even Bondage and Discipline languages. Haskell's GHC just addded a flag to make type errors warnings!
The closures capturing references thing is a big design bug. If a programmer wants a to share a reference, he has the & operator.
- cmccabe 14y agoYeah, the use requirement is annoying. It would really be nice if there were a way to make that check optional. As far as closures capturing references-- if closures captured by value rather than by reference, how would maps and slices be handled? Anywhere the closure used one of those items, it would have to be deep-copied-- a potentially slow operation. Even deep-copying structures could get expensive. The worst part would be that this cost would be hidden to the programmer, who would wonder why his code got so slow all the sudden. I think having them capture references is the only reasonable design given the other design choices.
- akkartik 14y agoCopy on write, maybe?
- tomp 14y agoI don't think it's a design bug. Personally, I would prefer if for each iteration of the for loop, the variables were fresh, so that even if they were captured by reference, they would be different references. So, you would be able to do: l = []; for i = 1 .. 10 { f = () -> { i += 1; } g = () -> { return i; } l.append({adder: f, getter: g}); } This would also play nice with loop unrolling. If the programmer wants a variable that is shared between the iteration of the for loop, the declaration should be outside the loop.