0% found this document useful (0 votes)
10 views26 pages

Unit 4

The coding phase involves techniques like single entry single exit constructs, data encapsulation, GOTO statements, and recursion. Single entry single exit constructs allow for sequencing, selection, and iteration. Data encapsulation packages data structures and access routines together. GOTO statements provide conditional control transfer but should be reserved for uncommon situations. Recursion uses function calls to solve problems recursively. Good coding practices include using standard constructs, comments, indentation and avoiding NULL statements and deep nesting. Verification checks if a product is built correctly while validation checks if the right product is built.

Uploaded by

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

Unit 4

The coding phase involves techniques like single entry single exit constructs, data encapsulation, GOTO statements, and recursion. Single entry single exit constructs allow for sequencing, selection, and iteration. Data encapsulation packages data structures and access routines together. GOTO statements provide conditional control transfer but should be reserved for uncommon situations. Recursion uses function calls to solve problems recursively. Good coding practices include using standard constructs, comments, indentation and avoiding NULL statements and deep nesting. Verification checks if a product is built correctly while validation checks if the right product is built.

Uploaded by

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

Unit - 4

CODING PHASE
Coding Techniques

• It includes –
1) Single Entry, Single Exit constructs,
2) Data Encapsulation,
3) GOTO statements,
4) Recursion
Single Entry, Single Exit constructs
• All the statements in these types of constructs
can only be represented in three basic forms –
a) Sequencing, b) Selection, c) Iteration.
• This construct permits nesting of constructs within one
another in any desired fashion. Each ‘Sn’ statement
might be an assignment statement, a procedure call, a
conditional statement or a looping statement. The most
important aspect of this type of construct is the
linearity of control flow.
• These constructs sometimes show a disadvantage of
inefficient memory space utilization and more
execution time, due to the use of auxiliary variables,
repeated segments of code and excessive subprogram
calls.
Data Encapsulation :-

• It involves packaging of a data structure and its access


routines in a single module. The data structure is
manipulated by the access routines only and other
routines use the data structure by calling the
appropriate access routines.
• A data structure is defined by the operations that can be
performed on it.
• Routines that use the structure need not know the
details of data representation or data manipulation.
Hence the encapsulated data structures provide abstract
objects
GOTO statement :-

– It provides conditional transfer of control and


thus allows violation of Single Entry, Single Exit
procedure of structured programming.
– This statement should be reserved for unusual or
uncommon situations where the natural structure
of an algorithm is broken.
Recursion :-

– A recursive subprogram is one that calls itself, either


directly or indirectly.
– It’s a powerful and elegant programming technique.
When properly used recursive subprograms are easy
to understand and efficient.
– They can be used for implementing recursive
algorithms very easily.
– The distinguishing property of recursive programs is
that they use the system stack to hold the values of
local variables, parameters and return points during
recursive calls.
Suggestions on Coding Style

• The goal of good coding style is to provide


easily understood, straightforward and elegant
code. Following are some Do’s and don’t’s that
can be followed during coding.
DO’s
1) Using standard control constructs: - While coding the
major part is covered by using statement sequences,
selection among alternatives and a mechanism for
iteration. So for all these procedures there are some
standard constructs provided in the programming
language itself hence it’s advised to use them rather
creating a custom made method. This will make the
coding more uniform, easier to read, easier to
understand.
2) Use of GOTO in a controlled manner: - The GOTO
statements should only be used for forward transfer of
control only within the local region of the code. Using
GO TO to achieve backward transfer of control or to
perform a forward jump to a remote region of a
program should be avoided.
3) Apply user defined data types to represent entities in the
problem area: - Use of distinct data types makes it possible
for humans and computer system to distinguish between
entities from the problem domain. User defined data type
that segment the problem domain in a logical manner can
greatly improve the clarity and readability of a source
program. Under strong type checking rules, user defined
data type also provide increased data security.
4) Use of information hiding: - If a software system is designed
using information hiding, each module makes visible only
those features that are required by other modules. All other
aspects of the modules are hidden from external view.
Hiding data structures behind access functions is the
approach taken in data encapsulation, where the data
structure and its access routines are encapsulated in a single
module.
5) Standard documentation prologues for each subprogram: - A
documentation prologues contains information about a
subprogram or compilation unit that is not obvious from
reading the source text of the subprogram or compilation unit.
6) Carefully examine routines having less than 5 or more than 25
statements: - A subprogram that has less than 5 statements is
usually too small to provide a well defined function, it is
usually preferable to insert five or less statements in line as
needed rather than creating a sub program and calling it. It has
been suggested that 30 executable statements is the upper
limit to constitute a subprogram. A routine having less than 5
or more than 25 executable statements should be closely
examined for in line placement in the calling routines ( less
than 5 statements) , and identification of well defined sub-
functions that can be placed in separate routines and called as
needed ( more than 25 statements) .
7) Use indentation. Parenthesis, blank spaces, and
blank line to enhance readability: - Inserting blank
lines and borders around comment statements
enhances the readability of a source program. While
formatting a source text standard conventions should
be followed by all programmers.
DON’T’s

