In this article we will explain tips that can help to have a cleaner code in our projects
1) Class Naming Guidelines
- Noun
- Be specific
- Single Responsability
- Avoid generic suffixes
2) Method Naming Guidelines
Avoid these words because it does not explain the functionality of the method well.
- Go
- Complete
- Get
- Process
- DoIt
- Start
- Init
- Load
3) Methods must perform an operation
if you see one of these words in your method name, it is a warning sign that your method may be doing more than one functionality.
- And
- If
- Or
4) Avoid Abbreviations
since there is no standardization of abbreviations in different languages, it is better to avoid abbreviations
for example, If we are discussing about a method, and we find these names in the method we don't know if we are talking about a "registry of clients", "registered clients", etc.
- RegCli
- RegistClient
- RegisCli
5) Naming Booleans In this case, the boolean variables must be named as if we were answering a question, since if we do not do so, it is difficult to know what status the application will be in when the variable is true or false.
avoid words like these
- open
- start
- status
- login
the word "open" if assigned a true or false value, it may be ambiguous for certain cases
it's better to use names like "isOpen", it answers the question "is it open?, it's more understandable for the other developers in the team
6) Naming Variables, Be Simetrical
When naming variables, it should be treated as far as possible that they are symmetric for better understanding, for example
- enable/off
- quick/slow
these examples of pairs of variable names are not symmetric, it is better if we use words that are direct antonyms
- on/off
- fast/slow