Programming's two worst variable names  MAR 09 2004

Programming's two worst variable names. $data and $data2

There are 5 reader comments

rheiser15 09 200410:15AM

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.

Jim56 09 200412:56PM

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.

Joseph22 09 2004 9:22PM

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.

barlow38 10 2004 1:38PM

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.

sam06 12 2004 9:06AM

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.

kottke.org

Front page
About + contact
Site archives

Subscribe

Follow kottke.org on Twitter

Follow kottke.org on Tumblr

Like kottke.org on Facebook

Subscribe to the RSS feed

Advertisement

Ads by The Deck

Support kottke.org shop at Amazon

And more at Amazon.com

Looking for work?

More at We Work Remotely

Kottke @ Quarterly

Subscribe to Quarterly and get a real-life mailing from Jason every three months.

 

Enginehosting

Hosting provided EngineHosting