Skip to content

alisalehi1380/Key-points-of-clean-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Clean code that is easily understood by all team members. Clean code can be read and developed by a developer other than its author. Code readability, maintainability, modifiability, and extensibility are only possible when you properly understand how the code works.


General rules

  1. Follow standard rules such as naming classes and functions, the amount of indentation, etc. (Standard Conventions)
  2. Reduce the complexity in the code as much as possible. Simplicity is always better. (Law KISS)
  3. Deliver source code cleaner than when you receive it. (Law Boy Scout)
  4. Always look for finding problems and bugs in the code. To fix them, identify main and root causes. (Act RCA)

Design rules

  1. Variables, constants and all configurable data must be at the highest level of abstraction. (Configurable Data At High Levels)
  2. Instead of breaking the open-closed rule, use the polymorphism property. (Replace Conditional With Polymorphism)
  3. (Separate multi-threading code)
  4. Avoid giving your application developers too much freedom of action. (Prevent Over-Configurability)
  5. Instead of creating objects (using new), use dependency injection. (Dependency Injection)
  6. Functions and classes should not have access to other details in the code except what they do. (Law LoD)

Rules of functions

  1. Your functions should be small. (Small)
  2. Each function should do one thing only. (Do one thing)
  3. The name you choose for each function should fully describe what it does. (Use descriptive names)
  4. The best function is the Niladic function (Niladic). Your function should take the fewest arguments possible. (Prefer fewer arguments)
  5. Your function should not change anything that is outside its scope. (Have no side effects)

Tests

  1. Each test (it is better) to have just one assertion. (One Assertion Per Test)
  2. Follow the F.I.R.S.T rules.
    1. Your tests must run quickly, even if there are 1000 of them. (Fast)
    2. Your tests should be isolated and independent and nothing, including the operating system, environment variables, other programmer's codes, should interfere with their work. (Isolated/Independent)
    3. Your tests should be conclusive and repeatable, their variables should not change in different environments. (Repeatable)
    4. (Self-validating)
  3. Your tests should be easy to read and understand. (Readability)

About

Key points of clean code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published