I disagree, depending on the context. Data is an acceptable variable name to refer to binary blobs that don't <i>have</i> a type, eg, this is roughly the low level class that holds data that I'm streaming in (files may either be in a pack file or downloaded while the game is played):<p>class packFile {
var name:String;
var location:String;
var downloadPriority:Int;
var data:Array<Byte>;
}<p>There may be a better name than data, but I can't think of one off the top of my head, and it's certainly not a bad one.
What it is about code written in languages that prefix variables with $ that results in unmaintainable code?<p>I'd personally vote for i and j<p>Mea Culpa: I've written my fair share of horrid code in PHP and Perl.
A really bad variable name should confuse the reader as much as possible. If I remember my compiler design classes correctly Pascal (?) allows you to name variables the same as language constructs. That means you can write something like<p>FOR FOR = WHILE WHILE WHILE = FOR<p>Now THAT'S bad variable names. :)<p>Isn't there an example like this in the Dragon Book?
You forgot 'i'.<p>Yes, I know you're iterating over something.<p>Best case scenario: you named that something well so all I have to do in your great big for loop is scroll up, work out what you meant, and apply that to the code I care about, being mildly annoyed.<p>Worst case scenario: the something is also badly named and I have to open up a debugger and set a trace to work out whether the iterable is people, channels, cows, or dinosaurs.<p>Yes I know this is common behaviour. So are many other bad things.
Oh thank god it's not the stuff I use. My code is so bad that every time I declare a variable a fairy dies. At least there's something I'm not doing wrong.
$data is a perfectly fine variable name, if it's used in the correct context. Such as pulling a result set out of a database. In that case, it's exactly like using i in a for loop.<p>Anything postfixed with 2 is more shady, I agree, but the absolute worst variable names are the ones that say they are something they're not - such as a column named "tablename_key" - which is actually a foreign key, but not in "tablename".
Often when I read something from a file or socket, prior to parsing, it's called data. Same goes for the information to be inserted into a template, or intermediate structures when transforming datasets or documents without knowing their type.<p>Data is the variable name you use when you don't know, or can't specify, what you're dealing with.
I think that names that are wrong are worse, like something called $xmldata which doesn't contain data in xml format, or $price_in_cents which actually contains $price_in_dollars but nobody has bothered to change it.
I'm guilty of using tmp quite a lot. On my defense though, it's usually just that, temporary: I end up refactoring it down the road (most of the times)!