Professional Documents
Culture Documents
Cha 6
Cha 6
d i ng
C o
Introduction
• The goal of the coding or programming activity is
to implement the design in the best possible
manner.
• Coding affects testing and maintenance
profoundly
• The time spent in coding is a small percentage of
the total software cost, while testing &
maintenance consume major percentage.
• As testing and maintenance costs are high, the aim
Hence, goal should not be to reduce coding cost, but
testing and maintenance cost, i.e. make the job of tester
and maintainer easier
Programming Principles & Guidelines
Coding Standards
Programmers spend more time reading code than
writing code
Readability is enhanced if some coding conventions are
followed by all
Coding standards provide these guidelines for
programmers
Some Java coding conventions are
Naming conventions e.g. Const name, package name,
Type name, method name variable name
Commenting and layout e.g. single line and multiline
comments
Layout guidelines e.g. Indentation guidelines
Coding Process
• Coding starts when specifications for modules from
design is available
• Usually modules are assigned to programmers for
coding
• In top-down development, top level modules are
developed first; in bottom-up lower levels modules are
developed first.
• For coding, developers use different processes; Some
of these are.
• An Incremental Coding Process : most common
• Test Driven Development: relatively new approach
• Pair programming: key technique in extreme
programming (XP) methodology
An Incremental Coding Process
• In this process
• A code is written for the currently assigned module,
and when done, unit testing is performed on it and
the bugs found are fixed
• Then the code is checked in the project repository to
make it available to others in the project.
• Look at the figure on next page
• A better process for coding, that is often followed by
experienced developers – most common one
• Advantage
• with testing being done after every round of coding is
to facilitate debugging—an error found in some
testing can be safely attributed to code that was added
since last successful testing.
Test Driven Development (TDD)
• In TDD, a programmer first writes the test scripts, and then
writes the code to pass the tests.
• The whole process is done incrementally, with tests being
written based on the specifications and code being written to
pass the tests.
• Is a relatively new approach, and is a part of the extreme
programming (XP)
• Ensures that all functionality is there is on test case design,
not coding
• Help ensure that all code is testable (advantages)
• Has possibility that special cases for which test cases are not
possible get left out (Disadvantage)
Pair programming
• Also a coding process that has been proposed as key
practice in XP
• Code is written by pair of programmers rather than
individuals
• The pair together design algorithms, data structures,
strategies, etc.
• One person types the code, the other actively reviews
what is being typed
• Errors are pointed out and together solutions are
formulated
• Roles are reversed periodically
• Advantage
• PP has continuous code review, and reviews are
known to be effective
• likely to result in better decisions being taken about
the data structures, algorithms, interfaces, logic, etc.
• Disadvantage
• It may, however, result in loss of productivity
• Ownership and accountability issues are also there
Verification
• Once a programmer has written the code for a module,
it has to be verified before it is used by others.
• Here we discuss only verification of code written by a
programmer (system verification is discussed in next
chapter-Testing)
• There are many different techniques; Some of these are
• Code Inspections
• Unit Testing
• Static Analysis
• Formal verification
Verification techniques
• Code Inspection:
• Involves reviewing source code with a group who ask
questions analyzing the program logic, analyzing the
code with respect to a checklist of historically
common programming errors, and analyzing its
compliance with coding standards.
• Unit Testing
• A software testing technique that focuses on
exercising the features of individual functions or
modules in isolation.
• Static Analysis
• Analysis of a program carried out without executing
the program.
• There numerous tool supports
• Formal Verification
• Use of various types of logic and mathematical
methods to verify the correctness of code - Used
mostly in very critical situations