Software Engineering
Techniques
Unit III Software Coding & Metrics
UNIT-II
Software Coding: Programming Principles Programming Guidelines - CodingConventions - Key
Concepts.Software Metrics and Estimation: Introduction - Measurement - Metrics - Lines of
Code -Function Point Count. Software Estimation: Definition - Importance ofAccurate
Estimation - Efforts and Duration - Estimation Process.
User Interface Design
By
Dr.C.Mohanapriya
MSc(CT).,Mphil.,SET.,PhD.,
1
KEY CONCEPTS IN SOFTWARE CODING
• Coding is considered as the most critical part because the real software gets written.
Unless proper focus is maintained for keeping the standard of this stage high,
• The software will break at the later stages, causing huge effort in fixing the defects
called bugs.
• There are few key concepts in software coding which needs to be understood
properly to create an efficient software.
2
KEY CONCEPTS IN SOFTWARE CODING
1. Structured Programming 10.Symbolic Execution
2. Information Hiding 11.Proving Correctness
3. Coding Standards and Guidelines 12.Code Inspections
4. Top-Down and Bottom-Up Coding 13.Programming Productivity
5. Incremental Development of Code 14.Rapid Prototyping
6. Programming Style 15.Intelligent Software Agent
7. Code Sharing 16.Software Reuse
8. Code Review
9. Static Program Analysis
3
Structured Programming
• It is the subset of procedural programming.
• It is also called as modular programming .
• It represents the usage of a logical structure on the program being
written to make it more readable, efficient, reliable, and easily
maintained.
• In a typical structured programming language, the overall program is
divided into logical structure for meaningful implementation.
• Common functions across the structures are taken out and coded in a
separate module (or separate program) itself so that the functions can
be reused and memory usage also minimized.
• Modules are tested separately before fitting into the overall
programming structure.
4
• Unstructured programming (BASIC,FORTRAN) relies upon the
discipline of the software developer to avoid structural problems
• programming languages such as Pascal, COBOL, C, C++, Java, and
dBASE are designed with features that enforce a logical program
structure.
• Object-oriented programming structure (OOPS) is a type of
structured programming that uses structured programming
techniques for program flow and adds more structure for class,
object, and data to the model.
• Structured programming was first suggested by Corrado Bohm and
Guiseppe Jacopini, who demonstrated that any computer program
can be written with just three structures namely
1. decisions (to decide the course of action),
2. sequences (order), and
3. loops (iterative execution).
5
Structured Programming
6
• The most common methodology employed was developed by Dijkstra.
• He suggests avoiding “GO TO” statement.
• In this model, programs are divided into sections and then subsections
• Each subsection has only one entry point and one exit point and in
which control is passed downward through the structure from the top
without unconditional branches to higher levels of the structure.
• There are three types of control namely sequence, selection, and
repetition.
• Sequence refers to the orderly execution of statements one by one.
• Selection refers to the selection of statements based on some
conditions.
• This is usually expressed with keywords such as if..then..else..endif,
switch, or case.
• Repetition refers to the same statement executed repeatedly depending
on a condition such as for loop, while loop, and do loop.
7
Information Hiding
• Users will be exposed to only the required details.
• For example, while we use any software (say Microsoft Word),
we (users) know only how to use that software not how it was
built and its related software.
• Encapsulation uses the principle of information hiding.
• No object can access the other object’s data directly; instead,
data are accessed only by sending the messages to the other
object requesting for the information.
• This means the user need not know what is happening inside
the object but can only use the object by calling the object’s
methods.
8
Information Hiding
9
Information Hiding
• This will provide insulation for the data inside the object from
accidental manipulation by another object or user.
• In a good OO design/code, the object should reveal its data only
through the specified interfaces or methods, and the other objects
can only use this interface or methods to interact with the object.
• The attributes which are only for the internal use of the object and
not to be revealed are completely hidden from other objects.
• In those cases, the attributes are declared as “private”.
10
Information Hiding
• This also protects the object attributes getting changed erroneously
while some other attributes are getting changed.
• For example, in the class Car engine, there are many parts
(attributes) inside it. Everyone applies a common technique in
accessing the engine functionalities no matter how the engine is
made of. The detail and design of the engine are hidden from the
knowledge of the driver.
• Information hiding technique reduces complexity and increases
usability and maintainability.
• Information hiding principle is used to prevent other programmers
or other program to change this program –intentionally or
unintentionally.
11
Coding Standards and Guidelines
• Good developers always follow the coding standards and guidelines
while writing the code. Code written using the standards and
guidelines are easy to review/understand/debug. It is also easy to
maintain and enhance the code if it follows the standards and
guidelines.
• Advantages of coding standards:
• Advantages of coding standards.
1. Reusability (easy to reuse parts of code as it is written in standard
code)
2. Maintainability (easy to identify bugs, easy to add new features)
3. Readability (coding standard increases easy reading)
4. Understand ability (easy to understand – this is not the same as
readability, e.g., repetitive code may be is readable, but not
understandable) 12
Coding Standards and Guidelines
13
Coding Standards and Guidelines
• The sample coding standards and guidelines are as follows:
1. Write comments before writing the code
2. Use meaningful names for varibles and functions. (Try to avoid single
character varible names and function names).
3. Avoid extremely long names
4. Format the code properly using the standards specific to the programming
language
5. Use tools to improve coding standards if possible
6. Prefix “is” for Boolean variable - For Example: is Open+ True
7. Comment should explain “Why” instead of “How” (Why a particular algorithm
was chosen)
8. Comments should be blended into the code
9. Avoid deeply nested code
10. Never use “Go To” Statement
11. Don't duplicate the code 14
Top-Down and Bottom-Up Coding
• Top-down coding: Here the implementation starts with the top of the hierarchy. The top
main module
is written first before writing the bottom submodules.
• Testing top-down coding: Top main module is written first and hence the test cases are
written completely for it. A stub is written in place of bottom submodules.
• Bottom-up coding: It is the reverse of top-down coding, and here the implementation
starts with the bottom submodules. The top main module is written after that until it
reaches the top of the hierarchy.
• Testing bottom-up coding: Bottom submodules are written fi rst, and hence the test
cases are written completely for it. A driver module is written to involve those modules
under testing.
15
Incremental Development of Code
• Project delivery is divided into parts – analyze, design, code, test, and deliver product
(release).
• The delivery of product is also divided into parts. Initially, a part of the product is
released and then, additional developments are made based on feedback. These
developments are linked and the overall solution is finally completed.
• The solution from each part is reviewed and tested. Results from the testing are
assessed, and any required changes are incorporated into the next stage (next part)
of solution development.
• Unified process model (RUP) is an example of incremental model, and there are four
phases associated with it, namely inception, elaboration, construction, and transition.
1. Inception: Requirements and scope identifi ed at high level.
2. Elaboration: Working architecture delivered that fulfi ls the non-functional
requirements
3. Construction: Production ready code is developed incrementally.
4. Transition: Deployment of the code into production happens here. 16
Incremental Development of Code
• The spiral model is also a type of incremental model (refer Figure
8.18).
17
Advantages /Disadvantages of incremental life cycle model:
Advantages of incremental life cycle model:
1. Quick feedback loop from business stakeholders
2. Focus on customer feedback
3. Customer feels the product early.
Disadvantages of incremental life cycle model:
1. Even though the final product is given in pieces, tracking and
monitoring is difficult.
2. Testing needs to be exhaustive in each part.
18
5.Iterative Life cycle Model
• Professor Barry Boehm’s paper describes this model as “Analyze a
little, design a little, test a little, and loop back”.
• Development happens in iterations that encompass the activities
of requirements analysis, design, coding, and testing.
• The early iterations produce a small system, which gradually
expands over a series of iterations to become the overall complete
system. Feedback is implemented from one iteration to the next
iteration.
• During iteration, activities from all Project Management Process
Groups will be performed.
• At the end of each iteration, a set of deliverables will be completed
(refer Figure 8.19).
19
20
5.Iterative Life cycle Model
Advantages of iterative life cycle model:
1. Quick feedback loop from business stakeholders.
2. Focus on customer feedback.
3. Focus on getting the highest priority features first.
4. Ability to validate pieces of deliverables incrementally.
Disadvantages of iterative life cycle model:
1. Getting feedback from customer on time is difficult.
2. Even though deliverables are given in pieces, tracking and monitoring is difficult.
3. Project may not proceed further if customer is not cooperating.
4. The fully developed solution requires the partial developments to be
implemented, and this is often complicated and costly.
21
6.Programming Style
• Set of rules and guidelines followed while writing a computer
program is called as programming style.
• This programming style varies across the programming languages
because the styling used in BASIC is different from C, styling
used in C++ is different from C.
• Following a particular style improves readability of the code and
also helps to avoid errors. Programming styles are based on
organization standards and guidelines.
• But most of the authors (coders) create their own programming
styles. Creating a common coding standard will help formulating a
programming style across the team and the organization.
22
7 Code Sharing
• Code share concept (refer Figure 8.20) is famous in aviation
business arrangement where one flight is shared by different
airline operators.
• Tickets are sold by different operators (marketing carriers), and
the flight will be operated by another operator (operating carrier).
• In software engineering also, third-party codes are being used
(integrated) while writing the code.
• For example, credit card payment gateway is a commonly used
code share. PayPal integration is also another example of code
share.
23
7 Code Sharing
24
7 Code Sharing
• Code share concept (refer Figure 8.20) is famous in aviation
business arrangement where one flight is shared by different
airline operators.
• Tickets are sold by different operators (marketing carriers), and
the flight will be operated by another operator (operating carrier).
• In software engineering also, third-party codes are being used
(integrated) while writing the code.
• For example, credit card payment gateway is a commonly used
code share. PayPal integration is also another example of code
share.
• Bookmytickets.com and meraevents.com are also examples of code share
providers.
25
• As software engineers, we can make use of those code shares which save lot of
26