Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How do you name your counters?

Adam Marker
new scripter
Join date: 2 Jan 2004
Posts: 104
02-25-2005 18:00
Somewhere I read that one letter is "just too short", with a recommendation to use at least two characters. So usually I use ix. Plus jx for a nested loop.

I have no idea where I read that ... but it sounds like the kind of rule that someone would come up with, no?
Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
02-25-2005 18:09
From: Adam Marker
Somewhere I read that one letter is "just too short", with a recommendation to use at least two characters. So usually I use ix. Plus jx for a nested loop.

I have no idea where I read that ... but it sounds like the kind of rule that someone would come up with, no?


One letter seems to be pretty standard - mostly dates back to FORTRAN where the only incrementers in loops you could use were i,j,k,l. (w,x,y,z also had special properties)

-Adam
_____________________
Co-Founder / Lead Developer
GigasSecondServer
Alan Kiesler
Retired Resident
Join date: 29 Jun 2004
Posts: 354
02-25-2005 18:43
Single letter for loops, mainly i or somesuch. My RL programming is mainly UNIX C-Shell and sed/nawk these days. I'll sometimes (ok, almost always ;) ) use ff for a foreach() loop in csh, more out of habit these days.

Everything else gets some form of descriptive moniker, even if a small one for embedded nawk code in a csh script.
_____________________
Timothy S. Kimball (RL) -- aka 'Alan Kiesler'
The Kind Healer -- http://sungak.net

No ending is EVER written; Communities will continue on their own.
Racer Plisskin
Rezerator
Join date: 2 Jan 2005
Posts: 147
02-25-2005 19:25
Looping? What's that? ;)

If I'm just making something for my own use, variable names could be virtualy anything (depends on mood and wether I'm feeling dislexic that day).

counters tend to be descriptive names and I'll 'unset' any throw aways when I'm done with them if the language has that feature (I mostly work on c & k shell Unix scripting lately).

If anyone else is gonna see it, I'll do global search/replace to put more reasonable names on stuff and put in documentation for anything that doesn't look obvious from the code itself once I'm done.

Racer P
gene Poole
"Foolish humans!"
Join date: 16 Jun 2004
Posts: 324
02-25-2005 20:59
From: Huns Valen
comedy cx answer because I like assembly

CX? Yeah, x86 assembly from the early 80s maybe! All the cool kids today are using ECX. ;)

From: Adam Marker
Somewhere I read that one letter is "just too short", with a recommendation to use at least two characters. So usually I use ix. Plus jx for a nested loop.

I have no idea where I read that ... but it sounds like the kind of rule that someone would come up with, no?

Bah! Don't just do something because someone else has a "rule" for it -- decide for yourself if it makes sense or not. :) If i and x are not descriptive on their own, you won't gain much by simply concatenating them. Plus, you'll have to type twice as much when identifying them. ;) Anyway, not really that big a deal...

My conventions: i, j, and k are generally sufficient for iterating. Anything with some longevity (eg. outside a loop) gets a concise (short-but-descriptive) name, using camelCase if necesssary.
Jack Lambert
Registered User
Join date: 4 Jun 2004
Posts: 265
02-26-2005 00:48
Typically in small functions I just use "i" but if there are more than one counter in it, I normally give it an annoyingly anal name like

iAvatarCounter

On that note I nearly always put the variable type in front of declarations like:

key kAvatarKey;
string sAvatarName;
float fAvatarHeight;
list lAvatars;

--Jack Lambert
Hinkley Baldwin
Registered User
Join date: 13 May 2004
Posts: 77
02-26-2005 02:35
Any ZX Spectrum programmer knows the only loop varialy you should use is "i". The NEXT command was on the I key so terminating a loop was two presses of the I key, no unnecessary finger movement for us!
Adam Marker
new scripter
Join date: 2 Jan 2004
Posts: 104
02-26-2005 04:26
Humbug! Those one-character names look a little lost on the page, so the two-character "rule" made sense to me. ix ix ix. Now that you mention it though, perhaps I should double up on the semi-colons as well;;
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
02-26-2005 14:50
I label my counters with basic descriptive names. like "counter", "iteration" or "dataSet". Most of the time if I need more then 2 counters at one time I can usually break part of the code off into it's own function, making it easer to read, and give me more re-usable code. When I'm working with 3D arrays I switch between two standards. I'll use a vector, allowing me to pass x, y, z as one variable. The vector thing is a new experiment. The other declaration I use, and probable will go back to using, is xCounter, yCounter and zCounter.

Most of the time I declare my variables at the top of a function call, but for counters i'll declare the variable right before the "for" or "while" loop. It might be a bad idea, but It's a habit from C++ where I could declare a variable in the loop call.

I find the closer I can make my code read like an english sentnce the less questions I get from other coders. Plus I can ushally glance at a peace of code I worte 8 years ago and not have to refigure out what's going on. Because it's easy to tell. It saves me time because don't have to look for clues as to what a funtion or variable will do/contain. To quote some one, "Programers are lazzy."
gene Poole
"Foolish humans!"
Join date: 16 Jun 2004
Posts: 324
02-26-2005 17:04
From: Adam Marker
Humbug! Those one-character names look a little lost on the page, so the two-character "rule" made sense to me. ix ix ix. Now that you mention it though, perhaps I should double up on the semi-colons as well;;


Heh! Heh! Alright alright,, why why not not?? ;) ;)
Richard Pinkerton
Registered User
Join date: 20 Jan 2005
Posts: 125
02-26-2005 17:47
From: Hinkley Baldwin
Any ZX Spectrum programmer knows the only loop varialy you should use is "i". The NEXT command was on the I key so terminating a loop was two presses of the I key, no unnecessary finger movement for us!


Damn right! :)

All that fuss with multiple shift keys to generate all the languages keywords as single entities just so they could avoid lexing the input. I loved that computer and I still don't know why.
1 2