SlideShare a Scribd company logo
Code Smell
Re-define refactoring at NAL (& code review)
Lan@NAL 201612
Once upon a time
We have “Code Review” on
own SDP (Software
Development Process), we
always said “do refactoring",
but ...
Once upon a time
We did not know own code
have bad smells, until ...
NOT BAD
Code Smell
Martin Fowler
https://martinfowler.com/bliki/CodeSmell.html
"A code smell is a surface indication
that usually corresponds to deeper
problem in the system."
In computer programming,
code smell is any symptom
in the source code of
program that possibly
indicates a deeper problem.
Code smells are usually not
bugs, they are not
technically incorrect and do
not currently prevent the
program from functioning.
Instead, they indicate
weaknesses in design
that may be slowing down
development or increasing
the risk of bugs or failures in
the future.
"A code smell is a hint that
something has gone wrong
somewhere in your code. Use the
smell to track down the problem."
Kent Beck
http://wiki.c2.com/?CodeSmell
Code Smells = Warning Signs
Code Smell ≠ A problem
Code Smell
“Bad code smells are symptons of poor design or
implementation choices”
[Martin Fowler]
● Pragmatic: code smells should be considered on a case by case basis
● Purist: all code smells should be avoided, no exceptions
Code Smell (taxonomy)
Smells Between Classes
Smells Within Classes
Object-orientation Abusers
Bloaters
Dispensables
Change Preventers
Couplers
Others
Encapsulation
Abstraction
Modularity
Hierarchy
Code Smell
Bad Smells:
● Bloaters
● Object-orientation Abusers
● Change Preventers
● Dispensables
● Couplers
Code Smell
Bloaters
Bloater smells represents something that has grown so large that it cannot be
effectively handled.
Long Method: A method contains too many lines of code. Generally, any
method longer than ten lines should make you start asking questions.
Large Class: A class contains many fields/methods/lines of code.
Long Parameter List: More than three or four parameters for a method.
Data Clumps: Sometimes different parts of the code contain identical groups
of variables (such as parameters for connecting to a database).
Primitive Obsession:
Use of primitives instead of small objects for simple tasks (such as
Code Smell
Object-orientation Abusers
All these smells are incomplete or incorrect application of object-
oriented programming principles.
Switch Statements: have a complex switch operator or
sequence of if statements.
Temporary Field: Temporary fields get their values (and thus
are needed by objects) only under certain circumstances.
Outside of these circumstances, they are empty.
Refused Bequest: If a subclass uses only some of the
methods and properties inherited from its parents, the
hierarchy is off-kilter. The unneeded methods may simply
go unused or be redefined and give off exceptions.
Alternative Classes with Different Interfaces: Two classes
perform identical functions but have different method
Code Smell
Change Preventers
These smells mean that if you need to change something in one place in your code,
you have to make many changes in other places too. Program development
becomes much more complicated and expensive as a result.
Divergent Change: You find yourself having to change many unrelated methods
when you make changes to a class. For example, when adding a new
product type you have to change the methods for finding, displaying, and
ordering products.
Shotgun Surgery: Making any modifications requires that you make many small
changes to many different classes.
Parallel Inheritance Hierarchies: Whenever you create a subclass for a class,
you find yourself needing to create a subclass for another class.
Code Smell
Dispensables
A dispensable is something pointless and unneeded whose absence
would make the code cleaner, more efficient and easier to understand.
Comments: A method is filled with explanatory comments.
Duplicate Code: Two code fragments look almost identical.
Lazy Class: Understanding and maintaining classes always costs time and money. So if a class
doesn't do enough to earn your attention, it should be deleted.
Data Class: A data class refers to a class that contains only fields and crude methods for accessing
them (getters and setters). These are simply containers for data used by other classes. These
classes do not contain any additional functionality and cannot independently operate on the
data that they own.
Dead Code: A variable, parameter, field, method or class is no longer used (usually because it is
obsolete).
Speculative Generality: There is an unused class, method, field or parameter.
Code Smell
Couplers
All the smells in this group contribute to excessive coupling between
classes or show what happens if coupling is replaced by excessive
delegation.
Feature Envy: A method accesses the data of another object more
than its own data.
Inappropriate Intimacy: One class uses the internal fields and
methods of another class.
Message Chains: In code you see a series of calls resembling $a->b()-
>c()->d()
Middle Man: If a class performs only one action, delegating work to
another class, why does it exist at all?
Code Smell
Others
Incomplete Library Class: Sooner or later, libraries stop meeting user
needs. The only solution to the problem – changing the library – is often
impossible since the library is read-only.
SO WHAT?!
Refactoring
In real world, WORKING WITH
CODE ...
20% Write new code
80% Modify existing code
Refactoring
● Unreadable Code …
● Duplicated Code …
● Complex Code …
…
Bad Smell Code is
HARD to MODIFY
Refactoring
Refactoring is ...
● Easier to Understand
● Cheaper to Modify
“Refactoring is the process of changing a software system in
such a way that it does not alter the external behavior of the
code yet improves its internal structure.”
Refactoring
Code Smells
Software Quality
Code Quality
READ
High Quality Code = easy to UNDERSTAND
CHANGE
In the Long Run, High Quality Code Costs less
Refactoring process ~ create Quality Code
Refactoring
Request Review
Review Comment
Refactoring
Repeat
Commit Code
Code Review
● Choose worst bad smell
● Select a refactoring
● Apply the refactoring
● Run all tests
Refactoring
Refactoring
“With refactoring you can take a bad design, chaos even, and rework it into well-designed code. Each step
is simple, even simplistic. You move a field from one class to another, pull some code out of a method to
make into its own method, and push some code up or down a hierarchy. Yet the cumulative effect of these
small changes can radically improve the design. It is the exact reverse of the normal notion of software
decay.”
So…
HOWto do refactoring in a
controlled and efficient manner?!
More reading/explore
● Refactoring: Improving the Design of Existing Code
(by Martin Fowler, Kent Beck, John Brant, William
Opdyke, Don Roberts
● Refactoring Workbook (By William C. Wake)
● http://www.slideshare.net/mariosangiorgio/clean-
code-and-code-smells
● http://mikamantyla.eu/BadCodeSmellsTaxonomy.ht
ml

More Related Content

What's hot

Clean code
Clean codeClean code
Clean code
ifnu bima
 
Bad Code Smells
Bad Code SmellsBad Code Smells
Bad Code Smells
kim.mens
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
CodeOps Technologies LLP
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
kim.mens
 
Clean code
Clean codeClean code
Clean code
Arturo Herrero
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
Mario Sangiorgio
 
Refactoring
RefactoringRefactoring
Refactoring
Ricardo Terra
 
Clean Code
Clean CodeClean Code
Clean Code
swaraj Patil
 
Clean code
Clean codeClean code
Clean code
Knoldus Inc.
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
saber tabatabaee
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
John Ferguson Smart Limited
 
Tech talks#6: Code Refactoring
Tech talks#6: Code RefactoringTech talks#6: Code Refactoring
Tech talks#6: Code Refactoring
Nguyễn Việt Khoa
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101
Adam Culp
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable Design
Victor Rentea
 
Code Refactoring
Code RefactoringCode Refactoring
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
Victor Rentea
 
Writing clean code
Writing clean codeWriting clean code
Writing clean code
Angel Garcia Olloqui
 
Coding standard
Coding standardCoding standard
Coding standard
FAROOK Samath
 
Clean Code
Clean CodeClean Code
Clean Code
Victor Rentea
 
Clean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software CraftsmanshipClean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software Craftsmanship
Ivan Paulovich
 

What's hot (20)

Clean code
Clean codeClean code
Clean code
 
Bad Code Smells
Bad Code SmellsBad Code Smells
Bad Code Smells
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Clean code
Clean codeClean code
Clean code
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Refactoring
RefactoringRefactoring
Refactoring
 
Clean Code
Clean CodeClean Code
Clean Code
 
Clean code
Clean codeClean code
Clean code
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 
Tech talks#6: Code Refactoring
Tech talks#6: Code RefactoringTech talks#6: Code Refactoring
Tech talks#6: Code Refactoring
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable Design
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
 
Writing clean code
Writing clean codeWriting clean code
Writing clean code
 
Coding standard
Coding standardCoding standard
Coding standard
 
Clean Code
Clean CodeClean Code
Clean Code
 
Clean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software CraftsmanshipClean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software Craftsmanship
 

Viewers also liked

Refactoring-ch7 moving feature btw objects
Refactoring-ch7 moving feature btw objectsRefactoring-ch7 moving feature btw objects
Refactoring-ch7 moving feature btw objects
fungfung Chen
 
Code Smells
Code SmellsCode Smells
Code Smells
Amandeep Batra
 
Developing design sense of code smells
Developing design sense of code smellsDeveloping design sense of code smells
Developing design sense of code smells
Llewellyn Falco
 
Code Smells and How to avoid it
Code Smells and How to avoid itCode Smells and How to avoid it
Code Smells and How to avoid it
Syed Shah
 
Revisiting the Relationship Between Code Smells and Refactoring
Revisiting the Relationship Between Code Smells and RefactoringRevisiting the Relationship Between Code Smells and Refactoring
Revisiting the Relationship Between Code Smells and Refactoring
Norihiro Yoshida
 
Code smells
Code smellsCode smells
Bad Smell In Codes 1
Bad Smell In Codes 1Bad Smell In Codes 1
Bad Smell In Codes 1
A Walk in the World
 

Viewers also liked (7)

Refactoring-ch7 moving feature btw objects
Refactoring-ch7 moving feature btw objectsRefactoring-ch7 moving feature btw objects
Refactoring-ch7 moving feature btw objects
 
Code Smells
Code SmellsCode Smells
Code Smells
 
Developing design sense of code smells
Developing design sense of code smellsDeveloping design sense of code smells
Developing design sense of code smells
 
Code Smells and How to avoid it
Code Smells and How to avoid itCode Smells and How to avoid it
Code Smells and How to avoid it
 
Revisiting the Relationship Between Code Smells and Refactoring
Revisiting the Relationship Between Code Smells and RefactoringRevisiting the Relationship Between Code Smells and Refactoring
Revisiting the Relationship Between Code Smells and Refactoring
 
Code smells
Code smellsCode smells
Code smells
 
Bad Smell In Codes 1
Bad Smell In Codes 1Bad Smell In Codes 1
Bad Smell In Codes 1
 

Similar to Code smell overview

Refactoring
RefactoringRefactoring
Code Smell and Refactoring
Code Smell and RefactoringCode Smell and Refactoring
Code Smell and Refactoring
kimsrung lov
 
Refactoring
RefactoringRefactoring
Refactoring
Arman Sheikh
 
A Study on Code Smell Detection with Refactoring Tools in Object Oriented Lan...
A Study on Code Smell Detection with Refactoring Tools in Object Oriented Lan...A Study on Code Smell Detection with Refactoring Tools in Object Oriented Lan...
A Study on Code Smell Detection with Refactoring Tools in Object Oriented Lan...
ijcnes
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Edition
jexp
 
Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - Refactoring
Diaa Al-Salehi
 
Code quality
Code quality Code quality
Code quality
Sunil Prasad
 
Code smell & refactoring
Code smell & refactoringCode smell & refactoring
Code smell & refactoring
Mamata Gelanee
 
Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016
Søren Lund
 
Code Review
Code ReviewCode Review
Code Review
Ravi Raj
 
Refactoring 2 The Max
Refactoring 2 The MaxRefactoring 2 The Max
Refactoring 2 The Max
Alfredo Morresi
 
Agile korea 2013 유석문
Agile korea 2013 유석문Agile korea 2013 유석문
Agile korea 2013 유석문
Sangcheol Hwang
 
YAGNI Principle and Clean Code
YAGNI Principle and Clean CodeYAGNI Principle and Clean Code
YAGNI Principle and Clean Code
Luan Reffatti
 
Code Smells Part 1: Basic Smells
Code Smells Part 1:  Basic SmellsCode Smells Part 1:  Basic Smells
Code Smells Part 1: Basic Smells
Nancy Henson
 
Reduce Reuse Refactor
Reduce Reuse RefactorReduce Reuse Refactor
Reduce Reuse Refactor
Alena Holligan
 
Documenting code yapceu2016
Documenting code yapceu2016Documenting code yapceu2016
Documenting code yapceu2016
Søren Lund
 
Code smells and Other Malodorous Software Odors
Code smells and Other Malodorous Software OdorsCode smells and Other Malodorous Software Odors
Code smells and Other Malodorous Software Odors
Clint Edmonson
 
Code review
Code reviewCode review
Code review
Abhishek Sur
 
Revisiting Refactoring
Revisiting RefactoringRevisiting Refactoring
Revisiting Refactoring
Nick Harrison
 
Revisiting refactoring
Revisiting refactoringRevisiting refactoring
Revisiting refactoring
Nick Harrison
 

Similar to Code smell overview (20)

Refactoring
RefactoringRefactoring
Refactoring
 
Code Smell and Refactoring
Code Smell and RefactoringCode Smell and Refactoring
Code Smell and Refactoring
 
Refactoring
RefactoringRefactoring
Refactoring
 
A Study on Code Smell Detection with Refactoring Tools in Object Oriented Lan...
A Study on Code Smell Detection with Refactoring Tools in Object Oriented Lan...A Study on Code Smell Detection with Refactoring Tools in Object Oriented Lan...
A Study on Code Smell Detection with Refactoring Tools in Object Oriented Lan...
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Edition
 
Few minutes To better Code - Refactoring
Few minutes To better Code - RefactoringFew minutes To better Code - Refactoring
Few minutes To better Code - Refactoring
 
Code quality
Code quality Code quality
Code quality
 
Code smell & refactoring
Code smell & refactoringCode smell & refactoring
Code smell & refactoring
 
Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016
 
Code Review
Code ReviewCode Review
Code Review
 
Refactoring 2 The Max
Refactoring 2 The MaxRefactoring 2 The Max
Refactoring 2 The Max
 
Agile korea 2013 유석문
Agile korea 2013 유석문Agile korea 2013 유석문
Agile korea 2013 유석문
 
YAGNI Principle and Clean Code
YAGNI Principle and Clean CodeYAGNI Principle and Clean Code
YAGNI Principle and Clean Code
 
Code Smells Part 1: Basic Smells
Code Smells Part 1:  Basic SmellsCode Smells Part 1:  Basic Smells
Code Smells Part 1: Basic Smells
 
Reduce Reuse Refactor
Reduce Reuse RefactorReduce Reuse Refactor
Reduce Reuse Refactor
 
Documenting code yapceu2016
Documenting code yapceu2016Documenting code yapceu2016
Documenting code yapceu2016
 
Code smells and Other Malodorous Software Odors
Code smells and Other Malodorous Software OdorsCode smells and Other Malodorous Software Odors
Code smells and Other Malodorous Software Odors
 
Code review
Code reviewCode review
Code review
 
Revisiting Refactoring
Revisiting RefactoringRevisiting Refactoring
Revisiting Refactoring
 
Revisiting refactoring
Revisiting refactoringRevisiting refactoring
Revisiting refactoring
 

More from Pham Manh Lan

Chăm sóc Khách Hàng trong tổ chức Agile
Chăm sóc Khách Hàng trong tổ chức AgileChăm sóc Khách Hàng trong tổ chức Agile
Chăm sóc Khách Hàng trong tổ chức Agile
Pham Manh Lan
 
Startup & marketing
Startup & marketingStartup & marketing
Startup & marketing
Pham Manh Lan
 
Customer care zero2one
Customer care  zero2oneCustomer care  zero2one
Customer care zero2one
Pham Manh Lan
 
Agile and what's next
Agile and what's nextAgile and what's next
Agile and what's next
Pham Manh Lan
 
Chất lượng ở NAL
Chất lượng ở NALChất lượng ở NAL
Chất lượng ở NAL
Pham Manh Lan
 
Nal Group - Hành trình Agile
Nal Group - Hành trình AgileNal Group - Hành trình Agile
Nal Group - Hành trình Agile
Pham Manh Lan
 

More from Pham Manh Lan (6)

Chăm sóc Khách Hàng trong tổ chức Agile
Chăm sóc Khách Hàng trong tổ chức AgileChăm sóc Khách Hàng trong tổ chức Agile
Chăm sóc Khách Hàng trong tổ chức Agile
 
Startup & marketing
Startup & marketingStartup & marketing
Startup & marketing
 
Customer care zero2one
Customer care  zero2oneCustomer care  zero2one
Customer care zero2one
 
Agile and what's next
Agile and what's nextAgile and what's next
Agile and what's next
 
Chất lượng ở NAL
Chất lượng ở NALChất lượng ở NAL
Chất lượng ở NAL
 
Nal Group - Hành trình Agile
Nal Group - Hành trình AgileNal Group - Hành trình Agile
Nal Group - Hành trình Agile
 

Recently uploaded

132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
zubairahmad848137
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
NazakatAliKhoso2
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
HODECEDSIET
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 

Recently uploaded (20)

132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEMTIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
TIME DIVISION MULTIPLEXING TECHNIQUE FOR COMMUNICATION SYSTEM
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 

Code smell overview

  • 1. Code Smell Re-define refactoring at NAL (& code review) Lan@NAL 201612
  • 2. Once upon a time We have “Code Review” on own SDP (Software Development Process), we always said “do refactoring", but ...
  • 3. Once upon a time We did not know own code have bad smells, until ...
  • 5. Code Smell Martin Fowler https://martinfowler.com/bliki/CodeSmell.html "A code smell is a surface indication that usually corresponds to deeper problem in the system." In computer programming, code smell is any symptom in the source code of program that possibly indicates a deeper problem. Code smells are usually not bugs, they are not technically incorrect and do not currently prevent the program from functioning. Instead, they indicate weaknesses in design that may be slowing down development or increasing the risk of bugs or failures in the future. "A code smell is a hint that something has gone wrong somewhere in your code. Use the smell to track down the problem." Kent Beck http://wiki.c2.com/?CodeSmell Code Smells = Warning Signs Code Smell ≠ A problem
  • 6. Code Smell “Bad code smells are symptons of poor design or implementation choices” [Martin Fowler] ● Pragmatic: code smells should be considered on a case by case basis ● Purist: all code smells should be avoided, no exceptions
  • 7. Code Smell (taxonomy) Smells Between Classes Smells Within Classes Object-orientation Abusers Bloaters Dispensables Change Preventers Couplers Others Encapsulation Abstraction Modularity Hierarchy
  • 8. Code Smell Bad Smells: ● Bloaters ● Object-orientation Abusers ● Change Preventers ● Dispensables ● Couplers
  • 9. Code Smell Bloaters Bloater smells represents something that has grown so large that it cannot be effectively handled. Long Method: A method contains too many lines of code. Generally, any method longer than ten lines should make you start asking questions. Large Class: A class contains many fields/methods/lines of code. Long Parameter List: More than three or four parameters for a method. Data Clumps: Sometimes different parts of the code contain identical groups of variables (such as parameters for connecting to a database). Primitive Obsession: Use of primitives instead of small objects for simple tasks (such as
  • 10. Code Smell Object-orientation Abusers All these smells are incomplete or incorrect application of object- oriented programming principles. Switch Statements: have a complex switch operator or sequence of if statements. Temporary Field: Temporary fields get their values (and thus are needed by objects) only under certain circumstances. Outside of these circumstances, they are empty. Refused Bequest: If a subclass uses only some of the methods and properties inherited from its parents, the hierarchy is off-kilter. The unneeded methods may simply go unused or be redefined and give off exceptions. Alternative Classes with Different Interfaces: Two classes perform identical functions but have different method
  • 11. Code Smell Change Preventers These smells mean that if you need to change something in one place in your code, you have to make many changes in other places too. Program development becomes much more complicated and expensive as a result. Divergent Change: You find yourself having to change many unrelated methods when you make changes to a class. For example, when adding a new product type you have to change the methods for finding, displaying, and ordering products. Shotgun Surgery: Making any modifications requires that you make many small changes to many different classes. Parallel Inheritance Hierarchies: Whenever you create a subclass for a class, you find yourself needing to create a subclass for another class.
  • 12. Code Smell Dispensables A dispensable is something pointless and unneeded whose absence would make the code cleaner, more efficient and easier to understand. Comments: A method is filled with explanatory comments. Duplicate Code: Two code fragments look almost identical. Lazy Class: Understanding and maintaining classes always costs time and money. So if a class doesn't do enough to earn your attention, it should be deleted. Data Class: A data class refers to a class that contains only fields and crude methods for accessing them (getters and setters). These are simply containers for data used by other classes. These classes do not contain any additional functionality and cannot independently operate on the data that they own. Dead Code: A variable, parameter, field, method or class is no longer used (usually because it is obsolete). Speculative Generality: There is an unused class, method, field or parameter.
  • 13. Code Smell Couplers All the smells in this group contribute to excessive coupling between classes or show what happens if coupling is replaced by excessive delegation. Feature Envy: A method accesses the data of another object more than its own data. Inappropriate Intimacy: One class uses the internal fields and methods of another class. Message Chains: In code you see a series of calls resembling $a->b()- >c()->d() Middle Man: If a class performs only one action, delegating work to another class, why does it exist at all?
  • 14. Code Smell Others Incomplete Library Class: Sooner or later, libraries stop meeting user needs. The only solution to the problem – changing the library – is often impossible since the library is read-only.
  • 16. Refactoring In real world, WORKING WITH CODE ... 20% Write new code 80% Modify existing code
  • 17. Refactoring ● Unreadable Code … ● Duplicated Code … ● Complex Code … … Bad Smell Code is HARD to MODIFY
  • 18. Refactoring Refactoring is ... ● Easier to Understand ● Cheaper to Modify “Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure.”
  • 19. Refactoring Code Smells Software Quality Code Quality READ High Quality Code = easy to UNDERSTAND CHANGE In the Long Run, High Quality Code Costs less Refactoring process ~ create Quality Code
  • 20. Refactoring Request Review Review Comment Refactoring Repeat Commit Code Code Review ● Choose worst bad smell ● Select a refactoring ● Apply the refactoring ● Run all tests
  • 22. Refactoring “With refactoring you can take a bad design, chaos even, and rework it into well-designed code. Each step is simple, even simplistic. You move a field from one class to another, pull some code out of a method to make into its own method, and push some code up or down a hierarchy. Yet the cumulative effect of these small changes can radically improve the design. It is the exact reverse of the normal notion of software decay.” So… HOWto do refactoring in a controlled and efficient manner?!
  • 23. More reading/explore ● Refactoring: Improving the Design of Existing Code (by Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts ● Refactoring Workbook (By William C. Wake) ● http://www.slideshare.net/mariosangiorgio/clean- code-and-code-smells ● http://mikamantyla.eu/BadCodeSmellsTaxonomy.ht ml

Editor's Notes

  1. Nhìn lại hoạt động coding review & refactoring (tái định nghĩa trong NAL)
  2. Chúng ta có Coding Review trong quy trình, có nói về Refactoring ... nhưng có lẽ không hiểu mục đích và cách làm các công việc này giống nhau.
  3. Chúng ta không biết là Code của mình THỐI, cho đến khi khách hàng nói code của chúng ta thối.
  4. Bloaters Bloater smells represents something that has grown so large that it cannot be effectively handled. Bloaters are code, methods and classes that have increased to such gargantuan proportions that they are hard to work with. Usually these smells do not crop up right away, rather they accumulate over time as the program evolves (and especially when nobody makes an effort to eradicate them). Object-Orientation Abusers All these smells are incomplete or incorrect application of object-oriented programming principles. Change Preventers These smells mean that if you need to change something in one place in your code, you have to make many changes in other places too. Program development becomes much more complicated and expensive as a result. Dispensables A dispensable is something pointless and unneeded whose absence would make the code cleaner, more efficient and easier to understand. Couplers All the smells in this group contribute to excessive coupling between classes or show what happens if coupling is replaced by excessive delegation. --------- Abstraction: “An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of objects and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer.” Encapsulation: “Encapsulation is the process of compartmentalizing the elements of an abstraction that constitute its structure and behavior; encapsulation serves to separate the contractual interface of an abstraction and its implementation.” Modularity: “Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules Hierarchy: “Hierarchy is a ranking or ordering of abstractions.”
  5. Incomplete Library Class Sooner or later, libraries stop meeting user needs. The only solution to the problem – changing the library – is often impossible since the library is read-only.