Clean code

Clean code that is easy to understand, maintain, and adapt

How to write it

  • Meaningful name for variables. Avoid Manager, Proxy, Data …

    • Use verbs for function names and nouns for classes and attributes

  • Small functions. Rule of nesting levels (max 3 levels)

  • Small function arguments. No more than 3, or encapsulate them into other

  • Single resposability

  • Tested/testable code

  • Use 1 formatting style

  • Comments are appreciated for complex functions (see function complexity)

  • Comments should address the logic/business, not the implementation

  • Don't reinvent the wheel just because you can

  • Don't use a library/framework just because you want to play with it. Side projects exist for a reason

  • Keep it DRY and SOLID (or shorter: keep it simple)

How to enforce it

  • Define coding guidelines

  • Code reviews / pair programming

  • Code analysis tooling (Sonar, linters, compiler configurations)

Last updated

Was this helpful?