HACKER Q&A
📣 izgzhen

Why is naming things in programming so hard?


It is considered a challenge to give names to things like files, variables etc., both as a joke and as a real thing that I and many of my friends acknowledge. Why?


  👤 gls2ro Accepted Answer ✓
They way I see this is thinking about vocabulary and language.

We can describe the world only within the limits of our vocabulary. Basically we want to describe thinking about new things with existing words.

In case of programming we are building new concepts and it might be the case when there is no word to properly describe that concept. So we try to find the best approximation. This task alone is very hard, specifically because there are two layers of modeling: first we model the domain into abstract programming concepts then we need to create a model (approximation) of these concepts that we now want to code to be able to find a word for them.

We can see it simply with a variable: we can use common names for variables which have a clear, easy to see around us purpose: counting => count/counter, indexing => index, ordering => order ... but when we have a variable that should retain an intermediate abstract value to be used futher then this concept cannot be found so easy.

Let's say we need to save the name of a class - generated on the spot - to be used further in the code.

What is the name for this variable?

- "class" - seems the first one, but in most languages this is a restricted word

- "klass" - here we are already creating a new word

- "bucket" - this is more easy to find around us as "a place to put things in", but it does not fit maybe the current code as it is a too large concept

- "intermediate_class_name" - now again this is inventing new words by glueing them together. Might work, might not work depending on coding guidelines and other restrictions


👤 dexwiz
What is a thing but a name? To really name something you have to know what it is, and that is harder than you think.

👤 yesenadam
Well, like other designed artifacts, a name should satisfy several criteria well. It shouldn't be too long to be usable, or too short to be readable. It should be pronounceable. It should capture its object's purpose fully and at an appropriate level of abstraction. It has to differentiate itself well from other names. Often a whole naming scheme must be worked out, depending on the nature and relationship of the precise things to be named. Changing any one name can create a need for many other names to also be changed, or for the named things to be rearranged or redesigned.

👤 wangchucheng
It is harder to express meaning accurately and concisely than ordinary expression. Sometimes you need to give different names to similar functions, which is even more difficult.

👤 karmakaze
Even answering the question, "why does this thing exist"? is often only answered in terms of its mechanism as it relates to previous choices. To be able to answer it fully, you'd have to be aware of the ad-hoc architecture that is being made-up as you go.

If you're able to envision the main decomposition and flow of the program before building (or rebuilding) it, you'll be much better off. Also be mindful of invariants or points in the process where certain constraints are met. The stuff between these points are to get you from here to there.


👤 poletopole
Programming is very symbolic whereas natural language is more phonetical, so using one in terms of the other will always be awkward. I feel the best strategy is just to let variable names, for example, be pithy or terse and just use comments to compensate; this is because I’ve found comments are still necessary even with long semantic variable names.

👤 quickthrower2
It forces you to understand what you are doing!

👤 afarrell
Because we write code primarily to communicate and the words we use to name things has a high impact on that communication.

👤 Someone
Because there are so many things to name.

If there were only 20-ish, using “foo”, “bar”, etc, or “red”, “yellow, etc, or even “x1”, “x2”, etc. would be good enough (not perfect, but people could easily get used to it, just as they get used to the (mostly) arbitrary name tags we put on people in our social circles)


👤 lrossi
On top of what others have said, when programming we also deal a lot with changing requirements. Code that used to do one thing, now needs to do something slightly different. Keeping track of everything and making sure that names remain accurate takes a lot of time and effort.

👤 Raed667
Sometimes you're trying to model the real world, sometimes you're trying to represent abstract concepts, sometimes you think you know what you're trying to name but you don't ...

👤 logicslave
I think it was harder before industrial IDEs