Coding Best Practices

These are a set of informal rules that helps code readibility and improve the processes involved in software development and results in higher quality of software.

Coding Styles

I recommend using AirBnB JavaScript style guide for any JavaScript project. This contains a broad set of rules that can be applied to other programming languages. Also using a good linter is recommended to consistently maintain coding styles.

For Python users I recommend Google Python Style Guide and Data Camp Code Standards in Python

Here a few key code style notes below:

Naming Conventions

It is important to have a solid and consistent naming convention when developing software. The most common is camelCase/PascalCase/under_score. In JavaScript camelCase is used for variables and functions with class definitions being defined with PascalCase and constants as UPPERCASE/under_score.

Meaningful Naming Conventions

Avoid abbreviations or meanlingless names when naming variables/functions etc. Make it obvious to any first time reader of your code what the variable/function is/does. Not too short, not too verbose.

Use Adjective/Nouns combinations to define variables e.g. homeNumber Use "Verb-Noun" to define method names e.g. getItemById() or setAddress()

Prefix Boolean method names with is e.g. isMale()

Common & Consistent Code Formating

Make sure that all code is formatted consistently, e.g. line spacing, tab size, function declarations, for loops, if statements etc should be formatted consistently across the codebase.

Best Practices

  • Try and use Pure functions when possible, this reduce side effects/bugs.
  • DRY Principle - Don't Repeat Yourself principle
  • Avoid Deep Nesting
  • Limit Line Length
  • Reduce Global Variables
  • Focus on Component Design/Modularization
  • Embrace Progressive Enhancement (based on device and broadband quality)

References