In this post I’m going to show you how to write code that is easy to read, maintain and understand.
Coding is for humans.
Clean code is the art of writing code that humans can understand.
Any fool can write code that a computer can understand.
Good programmers write code that humans can understand
We’ll walk through 3 core clean coding practices:
- Stay Native
- Maximize Signal to Noise Ratio
- Write Self-Documenting Code
1. Stay Native
Avoid using one language to write another language via strings.
Do not use strings in C#, Java etc. to generate
2. Maximize Signal to Noise Ratio
Signal is code that follows the TED rule. It is Terse, Expressive and Does one thing.
Noise is anything else:
• Huge Classes
• Long Methods
• High Complexity
• Excessive Indentation
• Unnecessary Comments
• Poor Naming
3. Write Self-Documenting Code
Understanding the original programmer’s intent is the most difficult problem.
Code’s author intent should be clear. Well written code is self-documenting and can reduce and hopefully eliminate the need for comments or external documentation like Javadoc or Wikis.
Self-documenting code does 4 core things:
- Expresses author’s intent clearly
- Uses layers of abstraction (code navigable through different levels of details)
- Is formatted for readability
- Favors self-expressing code over comments