Clean code: Qualidade e excelência no código (Published)

Read on Notion
46
Video preview
 
The world demands better code. - "Uncle Bob", Robert C. Martin
 

What is "Clean Code"?

Clean Code is a set of best practices for writing code that is clean, easy to understand, maintain, and evolve.
 

Principles:

  1. Naming conventions
  1. Small and simple functions (SOLID principles)
  1. Precise and useful comments
  1. Reusability
  1. Testing
  1. Standardization
  1. Separation of responsibilities
  1. Reduction of complexity (KISS)
  1. Constant refactoring (scout rule)
  1. Code formatting (elegance)
 
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." - Martin Fowler
 
"Can I see your code?"
notion image
 
 
"It's still messy; I'll improve and refactor the code later."
notion image
 
Ugly children have no parents! 😂
 
"I did my best within the time I had." "But the deadline was extremely short." "My manager pressures me all the time." "I need to deliver, I need to be very productive."
 
When we hear these phrases, it's certain that the professional isn't satisfied with the work done and isn't proud of their own code. The code is likely poorly structured and challenging to maintain. Often, when other developers analyze such contaminated code, they prefer starting a new project from scratch instead of venturing into that code.
 
There's no excuse for poorly written code!
notion image
 
Take pride in your code.
 
Enough small talk; let's get to the point.
Examples? We have them!
 

1. Naming

 
Bad code example:
 
Clean code example:
 

2. Classes

 
Bad code example:
 
Clean code example:
 

3. Methods

 
Bad code example:
 
Clean code example:
 

4. Conditions

 
Bad code example:
 
Clean code example:
 

5. Abstraction

 
Bad code example:
 
Clean code example:
 

6. Exceptions

 
Bad code example:
 
Clean code example:
 

7. Law of Demeter

A method M of a class C should only know:
 
Bad code example:
 
Clean code example:
 

8. Comments

 
Bad code example:
 
Clean code example:
 

9. Code Formatting (Elegance)

 
Bad code example:
 
Clean code example:
 

10. Testing

 
Follow the "F.I.R.S.T." principles for testing:
 

Scout Rule (Rule of the Scout)

"Leave the campground cleaner than you found it." "Leave the code cleaner than you found it."
 
That's it!
 
Developing projects with quality is challenging, especially with tight deadlines, but by adhering to standards and best practices, you can increase the chances of success.
Take pride in your code and show that you care. Poor code can harm careers and destroy companies.
I hope your coding performance improves after this presentation. Let's work together to make the world a better place for us developers.
 
notion image
 
And don't forget, always maintain the standard and take pride in your code!