Coding Standards

Understand why and how to write consistent code

Why have standards?

  • Code consistency
  • Establish best practices
  • Gives a uniform appearance to the codes written by different engineers
  • Aid in the on-boarding process and guide new developers
  • Encourage consistent conventions between team members
  • The purpose of coding standards is to establish a common style and convention for writing code. This helps to ensure that the code is free from errors and bugs, and that it is easy to understand and modify.
  • By maintaining consistency in coding style and convention, we can ease the burden of legacy code maintenance, and mitigate risk of breakage in the future
  • Easier for developers to understand and work with the code, leading to high-quality code
  • Improves readability, and maintainability of the code and it reduces complexity also. It helps in code reuse and helps to detect error easily
  • By reusing design system components code becomes more consistent and robust.

Best Practices

Avoid using an identifier for multiple purposes

It is important to avoid using the same identifier for multiple purposes. Moreover, it leads to more difficulty during future enhancements. Here are some examples of valid identifiers in JavaScript.

                                                            firstName, lastName, isMarried, userAddress

Length of functions should not be very large

Functions should be small enough to carry out small work and lengthy functions should be broken into small ones for completing small tasks. The length of a function should not be very large as it makes the code difficult to understand and maintain.

Avoid using a coding style that is too difficult to understand

Code should be easy to understand. Complex code makes it hard and costly to maintain and debug.

Comments can sometimes be useful

When explaining why something is being implemented in a particular way.

Further Information