Naming things is one of the most difficult part of our job, still it is one of the more effective way to communicate the intention of a piece of code. Take a look to a real example.
At lastminute.com group we care about the software we
developed. We also always though that what makes a real professional software developer is how much he/she care about
the software he/she is creating: the approach to the problem, the attention to
details in code, the passion put into creating every single line of code, the focus on the mission to solve his/her
customer problems with your software.
In fact at lastminute.com group we try to follow an
approach called clean code, created by Robert Cecil Martin, known as “Uncle Bob”, and famous also to be the guy that invented the
SOLID principles.
In this blog post I will talk about one of the main principles of clean code: meaningful naming.

As stated by Uncle Bob in the beautiful meme above, this principle is simple: choose your name carefully.
But what does it really mean to “choose carefully”? . Choosing the right names means the following thing:
Let’s see an example to understand the real value of naming classes, methods, functions and variable in the right way. For example, take a look at the following C++ code:
struct pt {
float x;
float y;
float z;
};
struct mt {
public:
float m[4][4];
};
class Obj {
public:
bool act;
mt matr;
std::vector<pt> ms;
};
class GameManager {
public:
GameManager(std::vector<Obj> anObjList){
objList = anObjList;
}
std::vector<Obj> get() {
std::vector<Obj> newObjList;
for (auto currObj : newObjList) {
if (currObj.act && currObj.ms.size() > 0) {
newObjList.push_back(currObj);
}
}
return newObjList;
}
private:
std::vector<Obj> objList;
};Even if you can maybe get a feeling of what is going, it’s hard to really understand all the details of this code,
and every class, struct is supposed to do and to represent. What are pt and mt???? What is supposed to represent
a GameManager and an Obj? And the method get, what wants to get????? . You can see that a lot of
things are a little bit obscure in this code.
We can try to refactor it following the names guidelines we exposed above. Do you think the code will improve in this
way? You can judge it by yourself:
struct Point {
float x;
float y;
float z;
};
struct Matrix {
public:
float values[4][4];
};
class GameObject {
public:
bool isActive;
Matrix transformation;
std::vector<Point> mesh;
};
class Scene {
public:
Scene(std::vector<GameObject> newGameObjects){
gameObjects = newGameObjects;
}
std::vector<GameObject> getValidGameObjects() {
std::vector<GameObject> activeGameObjects;
for (auto gameObject : gameObjects) {
if (isValid(gameObject)) {
activeGameObjects.push_back(gameObject);
}
}
return activeGameObjects;
}
private:
std::vector<GameObject> gameObjects;
bool isValid(GameObject gameObject) {
return gameObject.isActive && isValid(gameObject.mesh);
}
bool isValid(std::vector<Point> mesh) {
return mesh.size() > 0;
}
};It’s incredible how the code now seems self explained. Each instruction appears more clear in its intents. Each class, struct and method doesn’t need any additional comment/documentation. I think it’s really amazing how some changes to the names could improve the quality of a piece of code dramatically like in our case. I hope that this article will convince you that the names you choose define how much you code is “beautiful” in terms of readability and also, more import, maintainability. Quoting what Grady Booch said about clean code:
Clean Code reads like a well-written prose.
Choosing the right names is the first step to make your code more similar to a well-written prose.
iOS localization is a wild ride where device and app locales play by their own rules. But don’t worry, after some chaos, Apple’s settings actually matched our expectations. Of course, only after a few twists and turns [...]