In my opinion, code would be worlds easier to read, learn, debug, and understand if more programmers stopped using [unnecessary] abbreviations and started writing self-documenting code. Self-documenting code is...well, code that doesn't need explanation or comments to explain its function.
Here's an example from http://www.cprogramming.com/snippets/source-code/
.
/* n= positive integer e= power S= sum of integers raised in e power */
int e,n,i,S=0;
.
Is there really a reason for this sort of abbreviation? I see it all the time, everywhere, and even in learning materials. I don't really understand because as far as I know there aren't any technical limitations that would require such abbreviations to be used. On another note, " i " is later used in its usual fashion in a for-loop...but I've never seen it declared outside of the loop before.
So why not write it in a self-documenting fashion:
.
int power, positive_integer, sum_of_integers_raised_to_a_power;
.
If it's about typing long variable names, I don't really understand that notion. We're programmers, right? I'm not a professional or anything, but in the long run I believe it's worth the extra effort because when you're working with other people, no-one will have to spend time learning your coding style or searching for comments to figure out what the source is doing. Besides, most programming software offer code completion.
Sorry for little rant. I promise that I'm not just searching for petty things to talk about here. It just strikes me as a real problem. If you have throw-away variables that don't need to stick around for later use, like the following example, it's not that big a deal.
.
// This is perfectly OK! It's still easy to read!
string phrase = "Hello!";
for(int i = 0; i < phrase.size(); i++){
cout << phrase.at(i);
}
// This, however, probably needs a comment!
string p = "Hello!";
for(int i = 0; i < p.size(); i++){
cout << p.at(i);
}
.
How many of you write self-documenting code? If you don't always do so, what are your reasons for not using this style?