Clean code and Coding Standards

13
Clean Code and Coding Standards

Transcript of Clean code and Coding Standards

Clean Code and Coding Standards

Boy Scout Rule:“Always leave the campground cleaner than you found it.”

Meaningful Names (Open Discussion)

• Avoid Disinformation • Make Meaningful Distinctions • Use Pronounceable Names • Use Searchable Names • Member Prefixes (Avoid encodings) • Hungarian Notation (Avoid encodings) • Avoid Mental Mapping • Class and Method Names• Pick One Word per Concept

Functions (Open Discussion)

• Small functions• Do One Thing • One Level of Abstraction per Function • Reading Code from Top to Bottom • Use Descriptive Names • Function Arguments • Don’t Repeat Yourself (DRY) • Structured Programming • Indentation

Comments (Open Discussion)

• Comments Do Not Make Up for Bad Code // don’t comment bad code, rewrite it! • Explain Yourself in Code • Legal Comments • Informative Comments • Explanation of Intent • Clarification • Warning of Consequences • TODO Comments • Bad comments examples (/* The ****** variable */)

Formatting (Open Discussion)

• Team Rules: every programmer has his own favorite formatting rules but if he works in a team then the team rules.• Single template and color scheme for whole team.

Error Handling (Open Discussion)

• Prefer Exceptions to Returning Error Codes • Extract Try/Catch Blocks • Don’t Return Null

Questions?

Thank You!Mahesh Salaria