- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
As others have said, T, L W & H are very common, especially in UI code, and should be recognizible even as one letter names.
Also, the lines which they are used in (especially when you write code to rescale windows in an intelligent way) tend to be quite long and often have these variables occurring many times, which is a good reason to not clutter them up with unnecessarily long names.
I consider this nitpicking, where the letter of the law is more important than the intent of the law, and the change was probably just a "Screw you!"-gesture.
No real WTF, in other words.
Admin
If you have ANY idea what the damn code is supposed to do, (and you should, or you shouldn't be fucking with it), then you shouldn't need to have the damn code read like a fucking novel. 1 or 2 or 3 letter variables work just fine for real programmers.
Admin
It could have been worse:
int aa, Aa, aA, AA; //top left height width
They're all at least one character different from each other. Hmm, reminds me of a recent 'cOut' wtf actually
Admin
Oh god, this is lame. Such l t w h or x y w h single letter variables are no problem (i'm porting java games) at least you know they really mean what they are - positions and lengths. In the really doomed source codes, you can find variables like boolean makePaintWait which actually makes the sprite to move, skipXYZ=true which makes the xyz go, etc. etc.
P.S. What comes next ? Moaning about single letter i variable used in "for" loops :-D ?
Admin
Yeah, let's call all iterators pui_iteratorOverTableOfHPC.
Yeah, let's call all "x & y & z"s horizontal_position & vertical_position (coordinate is longer so better ?)
Name according to context and purpose and do it reasonable this should be coding rule. No "always", "never" and no limits.
Admin
That's othe rule. No context with so simple names should be so long. Nothing to do with local variable name.
Members, global variables (no!!), classes and all other global entities should be named descriptively.
Leave out x,y,z in context of geometry, t,l,w,h in context of windows/rectangles i,j,k for iterators as long as entity is recognizable. They must be as local as it could be. And it's not naming error if they are used "hundred lines of code later" it's conception error or just stupid optimizalization(?).
Admin
I'd suggest:
rect<int> r; // whatever
preceded by:
template <class C> class rect { // or Rect if you will C _left,_top,_width,_height; public: ... C x() const { return _left; } C y() const { return _top; } ... };
doesn't say function names need to differ by more than 1 letter
Admin
or maybe just:
int r[4]; // ...
Admin
You are right! Comments can make sense. I had comments in mind like
int loopCount //count variable for the loop
or this real world example, i've seen for a while!!!
// returns the id int getId(){}
such comments add noise to the code, no value.
Admin
As far as I'm concerned this is the only good reason for comments.
Admin
OTOH, you can end up with some really horribly written loops.
I've seen contraptions like:
for (i=0; (j < 100) && (i < 30); j=newval(j), i++, k--)
which makes you wonder WTF the code is doing - yes, they're all indices, but to different arrays and stuff, and it's not immediately obvious what each is supposed to do. (worse yet, j and k are often updated in the middle of the loop, as well).
It's worse when you have N dimensional arrays (N > 1), and the indices used aren't in a consistent order of array[i][j][k] and crap.
Admin
I'm a fan of single letter (and double letter, I guess, as in ii) index/iterator names because they un-clutter the loop and thus make it easier to read, even though the variable names are shorter.
there's a good reason. never thought of that before...</monster-post>
Admin
Admin
This programmer was working on the Superdoll3000(tm), and it concerned her states...
"Top" (for those who like that), "Bottom" (default position) "Left" (you failed to pay the rent on this expensive toy) "Right" (will remind you for weeks about this single fact and brazenly ignore anything to the contrary)
So those of you who thought it was good comment or code should probably think twice..... :p
Admin
I always use 'ii' and 'jj' and 'kk' for iteration indices. My reason is that I sometimes know a piece of code contains a for-loop, but don't know quite where. I can just look for 'ii' with text search, which would be harder with single letters.
Admin
Admin
For those of your that think descriptive variable names are always better than i, j, k for local loop indices, I would point you to Section 1.1 in "The Practice of Programming" by Kernighan and Pike. It recommends descriptive variable names with a proviso against local loop index names.
And this is the example they trotted out to illustrate their point:
for (theElementIndex = 0; theElementIndex < numberOfElements; theElementIndex++) { elementArray[theElementIndex] = theElementIndex; }
to
for (i = 0; i < nelems; i++) { elem[i] = i; }
Admin
As a former programmer of Fortran IV, I think this is a ridiculous argument. Indices are indexes. There is no semantic reason for this in the ISO-85... damn, can't be bothered to look it up ... Latin alphabet at all.
Or, to put it another way: find a book from 1800 onwards that denominates things with an index of "l".
Go on.
Admin
Using the full names would only expose the rigid application of this standard in this case for the farce it is:
int Top, Left, Bottom, Right; // Top, Left, Bottom, Right
Rigid farce it may be, but that looks like the best version so far to me, except the comments should be more explicit.
Admin
The code is perfectly understandable. The worse part is that he's using capital letters for variables, when they should be reserved for macros.
Personally, I like his "fix": it's a nice jab at silly cargo cult coding standards.
Admin
The problem with the lowest common denominator is that it is to low.
Admin
Rules like these are useless.
Admin
What would you say for this ... ?
The Real WTF (haha I've used this sentence) is that it works as normal loop.
Admin
Everybody knows though that i is for index in an array/vector used as part of a loop counter, and possibly an operator overload definition.
Just as everyone knows that T is the template parameter for a generic type, eg
template < typename T > class Foo { // etc };
Admin
As a side note to side note anyone else hate when someone uses x and y for indices that are not related to coordinates?
Admin
i is for index. j and k are used simply because they are the letters that come next in the alphabet.
Similar to using T for type, and if you need a second one U is a common choice.
Not sure why x was chosen for the archetypal variable. I know when you first learn algebra at the basic level at school (i.e. using letters in equations to represent unknowns) x is typically chosen. (Always seems a bad choice as it is slightly ambiguous to the multiplication sign). Of course to eliminate that you write xy to mean x multiplied by y but that means you cannot have multi-letter identifiers and when you run out of English letters (or Latin letters if you prefer to call them that) you usually start using Greek ones, (in fact Greek ones are often used in the first instance).
Typically a and b are used as limits to integrate between.
f is used as the archetypal function (after all function begins with the letter f). g is usually therefore the next function, but in group theory g is your archetypal group element (with G being the group), and H is the next-defined group.
n is used as the archetypal count (number of items) but then you tend to go backward to m. I guess o is avoided because it is too much like 0.
p is the archetypal probability. q is typically the next one used.
t is generally used to denote a period of time. In fact if you talk about a function on variable x you will typically refer to dx/dt without even defining t - time is always assumed.
Admin
All that space to put those comments then can't afford just one more line to make the braces match vertically?
Admin
I would do that... Nobody tells me how to name my Ts!
Admin
Viola Merda! Forza Rapid!
Admin
Start using words like 'left' and 'right' as variable names and you can run into collisions with reserved words in certain languages, eh?
I dont like to type long variable names.
I prefer lower-case names, they just look better. Upper case names SHOUT OUT at you.
Sometimes, I get cute with variable names, e.g. 'for dead_guy in street...'
The private, somewhat antisocial humor or the american programmer...
Admin
Start using words like 'left' and 'right' as variable names and you can run into collisions with reserved words in certain languages, eh?
I dont like to type long variable names.
I prefer lower-case names, they just look better. Upper case names SHOUT OUT at you.
Sometimes, I get cute with variable names, e.g. 'for dead_guy in street...'
The private, somewhat antisocial humor or the american programmer...
Admin
The rigid coding standards are typical. Comments, dear friends, are subject to 'comment drift' - where the comment says one thing and the code does another. n'est ce pas?
Best thing is to keep it simple. Comments where needed.
Comments everywhere clutter up the code. The worst is when the developers 'pecker-tag' up the code with: /* 3/15/06 J.Jones added clause to prevent double-clutching... */
So you get 20,50 100 lines of comments at the top of your proc. Makes is tough to navigate
That stuff belongs in PVCS or VSS...
Admin
I and J are actualy the same letter.
For the Romans the letter I had both a vowel sound and a consenent sound. Sometime in the Middle ages scribes got into the habbit of adding a hook to the bottom of the I for the consonent. Thus J.
The original J sound was more of a 'y' or 'yh' sound, which is how "Yeshua" became "Jesus".
Mark Iennaco <= pronounced Yhen-na'-ko
Admin
Speaking of Jehovah, all we know about the name of the Lord is that His initials were IHVH, now either YHVH or JHVH (consonant I in early Latin is a Y sound), and the vowels of a different word were inserted in the gaps in what amounts to a Hebrew equivalent of L33t-sp34k, like writing J3sus or 4ll4h so as not to commit profanity, or in English speaking a neologism such as Zounds rather than the perhaps-offensive phrase "God's wounds".
Admin
var personId = person.Id; if (!ValidPersonId(personId)) throw exception... personId = PersonIdFix336(personId); if (NotARealPerson(personId)) throw dogException... if (ManagementDecisionOnPersonIdToAvoidCosmicRayRedux(personID)) throw justWriteCommentHereException...
Admin
I used to work at a place where there was a coding convention in place that apparently was created to make code as hard to read as possible. I am not even kidding: Variable names could only be 3 characters long. Which is especially useful in languages like PHP where you don't declare variables like "int num" or "string str", but where they just get the type of the object that is assigned to them. So, a variable like "dat" could be a "date" or maybe "data" or even "Datei" (german for "file"). And indentation was to be set to two spaces. Yeah, have fun reading that shit after staring at code for 8 hours. Luckily those conventions where no longer in use when I started working there. So, the very first thing I did when I had to open an old project was to go through all the classes and correct the indentation to 4 spaces.