3 ms·
When I first started programming (this was in C++), I decided that the obvious optimisation was to declare all these redundant local indices i,j,k as globals. T
by tgb 9y ago
When I first started programming (this was in C++), I decided that the obvious optimisation was to declare all these redundant local indices i,j,k as globals. Then the program won't need to make all this redundant crap! Of course that led to absurdly subtle bugs that only occasionally showed up since whenever I called a function which had a loop in it from inside of another loop, I would use i as the index for both loops. Error! I learned several important lessons when I figured that one out.
But now the author here says they're doing that same thing! How has this not inevitably led to problems? Or am I misunderstanding the scoping in Java?
- MetallicCloud 9y agoI'm sure it would have lead to problems, that's just one of the examples of beginner mistakes with the code. That's kind of the point of this post, for the author to poke fun at themselves for the number of newbie mistakes they made.
- raxod502 9y agoOriginal author here. The fact that all the methods were so ridiculously large made declaring loop indices globally less of a problem. But trust me, it caused plenty of bugs... :P