I’m sure you’ve heard the saying: “There are only two hard things in software – cache invalidation, and naming things.” I’ve thought about this quote for years and I still can’t decide whether I agree that there are indeed only two hard things. But I definitely agree that Naming Things is hard.
Naming is hard because it gets right to the heart of what we’re doing: building a model in order to solve a real world problem. To be useful, that model must be a clever description of reality that captures the essence of the problem while ignoring what’s irrelevant. And the way we describe things is with words.
Those words must convey our model to the reader. Not only must they give the reader an accurate mental picture of our model, but they must be ruthlessly consistent and unambiguous. When we identify a concept we have to define it and then name it; let’s call it A. Now we must consistently call it A throughout our model (and code, which is really just formal documentation of our model). Don’t switch to calling it B half way through. If you do name something B, then B better be distinct from A in a way that is important in your model.
Notice that I say “in your model”, not “in real life”, because the same real world concepts might be distinct in one model of reality and indistinguishable in another. Imagine modelling a car. Almost all models will care about the car’s VIN, for example. But a model for logistical purposes will care about things like the car’s current location and status. A model for marketing purposes will care more about its colour and price and so forth.