2 ms·
"You don't have to write a novel and explain that you are adding 2 to variable i" Better yet, don't name your variable "i". Name it something like "PartCounte
by edw519 19y ago
"You don't have to write a novel and explain that you are adding 2 to variable i"
Better yet, don't name your variable "i". Name it something like "PartCounter" or "CustCtr". Then you won't have to write many comments. Your code can be largely self-commenting.
As a general rule of thumb (IMO), never name any variable with less than 3 characters and never allow one variable name to be completely contained within another (Ctr & CustCtr). Being able to find every instance of a variable (and nothing else) with a simple editor global search will save you much time and headaches over the next n years. (Oops, I just violated my own rule.)
- boucher 19y agoand, as always, take other people's rules (of thumb) and guidelines with a grain of salt. there's almost always someone who will argue the opposite, all, or part of the time. ( i for one will continue to name my counters i :-) )
- Goladus 19y agoA long time ago I started naming mine 'ii' or some variant of 'index' for exactly the reason mentioned (wouldn't confuse search/replace). Although I often try to avoid using counters at all via foreach or recursion.