Comment Re:Imperial vs US Gallon (Score 1) 417
In the UK we still use Miles per Gallon to measure fuel consumption, but buy our petrol in litres!
In the UK we still use Miles per Gallon to measure fuel consumption, but buy our petrol in litres!
LOCAL variable names should be short, and to the point.If you have some random integer loop counter, it should probably be called "i". Calling it "loop_counter" is non-productive, if there is no chance of it being mis-understood. Similarly, "tmp" can be just about any type of variable that is used to hold a temporary value.
I'm sorry, but I have to say bollocks to the last clause there. Calling a loop counter "i" means then that it is next to impossible to find out where it is being used.
Instead of using "i", I would use "index", for a generic case, as usually we're talking about indexing into some array or other data structure. The use of single letter variables names gets even worse when you have nested loops, I've lost count of the number cases where somebody using "i" and "j" as their loop variables have accidentally transposed the references, espcially when we're talking about code that gets changed over time. (i.e. real code, not an example
It's far better to spend a extra few seconds in giving a meaningful name to a variable, rather than spending hours, debugging some strange intermittent memory overwrite! Let alone the cumulative numbers of hours spend trying to undestand a piece of code when frobnicating it a year later.
We don't really understand it, so we'll give it to the programmers.