Skip to content

Instantly share code, notes, and snippets.

@zero88
Last active July 23, 2018 14:22
Show Gist options
  • Select an option

  • Save zero88/88b5a638fc9005576c903f4153b94d45 to your computer and use it in GitHub Desktop.

Select an option

Save zero88/88b5a638fc9005576c903f4153b94d45 to your computer and use it in GitHub Desktop.

Revisions

  1. @Zero-88 Zero-88 revised this gist Jul 23, 2018. 1 changed file with 32 additions and 1 deletion.
    33 changes: 32 additions & 1 deletion CleanCode.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,32 @@
    # Clean Code
    # Clean Code

    **Code for human not machines**

    Code is clean if anyone in team can understand, easy to read and enhance by other developer instead of origin author.

    Code clean is readability, flexibility, extensibility, maintainability.

    Bullet points:

    1. Keep code simple stupid.
    - Reduce complexity algorithm as muc as possible.
    - Return code early to keep `code_indent <= 3`
    - Avoid negative condition
    2. Follow one consistence coding standard for **_team_**.
    3. Naming convention
    - Variable/function/class/module name is meaningful, explanatory.
    - Name can be long if it is public, short name is acceptable if it is private.
    - Function/ Method name is Verb, meanwhile variable/class/module is Noun.
    - Extract magic number to constants.
    4. Don't repeat yourself: No duplicate code.
    5. Single responsibility
    - Single module/package contains a set of similar classes, that represents one campaign concept.
    - Single class wraps a set of similar functions, that represents one duty of campaign.
    - Single function covers one and only one purpose, and do it well.
    6. No god class, long method, many arguments/parameters in method
    - Class: `line_of_code < 1000`
    - Method: `line_of_code < 50`
    - Method parameters: `total_parameter < 5`
    7. Catching and logging exception even if exception is thrown in silent.
    8. Loose coupling: each software layer (presentation layer/business layer/persistence layer/database layer, etc.) or each part in MVC communicates to each other via abstract interface instead of concreate.
    9. Code modular: seprate functionality into independent and interchangeble module. Use more `composite/component` pattern instead of `inheritance`.
  2. @Zero-88 Zero-88 created this gist Jul 23, 2018.
    1 change: 1 addition & 0 deletions CleanCode.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    # Clean Code