0% found this document useful (0 votes)
7 views30 pages

Re Engineering slides

The document discusses software reengineering with a focus on code smells, which are indicators of potential issues in code that can hinder maintenance and evolution. It outlines various types of code smells, their causes, and detection techniques, emphasizing the importance of refactoring to improve software quality. The conclusion highlights the need for better detection tools and standard benchmarks in the field of software maintenance.

Uploaded by

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

Re Engineering slides

The document discusses software reengineering with a focus on code smells, which are indicators of potential issues in code that can hinder maintenance and evolution. It outlines various types of code smells, their causes, and detection techniques, emphasizing the importance of refactoring to improve software quality. The conclusion highlights the need for better detection tools and standard benchmarks in the field of software maintenance.

Uploaded by

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

Software Reengineering

By

Dr. Junaid Akram


Assistant Professor, Department of Computer Science COMSATS (Lahore)
Software Maintenance
( Code Smells )
2
J.A COMSATS Uni
3
Smells

4
Concepts and Definitions

Examples of Code smells

Research on code smells

State of the Art

Outline
Code smells detection techniques

Evaluation of technique

Conclusion
Code Smells

Flower et al[4] identified 22 code smells in 1999.

Code Smells are usually implementation problems.

It is claimed that classes that are involved in certain


code smells are liable to be changed more frequently
and have more defects than other classes in the
code[2]

God Class, Data Class, Long method parameters,


Feature envy etc. are code smells
Code smell is any symptom that indicating
something wrong

Code smell is actually a hint that something has


Code Smells gone wrong somewhere in your code which may
cause problems
Definitions
Code Smells are structural characteristics of
software that may indicate a code or design
problem that makes software hard to evolve and
maintain, and may trigger refactoring of code
Why Cod Smells Occur?
Frequent changes and enhancement

Violation of standard design and coding principles

Deadline Pressure

Priority to features over quality

Inexperience of developers

In-appropriate Refactoring operations

Poor human resource planning

Framework constraints etc.


• Successful systems are maintained over
multiple years
• Exceeding size and complexity are problem for
evolution and maintenance
Motivation • System’s Life-Cycle Properties worsen over
time
for Code • Understandability
Smells •

Testability
Extensibility
• Reusability
• Restructuring/Refactoring helps to improve
life-cycle properties
• Code Smells
Summary of Code Smells
Large
Class

A class is trying to do too much. These classes


have too many instance variables or methods.
Large Class

• A large class has monopoly on entire application


• Some methods belong to other classes
Large Class

J.A COMSATS Uni


Long Method

• Long Method is a method that is too long, so it is difficult to


understand, change, or extend
• Still, no hard and fast rules about size.
• Cyclomatic Complexity metrics can be used to detect long methods
from code.
• Detection rule may be:
ümore than or equals to a specified number of Lines of code (excluding
method declaration, comments and parenthesis) or
ümore than or equals to a specified number of Operands and (or) Operators
Data Class

• These are Classes that have fields, getting and setting methods and
nothing else
• Is just acting as a data holder
• Can indicate the design is really procedural
• Detection rules will be as:
üIf the class contains public attributes and no methods the smell is detected;
üIf the class contains only get and set methods the smell is detected
Duplicate Code
• Percentage of duplicate code lines in the systems
• Duplicate methods in subclasses
• Duplicate expressions in same class
• Duplicate expressions in different classes

Example:
sqrt(pow(loc1.getX() - loc2.getX(), 2)+
pow(loc1.getY() - loc2.getY(), 2))

sqrt(square(loc1.getX() - loc2.getX())+
square(loc1.getY() - loc2.getY()))
double square(double d) {
return pow(d, 2);
}

J.A COMSATS Uni


Duplicate Code
>"#A%CCCDEFGHI-KLMGHNCCCC >"gN%CCCDEFGHI-KLMGHNCCCC >"oN%CCCDEFGHI-KLMGHNCCCC
>"##%CCCOP4RSTPUG9:;<<=[SNRS?UR9[]UAES_TUC>"gn%CCCOP4RSTPUG9:;<<E[SNRS?UR9[]4PUASCUAES_TUC >"on%CCCOP4RSTPUG9:;<<=[SNP_S]UAES_TUCwCRNP_Sp
>"#"%CCCa >"go%CCCa >"oo%CCCa
>"#b%CCCCCUAcdSPES_TUCC?_[ef >"NT%CCCCCUAcdSPES_TUCC?_[ef >bTT%CCCCCUAcdSPES_TUCC?_[ef
>"#g%CCCCCUAGhiGCMd_;f >"Nr%CCCCCUAGhiGCMd_;f >bTr%CCCCCUAGhiGCMd_;f
>"#N%CCCCCUA_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ace, layout, and
comments.
Type-2 Code Clone:Code fragments that are identical except for variations in identifier names and
literal values, in addition to differences in whitespace, layout, and comments
Type-3 Code Clone: Code fragments with further modifications such as changes in statements, which
may involve adding or removing statements, but retain similar functionality.
Type-4 Code Clone: Code fragments that are semantically similar but syntactically different. This
means they perform the same functionality but are written in different ways.

19
Types of Clones

J.A COMSATS Uni


Message Chain
• Long list of method calls:
• Can be analyzed by Measuring the couplings of a method
• customer.getAddress().getState()
• window.getBoundingbox().getOrigin().getX()

• Replace with shorter calls:


• customer.getState()
• window.leftBoundary()
Long Parameters List

• A long parameter list exists if


• a method contains more than or equals to a specified number of parameters.
The specific (threshold) value for the number of parameters is given by the user
or ; (PMD uses 10 as specified threshold while for Check Style it is 7)
• if it contains two or more (specified numbers of) parameter of same primitive
data type.

J.A COMSATS Uni


Research on code smells

Very active research area

There are many studies published on detection and refactoring of code


smells

Due to large body of knowledge, there are many published surveys, mapping
studies and systematic review studies on the topic

There is a recent secondary study


Research in
Code Smells

Zakeri-Nasrabadi, Morteza, et al. "A systematic literature review on the code smells datasets and validation
mechanisms." ACM Computing Surveys 55.13s (2023): 1-48.
Zakeri-Nasrabadi,
Morteza, et al. "A
systematic literature
review on the code
smells datasets and
validation
mechanisms." ACM
Computing
Surveys 55.13s (2023):
1-48.
Research in Code Smells
Pereira dos Reis, José, et al. "Code smells detection and visualization: a systematic literature
review." Archives of Computational Methods in Engineering 29.1 (2022): 47-94.

26
J.A COMSATS Uni
Research in Code Smells

Pereira dos Reis, José,


et al. "Code smells
detection and
visualization: a
systematic literature
review." Archives of
Computational Methods
in Engineering 29.1
(2022): 47-94.

27
Programming languages and number of
studies that use them

28
Conclusion
Software Refactoring and Maintenance is heavily based on the detection of Code
Smells.

Detection tools for the detection of different Code Smells from multiple
languages is missing.

There is disparity in results of different tools

Standard benchmarks are highly desired

The impacts of Code Smells is heavily based on accurate detection of all


different code smells.

More focus is required on refactoring techniques and tools

J.A COMSATS Uni


Thanks for your attention!

Any Question?

Email me on : [email protected] 30

You might also like