INSIGHTS

Developing QA Code With Quality | Part I – Clean code: Names

On our world names is so important to everything, so with our source code is not different, we need to give a name to everything, classes, methods, variables, and because this we need to give a good names.

In clean code we have some tips to give good names in our source code, when i’m coding i use a lot this two:

Intention-Revealing Names

Avoid Disinformation

Intention-Revealing Names, to me this is a very important concept, because the name can give some informations to another developers just using the name of a variable, class, or method, we can select a name with a answer of this questions for exemple:

why it exists ? what it does ? how it is used ?

We need to avoid disinformation in our source code, and the names used in our source code is a good way to do it. When i talk about disinformation in source code, especificly in name of things, is related to avoid use a names not related with the propouse of creation. In some cases whe give a arbitraty names, or try to avoid a long names and the result is a lot of bad names, for example, A, I, B2, this is a bad names, and is very common to find in a source code, another good example is when we use a generic names and in that part of code can represent a lot of things and generate more doubts to another developers:

int timeLeft
why we need this?
timeleft for what ?
how mutch time we have?

To finish this first talk about clean code in QA code, i want to talk more two good tips to give a good name to methods and classes.

Methods names

Methods should have verb or verb phrase names like deleteOrder, saveClient, orderProducts. And another very important thing is to use the get and set therms to access values, and is for methods with boolean return type.

Class names

Classes and objects should have noun or noun phrase names like OrderClient, PaymentMethod.

Scope Rule:

Variables with long scopes need long names, and when a variable was on short scope, you can use a short names.

Methods have the opossite condition, when a method was on long scope the name can be short, but when you was in short scope, need a long name.

https://cleancoders.com/

Enjoy this insight? Share it!

Learn more

Let’s talk