0% found this document useful (0 votes)
20 views10 pages

Adv Software Engineering Lect7-1

Coding standards provide uniformity in coding style and conventions to improve code readability, understanding, and maintenance. They define naming rules, error handling, documentation standards, and prohibitions on obscure code. Code reviews like walkthroughs and inspections help find logical errors by simulating execution and examining for specific bugs. They are effective for producing high quality code.

Uploaded by

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

Adv Software Engineering Lect7-1

Coding standards provide uniformity in coding style and conventions to improve code readability, understanding, and maintenance. They define naming rules, error handling, documentation standards, and prohibitions on obscure code. Code reviews like walkthroughs and inspections help find logical errors by simulating execution and examining for specific bugs. They are effective for producing high quality code.

Uploaded by

A Rauf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10

Coding

Chapter 23
Sommerville
Coding
• Good software development organizations normally require
their programmers to adhere to some well-defined and
standard style of coding called coding standards.

• The purpose of requiring all engineers of an organization to


adhere to a standard style of coding is the following:

• A coding standard gives a uniform appearance to the codes


written by different engineers.
• It enhances code understanding.
• It encourages good programming practices.
Coding standards
• 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.
• Error return conventions and exception handling mechanisms:
• The way error conditions are reported by different functions in a
program are handled should be standard within an organization.
For example, different functions while encountering an error
condition should either return a 0 or 1 consistently.
Coding Standards
• Avoid obscure side effects:
• The side effects of a function call include modification of
parameters passed by reference, modification of global variables,
and I/O operations. An obscure side effect is one that is not
obvious from a casual examination of the code. Obscure side
effects make it difficult to understand a piece of code.
• For example, if a global variable is changed obscurely in a called
module or some file I/O is performed which is difficult to infer
from the function’s name and header information, it becomes
difficult for anybody trying to understand the code.
Coding Standards
• Do not use an identifier for multiple purposes

• Programmers often use the same identifier to denote several


temporary entities. For example, some programmers use a
temporary loop variable for computing and a storing the final
result.

• Each variable should be given a descriptive name indicating its


purpose. This is not possible if an identifier is used for multiple
purposes. Use of a variable for multiple purposes can lead to
confusion and make it difficult for somebody trying to read and
understand the code.

• Use of variables for multiple purposes usually makes future


enhancements more difficult.
Coding Standards
• The code should be well-documented:
• As a rule of thumb, there must be at least one comment line on
the average for every three-source line.

• Do not use goto statements:


• Use of goto statements makes a program unstructured and
makes it very difficult to understand.
Code review
• Code reviews are extremely cost-effective strategies for
reduction in coding errors and to produce high quality code.

• Code walk through


• Code Inspection
Code walk through
• 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.
Code Inspection
• 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
through.

• Use of uninitialized variables.


• Nonterminating loops.
• Incompatible assignments.
• Array indices out of bounds.
• Improper storage allocation and deallocation.
• Mismatches between actual and formal parameter in
procedure calls.
• Improper modification of loop variables.
Summary
• Coding Guidelines/Standards

• Code Walkthrough

• Code Inspections

You might also like