0% found this document useful (0 votes)
18 views4 pages

Coding Standards and Guidelines

Uploaded by

arafaths062
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

Coding Standards and Guidelines

Uploaded by

arafaths062
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Coding Standards, Guidelines and Code Review

Different modules specified in the design document are coded in the coding phase according to the
module specification

The main goal of the coding phase is to code from the design documents prepared after the design
phase through a high-level language and then to unit test this code.

Good software development organizations want their programmers to maintain to some well-defined
and standard style of coding called coding standards.

They usually make their own coding standards and guidelines depending on what suits for their
organization best and based on the types of software they are going to develop

It is very important for the programmers to maintain the coding standards otherwise the code will be
rejected during code review.

Purpose of having Coding Standards:

 It improves readability, and maintainability of the code and it reduces complexity also.
 It helps in code reuse and helps to detect errors easily
 It promotes sound programming practice and increases efficiency of the programmers.
 A coding standard gives a uniform appearance to the codes written by different engineers

Some of the coding standards are given below:

1. Limited use of globals:

These rules tell about which types of data that can be declared global and the data that can’t be.

2. 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:

 Name of the module


 Date of module creation
 Author of the module
 Modification history
 Synopsis of the module about what the module does
 Different functions supported in the module along with their input and output
parameters
 Global variables accessed or modified by the module
3. Naming conventions for local variable, global variables, constants and functions

Some of the naming conventions are given below:

 Meaningful and understandable variables name helps anyone to understand the reason of
using it
 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 letters( e.g.
GlobalData).Constant names should be formed using capital letters only( e.g CONSDATA)
 It is better to avoid the use of digits in variable names
 The names of the function should be written in camel case starting with small letters
 The name of the function must describe the reason of using the function clearly and briefly

4. 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

 There must be a space after giving a comma between two function arguments
 Each nested block should be properly indented and spaced.
 Proper indentation should be there at the beginning and at the end of each block in the
program
 All braces should start from a new line and the code following the end of braces also
start from a new line

5. Error return values and exception handling conventions:

All functions that encountering an error condition should either return 0 or 1 for simplifying the
debugging.

On the other hand, 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.

6. 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.

7. 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
8. Code should be well documented:

The code should be properly commented for understanding easily. Comments regarding the
statements increase the understandability of the code.

9. 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

10. 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.

Advantages of Coding Guidelines:

 Coding guidelines increase the efficiency of the software and reduces the development time
 Coding guidelines help in detecting errors in the early phases, so it helps to reduce the extra cost
incurred by the software project
 If coding guidelines are maintained properly, then the software code increases readability and
understandability thus it reduces the complexity of the code.
 It reduces the hidden cost for developing the software

Code Review:

Code review for a model is carried out after the module is successfully compiled and the all the syntax
errors have been eliminated. Code reviews are extremely cost-effective strategies for reduction in
coding errors and to produce high quality code. Normally, two types of reviews are carried out on the
code of a module. These two types code review techniques are code inspection and code walk through.

Code Walk Throughs:

Code walk through is an informal code analysis technique. In this technique, after a module has been
coded, successfully compiled and all syntax errors eliminated. A few members of the development team
are given the code few days before the walk through meeting to read and understand code. Each
member selects some test cases and simulates execution of the code by hand (i.e. trace execution
through each statement and function execution). The main objectives of the walk through are to
discover the algorithmic and logical errors in the code. The members note down their findings to discuss
these in a walk through meeting where the coder of the module is present. Even though a code walk
through is an informal analysis technique, several guidelines have evolved over the years for making this
naïve but useful analysis technique more effective. Of course, these guidelines are based on personal
experience, common sense, and several subjective factors. Therefore, these guidelines should be
considered as examples rather than accepted as rules to be applied dogmatically. Some of these
guidelines are the following:

 The team performing code walk through should not be either too big or too small. Ideally, it
should consist of between three to seven members.

 Discussion should focus on discovery of errors and not on how to fix the discovered errors.

 In order to foster cooperation and to avoid the feeling among engineers that they are being
evaluated in the code walk through meeting, managers should not attend the walk through
meetings.

Code Inspection:

In contrast to code walk through, the aim of code inspection is to discover some common types of
errors caused due to oversight and improper programming. In other words, during code inspection the
code is examined for the presence of certain kinds of errors, in contrast to the hand simulation of code
execution done in code walk throughs. For instance, consider the classical error of writing a procedure
that modifies a formal parameter while the calling routine calls that procedure with a constant actual
parameter. It is more likely that such an error will be discovered by looking for these kinds of mistakes in
the code, rather than by simply hand simulating execution of the procedure. In addition to the
commonly made errors, adherence to coding standards is also checked during code inspection. Good
software development companies collect statistics regarding different types of errors commonly
committed by their engineers and identify the type of errors most frequently committed. Such a list of
commonly committed errors can be used during code inspection to look out for possible errors.
Following is a list of some classical programming errors which can be checked during code inspection:

 Use of uninitialized variables.


 Jumps into loops.
 Nonterminating loops.
 Incompatible assignments.
 Array indices out of bounds.
 Improper storage allocation and de-allocation.
 Mismatches between actual and formal parameter in procedure calls.
 Use of incorrect logical operators or incorrect precedence among operators.
 Improper modification of loop variables.
 Comparison of equally of floating point variables, etc.

You might also like