The world’s two worst variable names
petdance.com
petdance.com
When a variable is only in scope for five lines, it's perfectly reasonable to give it a really short name.
I like to bring up the English language in this particular debate. "It", "he", and "she" are incredibly non-descriptive names, but each one of them is used many orders of magnitude more often than any "descriptive" name (other than maybe "I" or "you") and yet we don't hear rants about that.
The reason is exactly what the original commenter pointed out - scope. Sometimes the word "it" is descriptive enough all by itself. Other times it isn't. It's a more subtle matter than "worst variable names".
I see what you did there.
Optimizing for writing is not optimizing for reading.
Having to frequently parse very long name who doesn't give more informations is very painful, and generally make the real information harder to understand.
Then data2 might be a reasonable name in a unit test that checks to see if a function can handle the traditional "1, 2, many" categories of failure.
Which is not to say that data and data2 are not, often, horrible names. But the circumstances dictate (or excuse) all.
NSData *calculateHash(NSData *data) {
char result[CC_SHA1_DIGEST_LENGTH];
CC_SHA1([data bytes], [data length], result);
return [NSData dataWithBytes:result length:CC_SHA1_DIGEST_LENGTH];
}However, I prefer 'item' and 'items', as that completely evades any possible confusion. Especially useful when iterating over generic containers. Compare:
Foreac Foreach item in items
With Foreach datum in data
I also use itemss for a container of containers: Foreach items in itemss
Foreach item in items
Of course, if the code is less generic, different names are more appropriate: Foreach row in matrix
Foreach cell in row for i in items:
i += 1
for r in rows:
for c in columns:
matrix[r][c] *= 2I'm on my phone currently so I can't really be bothered to find links to support my case. Mostly curious whether others have got the same feeling.
http://www.kraigbrockschmidt.com/mm/Chapter06.htm#_ftn1
https://blogs.msdn.com/b/oldnewthing/archive/2003/10/15/5529...
I used to prefer descriptiveVariableNames, but as my programs have gotten shorter, my variable names have gotten much shorter. I found that longVariableNames were starting to overwhelm everything else and obscure the shape of the code. They were still communicating theIntentOfTheVariable like they always did, but in a way that felt less helpful and more like lexical noise.
Code shape communicates meaning through a different channel than variable names do. As code gets less verbose, its shape emerges more and more, that channel becomes more and more informative, and one begins to use shorter names so as not to drown it out.
This is very different than verbose programs written in verbose languages. There, descriptiveVariableNames don't take up an unseemly amount of space relative to everything else. The shape of the code is less meaningful because you can't see the forest for the trees. And you're far more dependent on intentionClarifyingNames to orient yourself in that forest.
This is why programs written in concise languages look absurdly cryptic to people who haven't spent time in that language's world. The markers of meaning they're used to relying on are missing, and their eyes haven't adjusted to the meaning that is there. The program may have been crafted to maximize overall meaning across several channels, but one needs time and practice to get what those channels are. And the tradeoffs are probably different in each language.
e.g.
typedef void (*function_t)( void* );
void someFunction( void* data ) {
myStruct_s* myStruct = data;
// do something with myStruct
} void someFunction( void* pvMyStruct ) {
myStruct_s* myStruct = pvMyStruct; $conn = mysql_connect(...);
$res = mysql_query($conn);
while($row = mysql_fetch_array($res)){...}
I think these are by far the three most common name conventions, at least for beginners in PHP.boolean alanIsABastard = true;
Where I am the Alan in question and this was written by someone who worked for me. :-)
Perhaps the author sets it to false later symbolizing some sort of transformation you went through or at least a change in his perception of you.
Perhaps it was in a "bipolar" loop:
while (true):
sleep(1000 * 60 * 24)
alanIsABastard = !alanIsABastardPerhaps it should have been a constant (and it was Java):
public static final boolean ALAN_IS_A_BASTARD = true; > Of course it’s data! That’s what variables contain! That’s all they ever contain. It’s like if you were packing up your belongings in moving boxes, and on the side you labeled the box “matter.”
Nope, if he goes with that analogy that data contains data, the box should be labeled with box, imho.Never underestimate the willingness of programmers to obfuscate in the name of (supposed) job security.
For one, in the cases where lambdas are normally used, verbose naming can actually make the code harder to understand by disrupting the formatting of the code in which the lambda is embedded. Also, it creates a nice built-in code smell: If the lambda statement is complicated enough that its purpose is hard to understand without descriptive variable names, that's an indication you should be using a named procedure instead.
Again, using $data2 to represent the square of $data is fine too.
I understand your point, but there are definitely exceptions.
while notDone: { if condition() notDone = false; };For example, there was a structured store where each entity was a byte array ("blob") with certain searchable, indexed "metadata". (The "data data" was the blob itself.) However, demands on the structure required certain additional fields regarding the content of that "metadata" that were allowed to break the contract of the original "metadata" and were therefore metadata on the metadata.
I fell out of my chair, hoping the "kick" would bring me up a level. It didn't. I wasn't dreaming.
It intrigues me why this is not on the article