Programming's two worst variable names. $data and $data2
I don't know. I was just working with some code where the engineer had declared two variables that worked together and named them "l0" and "l1". When I saw an assignment akin to; "l0 = l1 + 1" , I had to do a double take. It looks a lot more like "10" and "11" in the monospaced font my IDE was using.
Heh, I've run into that when coding in Courier New. I've been trying out some alternatives.
I'd have to disagree with Mr. Lester though. The worst variable names are those that are unintentionally misleading. Uninformative is irritating, but misleading can be disastrous.
The article reminds me of this classic.
My least favourite variable name, which I will admit to having used once or twice, is $l. Because at this point, when you're debugging six months later, you've just hit the fourth loop control counter (after $i, $j, and $k, by convention) in a deep dark nest, and you'd dearly love just a little bit more information please.
Is there much of a performance hit using long variable names in an interpreted language like PHP? I tend to use extremely long, descriptive variable names in lieu of commenting my code and I just haven't known how to look into the question of performance. Any insights would be appreciated.
I don't know anything about PHP internals but I should certainly think the answer is 'no'; most likely definied variables will be stored in some kind of hash so it can find them without having to search through the whole string. Even if they're not, who cares? Comparing two strings costs essentially nothing on modern processors, compared to your code that actually *does* something (like accesses a database or whatever).
Frankly in most PHP code you probably shouldn't care about performance anyway. Does your code run too slowly? If not, then why are you worrying? :) Premature optimisation is usually described as a major sin... I mean if you really need it to like run on some kind of embedded system or whatever where CPU cycles, RAM etc. are at a serious premium, then you shouldn't be using PHP in the first place.
so anyway - I'd go with your nice long variables, definitely. (But long variables are not a replacement for comments. Do both! Ensure your place in heaven. :)
This thread is closed to new comments. Thanks to everyone who responded.
About + contact
You can follow kottke.org on Twitter, Facebook, Tumblr, Feedly, or RSS.
Hosting provided by