Member-only story
Clean Code: Naming
Best practices for naming variables, functions, classes, and more

Welcome to the first part of the clean code series. This series will be highly inspired by and sometimes embarrassingly copied from the Clean Code book by Robert C. Martin (Uncle Bob). I highly recommend reading the book. This series is nowhere near to the original book.
The book has a lot of code examples, and most of them are provided in Java. I will not go through all the code examples, but if I do use some, I will translate or make examples using Python.
What Is Clean Code?
Clean code should have:
- Full test coverage
- Complete error handling
- No duplications
- High expressiveness
- A minimal number of entities such as class, function, methods, and …
- Performance close to optimal
- Minimal dependencies on third parties
Meaningful Names
Names are the smallest building block of code. Names are everywhere: Function, class, file, component, and container all have names. Names are also the basic building blocks of clean code. There are some hard and fast rules to a good name.
Use intention-revealing names
A good name should answer only three questions.
I know it sounds simple, but it takes a lot of time to get a good name. However, it will save more than that in the long run.
A name should not have comments to express its intentions. Look at this example:
# Dirty Code d = 100 # elapsed time in days # Clean Code elapsed_time_in_days = 100
In the first case, you need to go through the comment. That’s okay for one time. But whenever you use the variable d
, you will have to come to the initialization to get the intention of the variable. But the second case, elapsed_time_in_days
, is expressive on its own.
Don’t give your variable a one-letter name. One-letter names are never expressive. They fail to reveal their intention. There are some exceptions…