8.coding Standards and Code Review Techniques
8.coding Standards and Code Review Techniques
1
Coding Standards
• Good software development organizations require
their programmers to:
• adhere some standard style of coding
• called coding standards.
2
Coding Standards
• Many software development organizations:
• formulate their own coding standards that suits
them most,
• require their engineers to follow these standards.
3
Coding Standards
4
• A coding standard
• sets out standard ways of doing
Coding several things:
• the way variables are named,
Standards • code is laid out,
• maximum number of source lines
allowed per function, etc.
5
Coding
guidelines
• Provide general
suggestions
regarding coding
style to be followed.
6
Code inspection and
code walk throughs
7
Code inspection and
code walk throughs
10
Representative
Coding Standards
• Contents of headers for
different modules:
• The headers of different
modules should be standard
for an organization.
• The exact format for header
information is usually
specified.
11
Representative
Coding Standards
• Header data:
• Name of the module,
• date on which the module was created,
• author's name,
• modification history,
• synopsis of the module,
• different functions supported, along
with their input/output parameters,
• global variables accessed/modified by
the module.
12
• Naming conventions for
global variables, local
variables, and constant
identifiers:
• A possible naming convention
can be that
• global variable names always
start with a capital letter,
• local variable names are made
of small letters,
• and constant names are
always capital letters.
13
• Error return conventions and
exception handling
mechanisms.
• the way error and exception
conditions are handled
Representative should be standard within an
organization.
Coding Standards • For example, when different
functions encounter error
conditions
• should either return a 0
or 1 consistently.
14
Representative Coding
Guidelines
• Do not use too clever and difficult to
understand coding style.
• Code should be easy to understand.
• Many inexperienced engineers actually
take pride:
• in writing cryptic and
incomprehensible code.
15
Representative Coding
Guidelines
• Clever coding can obscure meaning of the code:
• hampers understanding.
• makes later maintenance difficult.
• Avoid obscure side effects.
16
• Code should be well-documented.
• Rules of thumb:
Representative • on the average there must be
at least one comment line
Coding • for every three source lines.
Guidelines • The length of any function
should not exceed 10 source
lines.
17
• Lengthy functions:
Representative • usually very difficult to
understand
Coding Guidelines • probably do too many different
things.
18
• Do not use goto statements.
• Use of goto statements:
Representative
• make a program unstructured
Coding Guidelines • make it very difficult to
understand.
19
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.
• Normally, two types of reviews are carried
out on the code of a module.
• These two types code review techniques
are
1. code inspection and
2. code walk through.
20
An informal code analysis technique.
The members note down their findings to discuss these in a walk through
meeting where the coder of the module is present.
25
Code Inspection
Use of incorrect logical operators
• or incorrect precedence among operators.
26
Programming (Coding) Style &
Conventions
27