1) Don’t use codes that are inefficient: - During


coding process always keep in mind the
purpose of the code. Using shortcut ways to
accomplish a code segment is not always
efficient in terms of speed and memory
utilization. For ex. using more multiplication
and division activities reduces the speed of
execution.
2) Avoid NULL statements: - A NULL statement is when we don’t
provide any executable inside a loop or in any part of if –then-else
statements. The NULL statements increase un-necessary codes and
poor readability, hence should be avoided as far as possible. Ex.
If(condition) for(int i=0 ; i<10 ; i++)
{ {No statements}
No statements
}
else
{
Statements;
}
3) Avoid using if statements inside the ‘If’ statements :- The nesting of ‘If’
statements in such a way that in the true part of the outer ‘If’ has another ‘If’
just as the first statement and so on should be avoided as it creates a
confusion while reading the code and documentation also becomes poor.

Ex.
if(condition)
if(condition)
if(condition)
{
statements;
}
else
{
statements;
}………
4) Don’t nest too deep :- Nesting of looping and
conditional statements should be avoided and
if at all necessary the depth of nesting should
not be more than 3 or 4 levels
5) Avoid sub optimization: - Sub optimization is the process
where time is invested on improving and refining that part
of code which is a very small part of entire system. Sub
optimization should be avoided because of the following
reasons :-
– Firstly, it’s usually not possible to determine that which part of
the code will occupy the majority of the execution time until
various execution characteristics of the complete program if fully
studied.

- Secondly, unless one has in depth knowledge of the


entire system i.e. language translator, operating system and
hardware, it would be very difficult and inaccurate to
determine that how various exception conditions will be
handled and the memory managed by the system
6) Avoid creating routines that require more
than 5 formal parameters: - From various
studies it had been concluded that a routine
having more than 5 formal parameters
becomes very complex and are a result of
inadequate decomposition of a software
system. Fewer parameters and global
variables improve clarity and simplicity of
subprograms
Source Code Metrics

• The Source Code Metrics are used to measure


the complexity of the source code.
Halstead’s effort equation:-
Estimation of Program Length

N = n1 * log2 n1 + n2 * log2 n2

Estimation for Program Defined

V = (N1 + N2) * log2 (n1 + n2)

Level of language abstraction

L = (2 * n2) / (n1 * N2)

Program Effort
E=V/L
Where
N1 – Total number of operators in a program.
N2 – Total number of operands used in the program.
n1 – Number of unique operators in the program.
n2 – Number of unique operands.
Verification and Validation

• Verification & Validation (V & V) are the activities


that encapsulate all kinds of testing. Verification
is the set of activities that are carried out to
ensure that the software implements a specific
function correctly. Validation is the set of
activities that are carried out to ensure that the
software product that is built is in accordance
with the requirements stated by the customer.
• In simple words:-
• Verification: - “Are we building the product
right?” To check whether all the functionalities
are working as per Goals set for each
functionality.
• Validation: - “Are we building the right
product?” To check whether the customer’s
requirements are getting fulfilled by the
product.
• The goals of verification and validation
activities are to asses and improve the quality
of the work products generated during
development and modification of software.
The quality attributes include – a) Correctness,
b) Completeness, c) Consistency, d) Reliability,
e) Usefulness, f) Conformance to standards
and g) overall cost effectiveness.
Verification:
• It’s the process of determining whether the product
is built in a right manner or not. There are two
categories of verification: - a) Life-cycle verification
and b) Formal verification.
– Life-Cycle verification: - It’s the process of determining the
degree to which the work products of a given phase of the
development cycle fulfill the specifications established
during prior phases.
– Formal verification: - It’s a rigorous mathematical
demonstration that whether the source code conforms to
the specification.
Validation:
• It’s the process of evaluation of the software at the end of
the software development process to determine compliance
with the requirements. In other words it’s the process of
determining whether the correct product is built or not.

• Verification and validation involve the assessment of work


products to determine conformance to the specifications.
Specifications include – a) Requirements specification, b)
The design documentation, c) Various stylistic guidelines, d)
Implementation language standards, d) Project standards, e)
Organizational standards, and f) User expectations.

You might also like