See all glossary termsThere's a long running joke in the development community that the two hardest problems in computer science are naming things and cache invalidation (falsely attributed to Martin Fowler, but actually by Phil Karlton).
What is cache invalidation?"Caching" is pre-calculating and storing the results of an operation so that you can retrieve them faster later.Cache invalidation is the process of updating or removing cached data. It's notoriously difficult to get right. Often, data is cached for too long (you would want an update to be reflected, but it doesn't show) or too short (you refresh the cache too often, which can be a performance issue).
While cach invalidation is indeed challenging, naming things is no slouch!
Naming is hard because generally, when you start writing your code, you do not know yet what it will be like.
You're in an exploratory phase, and it's only through iterations that the shape of your codebase emerges, like a drawing from a sketch (this is explained in more details in the architecture glossary entry). Names you picked at the beginning have become invisible to you, but they do not fit what the variables or functions do anymore.
Even if you know in advance your entire codebase, names are the interface between the code and the developer, and it is through naming that the code "exists". You have to make sure the names you pick are clear and unambiguous, and do not clash with any existing names, but also that they represent the concept contained in the name in the best way possible. In that sense, naming in programming can be thought as a "summary" of the underlying code or variable.
Consider the two examples below:
var player
You may think this is a player controller. What about this though?
var player_character
It's harder to think this is a player controller. The name is more precise and gives you a better idea of what the variable is about.
Another example. Suppose you open a script and find a variable at the top:
var amount := 0
The only way to know what amount
corresponds to would be to read the code and find how it is used. But if you find this instead:
var player_health := 0
While properly naming is critical when working in a team, it is also true when you're on your own! You're always working with a future version of yourself, and you want to make sure you can understand what you did when you come back to your code in a few weeks or months.
For tips and good practices on naming, head to the identifier glossary entry.See Also
Related terms in the Glossary
External Links
Handpicked resources on the internet
school.gdquest.com - 0.3.5-2024-11-18T20:36:29.840Z-