Most programmers are familiar with the quote, "There are only two hard things in Computer Science: cache invalidation and naming things." I'm curious about your personal experiences with the latter.
- What are some examples of really bad names you've encountered in code?
- What about the alternative -- any really good names that have stuck with you?
- What frameworks/libraries do it well or do it poorly?
- Has a really poor name ever come back to haunt you (i.e. caused you hours of extra debugging or misled you?)
I know we all have strategies for naming things, but I'm really curious about your personal examples and stories.
Oldest comments (20)
Naming something "event". Even if there is something that you are developing that occurs at a certain time, having the word "event" as some kind of business object when it's also a kind of key word in many languages is just confusing.
Basically, naming anything close to the name of a key word throws me off when reading through the code...
To comment on each point:
Broadcastwhich is such a good word, it's remarkable it didn't come to us sooner. But it's so easy to say that in hindsight.UserasCustomerbecause I thought it would encourage a more focused sales-oriented mindset. At that initial base stage it seemed to make sense. It was really confusing and regretful almost immediately.Great points Ben!
Curious -- why was the
Customername so confusing? Were there other names in the domain revolving around "people" or was it just thatUseris so synonymous with "a representation of a human being in code form"?It just seemed like every time we went to talk about the model, we had to clarify that customer was the main user model. Also it was Rails, where conventions are strong and everybody calls it user.
WordPress will use a "nonce" token to prevent duplicate input and CSRF attacks. That's all well and good, but in British English that word has another, sinister meaning. Occasionally we'll have a caching issue and a token will be re-used. WordPress usually displays a nondescript "Are you sure you want to do this?" error, but some plugins will print "Invalid/Bad Nonce" right there on the screen.
I've had to explain to a couple of clients that this is indeed correct and is a technical term. Unfortunately one of those clients was a school.
Hey Jack-
Yep, I've definitely seen
nonceused in URLs (not just in WP). I had no idea there was that alternate meaning in British English!I am annoyed when variable names seem correct at first glance, but turn out to be not exactly what the name says. I was working on a project, where the was a variable called
n_items, and you would assume, that it stored the number of items. However, it was calculated like this:where the array of item_ids goes from 0 to the number of items minus one. So actually,
n_itemswas the number of items minus one. Super confusing, super dangerous. I encountered that discrepancy, because I saw these kinds of loops, further below:Yuck. Thanks for sharing :)
I have a lot of fun with internal versioning names, since we conduct Integration Testing in another machine: I use cities in a particular state of the union in alphabetical order. So for example I have Geneva2 (New York) or Gainesville8 (Florida). It allows me to talk with my team about the latest version in an easy to remember way.
method name "dome" .. I puzzled for a long time trying to figure out why they named the function after a semi-spherical shape until another dev pointed out that they just hadn't camel-cased it and it was even worse.
I also get a twitch any time I see a variable named or suffixed with "data" .. the Tautology Club has many members.
We had just released Confluence 1.0 back in 2004, and as part of the cleanup we decided to move whatever non-app-specific code might be useful to the next product into shareable libraries.
The plan was to move all the code from the app into a temporary bucket while we untangled the remaining dependencies, and then break that staging library up into its more specific parts (ORM stuff, Spring stuff, app configuration stuff, and so on.)
I wanted to make it obvious to any developer which code was still in need of migration during this process, so I named the bucket library 'bucket', and all the java packages, 'bucket.whatever'.
When I left the company ten years later, we were still depending on 'bucket'.
I'm currently involved in writing code for an insurance company's project. Their enterprise data model is dominated by an object with the name "EstimateOrContract"(name altered for confidentiality). This object represents an insurance policy estimate initially and then the actual insurance contract after the policy is sold.
Worst, and yet, somehow best, name ever, I gave to a Javascript component I wrote as a lightweight version of jQuery UI Dialog. I gave the component the name TRELOMS, which stood for "Trivago EierLegende Overlay MilchSau". Stuck around for years, even became part of the vocabulary on non-tech people... :D Sometimes a humorously descriptive name can be perfect, internally the component named itself "overlay engine", which is more accurate, but just... boring :D
I was recently working on a tool for my internal use and I had no idea what to call it. I ended up just punting and calling it "Seborrhea" in reference to the Dilbert TV series.