chapter8 coding

Upload: nirmal-patra

Post on 08-Apr-2018

240 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 Chapter8 Coding

    1/16

    CodingCoding

    y Introduction

    y Coding Standards

    y

    Coding Guidelinesy Code Walkthrough

    y Code Inspection

    y

    Software Documentationy Gunnings Fog Index

    1

  • 8/7/2019 Chapter8 Coding

    2/16

    IntroductionIntroduction

    y The input to the coding phase is the designdocument.

    y During coding phase:

    Modules identified in the design document arecoded according to the module specifications.

    y At the end of the design phase we have: module structure (e.g. structure chart) of the system module specifications:x data structures and algorithms for each module.

    y Objective of coding phase: transform design into code unit test the code.

    2

  • 8/7/2019 Chapter8 Coding

    3/16

    Coding StandardsCoding Standards

    y Good software developmentorganizations require theirprogrammers to:

    adhere to some standard style of codingcalled coding standards.

    y Many software developmentorganizations:

    formulate their own coding standards thatsuits them most,

    require their engineers to follow thesestandards rigorously

    3

  • 8/7/2019 Chapter8 Coding

    4/16

    CodingCoding StandardsStandards --AdvantageAdvantage

    y Advantage of adhering to a standard style of

    coding:

    it gives a uniform appearance to thecodes written by different engineers,

    it enhances code understanding,

    encourages good programming practices.

    4

    A coding standard sets out standard ways of doing several things -

    the way variables are named, code is laid out , comments etc.

  • 8/7/2019 Chapter8 Coding

    5/16

    Representative Coding StandardsRepresentative Coding Standards

    y Naming conventions for global variables,

    local variables, and

    constant identifiers.

    y Contents of headers of different modules 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 theirinput/output parameters,

    5

  • 8/7/2019 Chapter8 Coding

    6/16

    CodingCoding GuidelinesGuidelines

    y Code should be easy to understand

    Dont take pride in cryptic code

    y Code should be well documented

    Comments should be present

    Functions should be small

    y Do not use Goto statements

    y Do not use the same variable for multiple

    purpose

    6

  • 8/7/2019 Chapter8 Coding

    7/16

    Code inspection and code walkCode inspection and code walk

    throughthroughy After a module has been coded,

    code inspection and code walk through are carriedout

    ensures that coding standards are followed helps detect as many errors as possible before

    testing.

    y Detected errors require much less effort forcorrection

    y Effort required is much higher if errors aredetected during integration or system testing

    7

  • 8/7/2019 Chapter8 Coding

    8/16

    Code walk throughCode walk through

    y Informal code analysis technique

    y Some test cases are selected and theirexecution are simulated by hand

    y Process of walk through are governed bythe developers experience and ability

    y Code walk through should not be one of

    the evaluation criteria of a developery Purpose should be error discovery and not

    how to fix errors

    8

  • 8/7/2019 Chapter8 Coding

    9/16

    Code InspectionCode Inspection

    y Its purpose is to find common made

    errors by going through the code

    y Good companies record all the common

    errors made by a developer which

    becomes a checklist for future

    y Coding standard is also verified here

    y Examples Checking for infinite loops

    Checking for incorrect logical operators

    9

  • 8/7/2019 Chapter8 Coding

    10/16

    Software DocumentationSoftware Documentation

    y When developing a software product wedevelop various kinds of documents apartfrom the executable files and the sourcecode:

    users' manual,

    software requirements specification (SRS)document,

    design document, test document, installation manual, etc.

    y All these documents are a vital part of goodsoftware development practice.

    10

  • 8/7/2019 Chapter8 Coding

    11/16

    Software DocumentationSoftware Documentation

    y Software documents can be classified into:

    internal documentation,

    external documentation (supporting documents).

    11

    Internal documentation Documentation present inthe source code

    External documentation Documentation presentother than those in the source code

  • 8/7/2019 Chapter8 Coding

    12/16

    Internal DocumentationInternal Documentation

    y Good software development organizations

    ensure good internal documentation through

    coding standards and coding guidelines.

    y Example of unhelpful documentation:

    a = 10; /* a made 10 */

    y Observation suggests:

    meaningful variable names

    is the most useful internal documentation.

    12

  • 8/7/2019 Chapter8 Coding

    13/16

    External DocumentationExternal Documentation

    y A systematic software development styleensures that all external documents are

    produced in an orderly fashion.

    y

    An important feature of good documentationis consistency.

    y All the documents should be up to date

    O

    ut of date documents cause a lot of confusion

    13

  • 8/7/2019 Chapter8 Coding

    14/16

    Textual DocumentsTextual Documents

    y Readability is an important attribute of

    textual documents.

    y Readability determines understand ability

    hence determines maintainability.

    y A well-known readability measure of text

    documents:

    Gunnings Fog Index.

    14

  • 8/7/2019 Chapter8 Coding

    15/16

    `

    Gunnings Fog IndexGunnings Fog Index

    y F corresponds to the number of years of

    schooling to easily understand the document.

    15

    Percentage ofwords of 3 ormore syllables

    Number of Words

    Number of SentencesF=0.4 +

    A

    document is easy to understand if:all sentences are smalluse only 4 to 5 words eachsmall number of characters used per wordnormally not exceeding five or six characters.

  • 8/7/2019 Chapter8 Coding

    16/16

    Example of Gunnings Fog IndexExample of Gunnings Fog Index

    16

    Rock-a-bye baby, on the treetop. When the wind blows,the cradle will rock. When the bough breaks, the cradlewill fall.And down will come baby, cradle and all.

    Number of words : 31Number of sentences: 4

    Number of 3 syllables or more word : 0

    F = 0.4 *(31/4)+ (0/31*100)= 0.4 * 7.75 = 3.1

    i.e anyone with 3 years of schools can understand the above