Coding rules

3. Coding rules#

last update: Feb 07, 2024

Coding rules are guidelines that help developers write clean, readable, and maintainable code. They can be enforced manually or through the use of automated tools.

Some common coding rules include:

  • Use consistent naming conventions for variables, functions, and classes.

  • Use meaningful variable names that reflect the purpose of the data they represent.

  • Avoid using abbreviations or acronyms unless they are widely used.

  • Avoid using magic numbers.

  • Avoid using global variables.

  • Avoid deep nesting.

  • Avoid duplicating code. Instead, use functions or classes to encapsulate reusable logic.

  • Write small functions that perform a single task.

  • Don’t reinvent the wheel.

  • Remove unused or commented-out code.

  • Use comments to explain complex logic and describe the purpose of each function.

  • Use whitespace and indentation to make your code easier to read.

  • Use error handling techniques to prevent unexpected behavior or crashes.

  • Test your code thoroughly to ensure that it works as expected and is free of bugs.

  • Use version control to keep track of changes and collaborate with other developers.

By following coding rules, developers can write code that is easy to understand, modify, and maintain, which can save time and reduce errors in the long run.