1 - Coding Standards and Guidelines
1 - Coding Standards and Guidelines
Coding Standards
Some of the coding standards are given below:
Limited use of globals: These rules tell about which types of data that can
be declared global and the data that can’t be.
Standard headers for different modules: For better understanding and
maintenance of the code, the header of different modules should follow
some standard format and information. The header format must contain
below things that is being used in various companies:
o Name of the module
o Date of module creation
o Author of the module
o Modification history
o Synopsis of the module about what the module does
o Different functions supported in the module along with their input
output parameters
o Global variables accessed or modified by the module
Naming conventions for local variables, global variables, constants and
functions: Some of the naming conventions are given below:
o Meaningful and understandable variables name helps anyone to
understand the reason of using it.
o Local variables should be named using camel case lettering starting
with small letter (e.g. localData) whereas Global variables names
should start with a capital letter (e.g. GlobalData). Constant names
should be formed using capital letters only (e.g. CONSDATA).
o It is better to avoid the use of digits in variable names.
o The names of the function should be written in camel case starting
with small letters.
o The name of the function must describe the reason of using the
function clearly and briefly.
Indentation: Proper indentation is very important to increase the readability
of the code. For making the code readable, programmers should use White
spaces properly. Some of the spacing conventions are given below:
o There must be a space after giving a comma between two function
arguments.
o Each nested block should be properly indented and spaced.
o Proper Indentation should be there at the beginning and at the end of
each block in the program.
o All braces should start from a new line and the code following the
end of braces also start from a new line.
Error return values and exception handling conventions: All functions
that encountering an error condition should either return a 0 or 1 for
simplifying the debugging.
Coding Guidelines
Coding guidelines give some general suggestions regarding the coding style that to be
followed for the betterment of understandability and readability of the code.
Some of the coding guidelines are given below :
Avoid using a coding style that is too difficult to understand: Code
should be easily understandable. The complex code makes maintenance and
debugging difficult and expensive.
Avoid using an identifier for multiple purposes: Each variable should be
given a descriptive and meaningful name indicating the reason behind using
it. This is not possible if an identifier is used for multiple purposes and thus
it can lead to confusion to the reader. Moreover, it leads to more difficulty
during future enhancements.
Code should be well documented: The code should be properly
commented for understanding easily. Comments regarding the statements
increase the understandability of the code.
Length of functions should not be very large: Lengthy functions are very
difficult to understand. That’s why functions should be small enough to
carry out small work and lengthy functions should be broken into small ones
for completing small tasks.
Try not to use GOTO statement: GOTO statement makes the program
unstructured, thus it reduces the understandability of the program and also
debugging becomes difficult.
Naming conventions are a set of rules and guidelines that are used to define
the names of variables, functions, classes, and other entities in
programming. These conventions help ensure that the code is readable,
maintainable, and less prone to errors.
1. Camel Case:
Used for naming variables, functions, and methods in many
programming languages like JavaScript, Java, C#, and Python.
Provides a readable and brief way to name identifiers without spaces
or separators.
In camel case, you start a name with a small letter. If the name has
multiple words, the later words will start with a capital letter.
Example: calculateArea, getUserDetails, firstName, lastName.
2. Pascal Case:
Commonly used for naming classes, structs, and interfaces in object-
oriented programming languages like C#, Java, and TypeScript.
Helps distinguish classes and structs from other entities in the code.
In pascal case, you start a name with a capital letter. If the name has
multiple words, the later words will also start with a capital letter.
Example: UserProfile, HttpClient
3. Snake Case:
Widely used for naming file names, directories, and variables in
languages like Python, Ruby, and Rust.
Improves readability, especially when multiple words are used, and
makes it easy to differentiate words.
In the camel case, you start the name with a small letter in the snake
case. If the name has multiple words, the later words will start with
small letters and you use an underscore (_) to separate the words.
Example: user_profile, product_details, max_retries, first_name and
last_name.
5. Upper Case:
Used for naming constants in many programming languages like C++,
Java, and JavaScript.
Clearly distinguishes constants from variables and other identifiers,
making the code more self-documenting.
Example: MAX_VALUE, DEFAULT_TIMEOUT, PI
6. Hungarian Notation:
Prefixes variable names with one or more lowercase letters indicating
the data type or other information about the variable.
While it was popular in the past, it is now generally discouraged as it
can make code harder to read and maintain, especially with modern
IDEs that provide type information.
Example: strName (string), iAge (integer), bIsActive (boolean)
7. Train Case (also known as Hyphen-Separated Case):
Words are separated by hyphens, and the first letter of each word is
capitalized.
Sometimes used for naming database tables or columns, especially in
legacy systems or when interoperating with systems that have naming
conventions restrictions.
Example: User-Profile, Product-Details
8. Flat Case:
All letters are lowercase, and words are usually concatenated without
separators.
Used in some programming languages or frameworks that follow a
minimalist naming style or have specific naming guidelines.
Example: myvariable, calculatesum, persondetails