Docsity

Coding Standards and Guidelines: Best Practices for Software Development - Prof. Kapoor, Lecture notes of Software Engineering

Partial preview of the text

Download Coding Standards and Guidelines: Best Practices for Software Development - Prof. Kapoor and more Lecture notes Software Engineering in PDF only on Docsity!

Coding

 At the end of the design phase we have:

 module structure of the system

 module specifications:

 data structures and algorithms for each module.

 Objective of coding phase:

 transform design into code

 unit test the code.

Coding Standards

Good software development

organizations require their

programmers to:

adhere some standard style

of coding

called coding standards.

Coding Standards

 Advantage of adhering to a

standard style of coding:

 it gives a uniform appearance

to the codes written by

different engineers,

 it enhances code

understanding,

 encourages good programming

practices.

Coding Standards

 A coding standard

 sets out standard ways of

doing several things:

 the way variables are named,

 code is laid out,

 maximum number of source

lines allowed per function,

etc.

Code inspection and code

walk throughs

After a module has been

coded,

code inspection and code

walk through are carried out

ensures that coding

standards are followed

helps detect as many errors

as possible before testing.

Code inspection and code

walk throughs

 Detect as many errors as

possible during inspection and

walkthrough:

 detected errors require less

effort for correction

 much higher effort needed if

errors were to be detected during

integration or system testing.

Representative Coding

Standards

 Rules for limiting the use of globals:

 what types of data can be declared

global and what can not.

 Naming conventions for

 global variables,

 local variables, and

 constant identifiers.

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.

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.

Representative Coding

Standards

 Error return conventions and

exception handling mechanisms.

 the way error and exception

conditions are handled should be

standard within an organization.

 For example, when different

functions encounter error conditions

 should either return a 0 or 1

consistently.

Representative Coding

Guidelines

Clever coding can obscure

meaning of the code:

 hampers understanding.

makes later maintenance

difficult.

Avoid obscure side effects.

Representative Coding

Guidelines

Code should be well-documented.

Rules of thumb:

 on the average there must be at

least one comment line

 for every three source lines.

 The length of any function should

not exceed 10 source lines.

Representative Coding

Guidelines

Do not use goto statements.

Use of goto statements:

make a program unstructured

make it very difficult to

understand.

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 code inspection and code walk

through.