Unit-6
Unit-6
Unit-6
• Coding is undertaken once design phase is complete & design documents have
been successfully reviewed.
• In the coding phase, every module identified and specified in the design document
is independently coded & unit tested.
• During the coding phase, different modules identified in the design document are
coded according to specifications.
Coding
Most software development organizations formulate their own coding standards that
suit them most & require their engineers to follow these standards rigorously due to
the following reasons:
• The primary goal of the coding phase is to translate the given design into source
code in a given programming language, so that the code is simple easy to test and
easy to understand and modify.
• In a Top down implementation, the implementation starts from the top of the
hierarchy and proceeds to the lower levels.
Top-down Bottom-up
• A top-down approach is essentially breaking • A bottom-up approach is piecing together of
down of a program into small programs (or module (or small program) to give rise to more
modules) in a reverse engineering fashion. complex program.
Structured Programming:
• The static structure is the structure of the text of the program, which is usually just a
linear organization of statements of the program.
• The goal of structured programming is to ensure that the static structure and the
dynamic structures are the same.
Programming Practice
Information Hiding:
• Information hiding can reduce the coupling between modules and make the system
more maintainable.
• Another form of information hiding is to let a module see only those data items
needed by it.
Programming Practice
Programming Style:
• The programming style consists of some standard and guidelines which we will
discuss in the next phase of this presentation.
Programming Practice
Internal Documentation:
• Comments are textual statements that are meant for the program reader and are not
executed.
Coding Standards
Indentation: It is an empty space at the beginning of a line to signal the start of a new
paragraph.
Proper & consistent indentation is important in producing easy to read & maintainable
programs.
Coding Standards
Structured Programming:
• The goal of structured programming is to ensure that the static structure and the
dynamic structures are the same.
Coding Standards
• A good rule for module length is to constrain each module to one function or action
(i.e. each module should only do one “thing”).
• The names of the classes, functions or methods shall have verbs in them. That is the
names shall specify an action,
e.g. “get_name”
“compute_temperature”
Coding Standards
Source Files: The name of the source file or script shall represent its function.
arithmetic.cpp
Variable Names: Variable shall have meaningful names that convey to a casual
observer, the intent of its use. Variable must be declared before they are used.
e.g. variable declaration for summation of two numbers & store it in variable
Use of Braces:
Coding Standards
Compiler Warnings:
• Compiler errors do stop the compilation process, forcing the developer to fix the
problem and recompile.
• General coding guidelines provide the programmer with a set of best practices which
can be used to make programs easier to read and maintain.
• Most of the examples use the C language syntax but the guidelines can be applied
to all languages.
Line Length: It is considered good practice to keep the lengths of source code lines at
or below 80 characters. Lines longer than this may not be displayed properly.
Coding Guidelines
Spacing: The proper use of spaces within a line of code can enhance readability.
Coding Guidelines
Wrapping Lines: When an expression will not fit on a single line, break it.
Coding Guidelines
Variable Declarations: Variable declarations that span multiple lines should always be
preceded by a type.
Coding Guidelines
Program Statements: It should be limited to one per line. Also, nested statements
should be avoided when possible.
Coding Guidelines
Meaningful Error Messages: Use error handing concepts. It handle errors but also
involves making error messages meaningful.
Code Reading: Code reading involves careful reading of the code by the programmer
to detect any discrepancies between the design specifications and the actual
implementation.
Code Inspection or Review: Review process was started with the purpose of detecting
defects in the code.
Code reviews are designed to detect defects that originate during the coding process,
although they can also detect defects in detailed design.
Code Verification
Unit Testing: It is a dynamic method for verification where the program is actually
compiled and executed.
It is one of the most widely used methods & the coding phase is sometime called the
“coding and unit testing phase”.