DEV Community

Ka Wai Cheung
Ka Wai Cheung

Posted on

What are your personal stories/examples of "naming things"?

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)

Collapse
 
brianlakstins profile image
BrianLakstins

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...

Collapse
 
ben profile image
Ben Halpern

To comment on each point:

  • I've regretted trying to get too domain-specific with names. Better off using conventions if they exist in the functionality of the thing. It really lowers the communication barriers.
  • On the good side, for dev.to we have a type of notification that we can send to a segment of the users from the mothership. We haven't really used it but it's functionality we'd use to notify folks of interesting updates without being too obtrusive about it. I recall @andy was working on it and really didn't have a good clear name in mind and we had a really good brainstorm and came up with Broadcast which 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.
  • Just yesterday I wrote a little mini-rant on Google's naming and describing of "progressive web apps" and other things. It's a bit of a marketing + software naming hiccup, but I think it generally applies.
  • Going back to the first point, I once decided to name what should have absolutely been User as Customer because 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.
Collapse
 
developerscode profile image
Ka Wai Cheung

Great points Ben!

Curious -- why was the Customer name so confusing? Were there other names in the domain revolving around "people" or was it just that User is so synonymous with "a representation of a human being in code form"?

Collapse
 
ben profile image
Ben Halpern

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.

Collapse
 
kauhat profile image
Jack Fletcher • Edited

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.

Collapse
 
developerscode profile image
Ka Wai Cheung • Edited

Hey Jack-

Yep, I've definitely seen nonce used in URLs (not just in WP). I had no idea there was that alternate meaning in British English!

Collapse
 
r0f1 profile image
Florian Rohrer

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:

n_items = item_ids.max()

where the array of item_ids goes from 0 to the number of items minus one. So actually, n_items was the number of items minus one. Super confusing, super dangerous. I encountered that discrepancy, because I saw these kinds of loops, further below:

for elem in range(n_items + 1):
    ...
Collapse
 
developerscode profile image
Ka Wai Cheung • Edited

Yuck. Thanks for sharing :)

Collapse
 
0nix profile image
Onix

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.

Collapse
 
stm555 profile image
Seth Thornberry

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.

Collapse
 
carlfish profile image
Charles Miller

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'.

Collapse
 
sushanthmlore profile image
Sushanth M

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.

Collapse
 
janvanthoor profile image
janvt

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

Collapse
 
miffpengi profile image
Miff

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.