TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The world's two worst variable names

31 pointsby niyazpkabout 15 years ago

20 comments

reitzensteinmabout 15 years ago
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&#60;Byte&#62;; }<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.
评论 #1245064 未加载
评论 #1244290 未加载
评论 #1244289 未加载
fleitzabout 15 years ago
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.
评论 #1244196 未加载
Aegeanabout 15 years ago
Data is not that bad. When you're reading a device it may have a data and status register and data becomes perfectly distinct in this context.
评论 #1244429 未加载
topbananaabout 15 years ago
In a code review I once got pulled up for using 'i' in a 2-line function called something like DoSomethingToThings(Thing[] things)
garplyabout 15 years ago
I think $data2 is worse than $data.
评论 #1244331 未加载
评论 #1244269 未加载
progabout 15 years ago
While programming in C I use str quite a bit. Moving to Python, that conflicts with the str builtin function, so I now use s.
erikstarckabout 15 years ago
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?
nailerabout 15 years ago
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.
评论 #1244283 未加载
_b8r0about 15 years ago
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.
mseebachabout 15 years ago
$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".
评论 #1244223 未加载
aphyrabout 15 years ago
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.
sevabout 15 years ago
Worse than the worst variable names? Good variable names where, for example, $profit = $revenue
sunkencityabout 15 years ago
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.
mziuluabout 15 years ago
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)!
etheraelabout 15 years ago
foo &#38; bar
评论 #1244222 未加载
allendabout 15 years ago
I don't know if $data is the 'worst'. I've used 'int nothing', and 'int anything' before.
araneaeabout 15 years ago
Haha, I use data all the time. Usually when I'm doing data analysis.
roundsquareabout 15 years ago
I think I once used stuff as a variable name before.
donaqabout 15 years ago
I use $dat, so I'm off the hook.
crpatinoabout 15 years ago
$r2d2 and $c3po<p>...seriously