Coding Standards
Coding Standards
Coding standards are a set of guidelines, best practices, and rules that
developers follow when writing code. These standards help ensure that code is
consistent, readable, maintainable, and understandable across a
development team or organization
1. Limited use of globals: Using global variables can lead to unexpected side effects, as
any part of the program can modify them. This makes debugging harder. Use local
variables inside functions whenever possible.
2. Standard headers for different modules: Each module (or file) should start with a
standard header that includes important information, like the file’s purpose, author,
and date, making it easier to understand the code.
3. Naming conventions for local variables, global variables, constants, and functions:
Proper naming convention for different variables ,constants should be followed so
that one can easilty identify that wheter a variable is global , local etc .
A possible naming convention can be that global variable names always begin with a
capital letter, local variable names are made of small letters, and constant names are
always capital letters.
4. Indentation: Use consistent indentation to make the structure of the code clear,
making it easier to read and understand.
5. Error return values and exception handling conventions: Clearly define how your
code should handle errors and exceptions to avoid unexpected behavior and make
debugging easier. Different functions in a program report the way error conditions
are handled should be standard within an organization. For example, different tasks
while encountering an error condition should either return a 0 or 1 consistently.
6. Avoid using a coding style that is too difficult to understand: Keep the coding style
simple and clear, so others (and your future self) can easily understand the code.
7. Code should be well documented: Include comments and documentation explaining
how the code works and why certain decisions were made, making it easier for
others to work with it.
8. Try not to use GOTO statements: Avoid using GOTO statements, as they can make
the code confusing and harder to follow. Instead, use structured control flow
statements like loops and conditionals.