On Jan 11, 2011, at 3:02 PM, Mark J. Reed wrote: If you're just counting, there's no reason not to use i as your loop control variable,
OK. Stop right there please.
Using i, j or k is non descriptive. You do not know what you are counting. You have to take a split second and analyze the loop and see what it is. There is no context to what you are counting.
This makes the keystrokes you save typing less, wasted braincycles when you have to look around and see what your loop is referring to.
It's more of a waste of time and of brain bandwidth. Plus, you can type once and copy paste the variable name.
By taking the time to do this, your loops are actually inherently communicative of what they are looping. Simple and self communicative, self documenting.
Now with variable types, I tend to go this route.
my goes in front of a local p goes in front of a property g goes in front of a global.
self communicative of scope.
The point is to make your code communicate to you what it's doing so you don't have to read it. You just glance at it and you immediately know what it's doing and what it's scoped to without having to think.
We should use our thinking for solving the problems, not for trying to understand our code. If we take these small steps, the code tells you what its about.
It's really easy.
And thanks for making me go in to detail as to why.
If you don't know why I'm so obsessive over this, it's because it's afforded me the ability to tackle larger projects as they are so easy to scale now that I've moved away from my old bad habits.
Pretty soon, I'll stop getting chocolate in my peanut butter.
|