9 Clean Code principles you can apply NOW in your code
1. Meaningful Names:
Use names in your code that are
, that are
2. Be careful with comments:
Comments aren't always good, and can even be harmful at times.
So use comments only when strictly necessary and remember to update when you change in code.
3. Don't Repeat Yourself:
One of the most important rules in Clean Code. This concept shows that there should not be two parts of the software performing the same function.
4. Follow code patterns:
Patterns make the code much easier to understand. Thus, character variations in naming, such as the usage of capital or lowercase letters should be standardized.
5. The Boy Scout Rule:
The code has to be kept clean over time. The code could not become a mess if we all submit our code a little cleaner than when we first saw it.
6. Error Handling:
It must do what was planned, but if an error appears, it should be able to handle it.
7. Keep tests clean:
Programmers get a suite of tests to pass, they must make sure that those tests were convenient to run for anyone else who needed to work with the code.
8. Keep functions small:
If you have a function in your code with more one concern that function can be split in smaller functions with meaningful names. This makes your code easier to understand and maintain in the future.
9. Think of your code as a book:
This last principle principle is essential to Clean Code. Your code must be easy to read and understand, like a regular book.