100% found this document useful (1 vote)
69 views

Clean Code Checklist

The document provides a checklist for writing clean code with guidelines in several areas: 1. Naming conventions including using descriptive names for variables, functions, classes and avoiding misleading names. 2. Comments and formatting with most comments being unnecessary and guidelines for vertical and horizontal formatting of code. 3. Functions should have a single purpose, small number of parameters, and avoid side effects. 4. Control structures and errors with preferences for positive checks, guard clauses, and extracting logic over deep nesting and synthetic errors. 5. Classes and objects focusing on high cohesion and single responsibility following principles like DRY, Law of Demeter and SOLID.

Uploaded by

nitishgalaxy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
69 views

Clean Code Checklist

The document provides a checklist for writing clean code with guidelines in several areas: 1. Naming conventions including using descriptive names for variables, functions, classes and avoiding misleading names. 2. Comments and formatting with most comments being unnecessary and guidelines for vertical and horizontal formatting of code. 3. Functions should have a single purpose, small number of parameters, and avoid side effects. 4. Control structures and errors with preferences for positive checks, guard clauses, and extracting logic over deep nesting and synthetic errors. 5. Classes and objects focusing on high cohesion and single responsibility following principles like DRY, Law of Demeter and SOLID.

Uploaded by

nitishgalaxy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Clean Code - Checklist

Naming
Use descriptive and meaningful names
Variables & Properties: Nouns or short phrases with adjectives
Functions and Methods: Verbs or short phrases with adjectives
Classes: Nouns
Be as specific as necessary and possible
Use yes/ no "questions" for booleans (e.g. isValid)
Avoid misleading names
Be consistent with your names (e.g. stick to get... instead of fetch...)

Comments & Formatting


Most comments are bad - avoid them!
Some good comments are acceptable
Legal comments
Warnings
Helpful explanations (e.g. for Regex)
Todos (don't overdo it though)
Use vertical formatting:
Keep related concepts close to each other (vertical density)
Add spacing / distance (e.g. blank linkes) between concepts that are not
directly related (vertical distance)
Write code top to bottom: Called functions should come below calling
functions (if possible)
Use horizontal formatting:
Avoid long lines - break them into multiple lines instead
Use indentation to express scope

Functions
Functions
Limit the number of parameters your functions use - less is better!
Consider using objects, dictionaries or arrays to group multiple parameters into
one parameter
Functions should be small and do one thing
Levels of abstraction inside the function body should be one level below the
level implied by the function name
Avoid mixing levels of abstractions in functions
But: Avoid redundent splitting!
Stay DRY (Don't Repeat Yourself)
Avoid unexpected side effects

Control Structures & Errors


Prefer positive checks
Avoid deep nesting
Consider using "Guard" statements
Consider using polymorphism and factory functions
Extract control structures into separate functions
Consider using "real" errors (with error handling) instead of "synthetic errors"
built with if statements

Objects & Classes


Focus on building "real objects" or data containers / structures
Build small classes - focus on a single responsibility (which does not mean "single
method"!)
Build classes with high cohesion
Follow the "Law of Demeter" for "real objects" (avoid
this.customer.lastPurchase.date)
Especially when doing OOP: Follow the SOLID principles
Especially SRP and OCP will help a lot with writing clean code (= readable code)

You might also like