Clean Code
We see this word a lot in SonarQube documentation, so it's worth explaining it better.
The goal is to achieve code that respects clean code rules, and what does that mean? It means the code needs to achieve certain attributes of consistency, intentionality, adaptability, and responsibility.

Consistency
Code should be uniform and conventional. All code should look similar and follow a regular pattern.
- Formatting
- Equally among all who contribute to a project. Some people use 4 spaces to differentiate blocks in a YAML file and others use 2.
- It's good to use a linter to achieve this goal.
- Conventional
- Use language features appropriately.
- Identifiable
- Names for variables, functions, etc. follow a pattern based on the language convention.
Intentional
Precise and purposeful code where each instruction makes sense.
-
Clean and Clear
- Code is self-explanatory and written directly without ambiguities.
-
Logical
- Well-formatted and solid instructions. Free from contradictions and unpredictable or questionable commands.
-
Complete
- Code used appropriately, being functional and achieving implicit objectives. For example, a function that receives several parameters but works with half of them.
-
Efficient
- Uses resources without waste, prioritizing more economical options for memory, processor, disk, and network usage.
Adaptability
The code is structured to be easy to evolve and develop with confidence. It makes it easy to extend or reuse its parts and promotes localized changes without unwanted side effects.
- Focused
- The code has a single and specific scope. Units do what they have to do without accumulation of instructions or complexity.
- Distinct
- Each part does what it needs to do without undue code duplication.
- Modular
- Code organized with separation between its parts, with relationships within the code being well managed.
- Tested
- Has test coverage
Responsibility
Takes into account ethical obligations regarding data.
-
Legal
- Respects licensing regulations and copyrights by exercising the creator's rights and honoring others' rights to license their own code.
-
Trustworthy
- Preserves private and sensitive information. Using credentials inside code is a great example of this.
-
Respectful
- Does not use discriminatory and offensive language.