This is a card in Dave's Virtual Box of Cards.

Naming Things (Programming)

Created: 2023-03-08

I’ve always loved this version of the "two hard problems" quote:

"There are 2 hard problems in computer science: cache invalidation, naming things, and off-by-1 errors." --Leon Bambrick, 2010

Why is it so hard to name things when we’re writing programs?

The usual answer is that it’s just really hard to come up with the right (English) words to describe certain things and actions, especially when those things are very abstract.

That is definitely true.

I’ve got two more that I haven’t seen explicitly mentioned before (though no doubt they have):

First, an argument in favor of point-free programming: Not being forced to name things gives us expressive power and clean syntax. This program to give us a total from a list of numbers is probably pretty clear despite having no names for any intermediate values (or even the output):

[1,2,3,4,5] sum

But my second answer (and the reason I added this card) is a realization I had the other day while trying to come up with a good function name:

I think the abstract logic needed to write a function uses a different part of the brain than the creative language part that can give it a really good name.

I’m not saying "if you can write it, you can’t name it" or "if you can name it, you can’t write it." It’s not that bad. But I do think it’s challenging to do both at peak performance at the same time.

I could sure be wrong about this, but I’ve seen the comments I write when I’m in "programming mode" and they’re not always great. My "writing mode" comments are a lot better. It seems reasonable to surmise that naming variables and functions probably follows the same pattern.

See also: Programmer Tunnel Vision.