8 ms·
If the change /doesn't/ break old code, it's also poorly justified. It means code doesn't care about the issue being addressed. The feature is only justified
by kazinator 3y ago
If the change /doesn't/ break old code, it's also poorly justified.
It means code doesn't care about the issue being addressed.
The feature is only justified if it changes existing code, such that bugs you didn't even know about are fixed.
I.e. people read about the issue, investigate their code bases and go, oh hey, we actually have a latent bug here which the change will fix.
- esrauch 3y agoNew code written today will use the new version and have the correct behavior from day 1. Old code that is maintained will eventually be upgraded, which yes does come with work sometimes where you realize your code works on version X but not version X+10 and you do a combination of tests and reading patch notes to see what changed.
- kazinator 3y agoThere is no "correct" behavior here; either one is a valid choice that can be documented and that programs can rely on and exploit. Code doesn't care about when it's written, only what you run it on, and with what compatibility options. E.g. one possibility is that ten-year-old code that wrongly assumed the opposite behavior, and has a bug, will start to work correctly on the altered implementation.
- jjnoakes 3y agoThere's a second motivation in my opinion. Code might work today without the change, but it could be because the author originally wrote buggy code, caught it in testing, and had to waste time tracking it down and understanding nuances that don't need to be there. Once they figured that out, they implemented an ugly workaround (adding an extra function parameter to a goroutine or shadowing the loop variable with n := n). Good language designers want to avoid both wasting developer's time and requiring ugly workarounds. Making a change that does both, especially if it doesn't break old code, is great imo.
- kazinator 3y agoWhichever way you implement the semantics of the loop variable, the developer has to understand the nuances, don't you think? And those nuances have to be there; all you can do is replace them with other nuances. If a fresh variable i is bound for each iteration, then an i++ statement in the body will not have the intended effect of generating an extra increment that skips an iteration. If you want the other semantics, whichever one that is, the workaround is ugly.
- jjnoakes 3y agoI think you can choose nuances that minimize unexpected behavior in practice, and I think the go team did a good job here.