SlideShare a Scribd company logo
Code refactoring
Long Nguyen
© Employment Hero, September 2016 ! 1
❝I like my code to be elegant
and efficient.❞
—Bjarne Stroustrup (inventor of C++)
© Employment Hero, September 2016 ! 2
❝Clean code is ... full of crips
abstractions ...❞
—Grady Booch (author of Object Oriented Analysis and Design
with Applications)
© Employment Hero, September 2016 ! 3
❝Clean code was written by
someone who cares.❞
—Michael Feathers (author of Working Effectively with Legacy
Code)
© Employment Hero, September 2016 ! 4
What is refactoring ?
Martin Fowler:
Refactoring is a controlled technique for improving the design of
an existing code base. Its essence is applying a series of small
behavior-preserving transformations, each of which “too small to
be worth doing”.
!
© Employment Hero, September 2016 ! 5
What is refactoring ?
Joshua Kerievsky:
By continuously improving the design of code, we make it easier
and easier to work with. This is in sharp contrast to what typically
happens: little refactoring and a great deal of attention paid to
expediently adding new features. If you get into the hygienic habit
of refactoring continuously, you’ll find that it is easier to extend and
maintain code.
!
© Employment Hero, September 2016 ! 6
What is refactoring ?
Michael Feathers:
One of the clearest preconditions for refactoring is the existence of tests.
Martin Fowler is pretty explicit about that in his Refactoring book, and
everything I’ve experienced with teams backs it up. Want to do make things
better? Sure, but if you don’t have tests to support you, you’re gambling. Can
you do a little refactoring to get tests in place? Yes, I advise it, but when you
start to do significant refactoring, you’d better have tests to back you up. If
you don’t, it’s only a matter of time before your teammates take away your
keyboard.
!
© Employment Hero, September 2016 ! 7
Refactoring in couple of words
☞ A controlled technique
☞ Improving the design
☞ Existing code base
☞ Series of transformations
☞ Habit
☞ Maintain
☞ Tests
☞ Teammates
© Employment Hero, September 2016 ! 8
Programming principles
There're lot of them. This website did a great job of collecting most of them together http://webpro.github.io/programming-principles
Please go and read them all, then you will have a good sense about good code. !
I will share some of uncommon principles which not that popular but I think they're great. Which can be a great guidance:
☞ Code symmetry
☞ Rate of change
☞ Local Consequences
☞ Minimize Repetition
☞ Logic and Data Together
☞ Declarative Expression
© Employment Hero, September 2016 ! 9
Code symmetry
Identifying and clearly expressing symmetry makes code easier to
read. Once readers understand one half of the symmetry, they can
quickly understand the other half.
Example:
void process() {
input();
count++;
output();
}
© Employment Hero, September 2016 ! 10
Symmetry in code is where the same idea is expressed the same
way everywhere it appears in the code.
void process() {
input();
incrementCount();
output();
}
© Employment Hero, September 2016 ! 11
Why all that ?
costtotal = costdevelop + costmaintain
costmaintain = costunderstand + costchange + costtest + costdeploy
© Employment Hero, September 2016 ! 12
Demo
! " # $
© Employment Hero, September 2016 ! 13
References
☞ Implementation Patterns https://www.amazon.com/
Implementation-Patterns-Kent-Beck/dp/0321413091
☞ Working Effectively with Legacy Code https://
www.amazon.com/Working-Effectively-Legacy-Michael-
Feathers/dp/0131177052
☞ Practical Object-Oriented Design in Ruby https://
www.amazon.com/Practical-Object-Oriented-Design-Ruby-
Addison-Wesley/dp/0321721330
© Employment Hero, September 2016 ! 14

More Related Content

PDF
Why software projects fail in 2021?
PDF
Tdd2018 state of the software quality in Germany
PPTX
Bdd and Behat
PDF
Boquet manager
PDF
Job manager 2020 in Angular
PPTX
Type script
PDF
Henning Muszynski - The ABC of Coded Style Guides
PDF
“Startup - it’s not just an IT project” - a random sampling of problems we’ve...
Why software projects fail in 2021?
Tdd2018 state of the software quality in Germany
Bdd and Behat
Boquet manager
Job manager 2020 in Angular
Type script
Henning Muszynski - The ABC of Coded Style Guides
“Startup - it’s not just an IT project” - a random sampling of problems we’ve...

What's hot (20)

PDF
Migrating a large codebase to Node & React
PDF
Front-end Testing (manual, automated, you name it) - Erich Jagomägis - Develo...
PDF
The perfect PR
PDF
VISUG: Visual studio for web developers
ODP
Test Automation Framework using Cucumber BDD overview (part 1)
PPTX
GWAB Lyon - Legacy code atelier
PDF
Building cross platform applications using Windows Azure Mobile Services
PDF
MaxGrosshandlerResume
PDF
GlennBasgaard
PPTX
HotelQuickly Product & Engineering
PPSX
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
PDF
8 tips for mastering node.js
PDF
Parallel development of Web Apps | Codesushi - Gliwice 2017
PDF
Kevin Nelms Baxter Resume
PDF
What is the best programming language for your web product?
PDF
WordPress Jump Start
PDF
Testing stage. being ahead business with cucumber
PPTX
Automated testing for real
PDF
Intro javascript build a scraper (3:22)
Migrating a large codebase to Node & React
Front-end Testing (manual, automated, you name it) - Erich Jagomägis - Develo...
The perfect PR
VISUG: Visual studio for web developers
Test Automation Framework using Cucumber BDD overview (part 1)
GWAB Lyon - Legacy code atelier
Building cross platform applications using Windows Azure Mobile Services
MaxGrosshandlerResume
GlennBasgaard
HotelQuickly Product & Engineering
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
8 tips for mastering node.js
Parallel development of Web Apps | Codesushi - Gliwice 2017
Kevin Nelms Baxter Resume
What is the best programming language for your web product?
WordPress Jump Start
Testing stage. being ahead business with cucumber
Automated testing for real
Intro javascript build a scraper (3:22)
Ad

Similar to Code refactoring (20)

PDF
WordCamp Nashville: Clean Code for WordPress
PPTX
Bringing Open-Source Practices to Your Day Job
PDF
Put to the Test
PDF
CODE REVIEW AND COOPERATIVE PAIR PROGRAMMING BEST PRACTICE
PPT
Agile Methodologies And Extreme Programming - Svetlin Nakov
PDF
Importance of Documentation for programmers
PPT
Agile Methodologies And Extreme Programming
PDF
Best Practices For Writing Super Readable Code
PDF
Software Development Standard Operating Procedure
PDF
WordCamp US: Clean Code
PDF
Structuring the code
PPTX
BelTech 2017 - Building Quality in the Browser
PDF
9 Tips to write efficient and scalable code.pdf
PDF
Software Defect Prevention via Continuous Inspection
PDF
Best practices for structuring Machine Learning code
PDF
Quick Intro to Clean Coding
PPTX
Principles that Guide Practice
PDF
Friday final test
PDF
It is a sunny day
PDF
Introducing Agile Methodologies
WordCamp Nashville: Clean Code for WordPress
Bringing Open-Source Practices to Your Day Job
Put to the Test
CODE REVIEW AND COOPERATIVE PAIR PROGRAMMING BEST PRACTICE
Agile Methodologies And Extreme Programming - Svetlin Nakov
Importance of Documentation for programmers
Agile Methodologies And Extreme Programming
Best Practices For Writing Super Readable Code
Software Development Standard Operating Procedure
WordCamp US: Clean Code
Structuring the code
BelTech 2017 - Building Quality in the Browser
9 Tips to write efficient and scalable code.pdf
Software Defect Prevention via Continuous Inspection
Best practices for structuring Machine Learning code
Quick Intro to Clean Coding
Principles that Guide Practice
Friday final test
It is a sunny day
Introducing Agile Methodologies
Ad

Recently uploaded (20)

PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Online Work Permit System for Fast Permit Processing
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Transform Your Business with a Software ERP System
PDF
System and Network Administraation Chapter 3
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
System and Network Administration Chapter 2
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
history of c programming in notes for students .pptx
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
How Creative Agencies Leverage Project Management Software.pdf
Operating system designcfffgfgggggggvggggggggg
Upgrade and Innovation Strategies for SAP ERP Customers
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Online Work Permit System for Fast Permit Processing
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Design an Analysis of Algorithms II-SECS-1021-03
Transform Your Business with a Software ERP System
System and Network Administraation Chapter 3
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Which alternative to Crystal Reports is best for small or large businesses.pdf
System and Network Administration Chapter 2
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
history of c programming in notes for students .pptx
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
How to Choose the Right IT Partner for Your Business in Malaysia
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
ManageIQ - Sprint 268 Review - Slide Deck
CHAPTER 2 - PM Management and IT Context
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf

Code refactoring

  • 1. Code refactoring Long Nguyen © Employment Hero, September 2016 ! 1
  • 2. ❝I like my code to be elegant and efficient.❞ —Bjarne Stroustrup (inventor of C++) © Employment Hero, September 2016 ! 2
  • 3. ❝Clean code is ... full of crips abstractions ...❞ —Grady Booch (author of Object Oriented Analysis and Design with Applications) © Employment Hero, September 2016 ! 3
  • 4. ❝Clean code was written by someone who cares.❞ —Michael Feathers (author of Working Effectively with Legacy Code) © Employment Hero, September 2016 ! 4
  • 5. What is refactoring ? Martin Fowler: Refactoring is a controlled technique for improving the design of an existing code base. Its essence is applying a series of small behavior-preserving transformations, each of which “too small to be worth doing”. ! © Employment Hero, September 2016 ! 5
  • 6. What is refactoring ? Joshua Kerievsky: By continuously improving the design of code, we make it easier and easier to work with. This is in sharp contrast to what typically happens: little refactoring and a great deal of attention paid to expediently adding new features. If you get into the hygienic habit of refactoring continuously, you’ll find that it is easier to extend and maintain code. ! © Employment Hero, September 2016 ! 6
  • 7. What is refactoring ? Michael Feathers: One of the clearest preconditions for refactoring is the existence of tests. Martin Fowler is pretty explicit about that in his Refactoring book, and everything I’ve experienced with teams backs it up. Want to do make things better? Sure, but if you don’t have tests to support you, you’re gambling. Can you do a little refactoring to get tests in place? Yes, I advise it, but when you start to do significant refactoring, you’d better have tests to back you up. If you don’t, it’s only a matter of time before your teammates take away your keyboard. ! © Employment Hero, September 2016 ! 7
  • 8. Refactoring in couple of words ☞ A controlled technique ☞ Improving the design ☞ Existing code base ☞ Series of transformations ☞ Habit ☞ Maintain ☞ Tests ☞ Teammates © Employment Hero, September 2016 ! 8
  • 9. Programming principles There're lot of them. This website did a great job of collecting most of them together http://webpro.github.io/programming-principles Please go and read them all, then you will have a good sense about good code. ! I will share some of uncommon principles which not that popular but I think they're great. Which can be a great guidance: ☞ Code symmetry ☞ Rate of change ☞ Local Consequences ☞ Minimize Repetition ☞ Logic and Data Together ☞ Declarative Expression © Employment Hero, September 2016 ! 9
  • 10. Code symmetry Identifying and clearly expressing symmetry makes code easier to read. Once readers understand one half of the symmetry, they can quickly understand the other half. Example: void process() { input(); count++; output(); } © Employment Hero, September 2016 ! 10
  • 11. Symmetry in code is where the same idea is expressed the same way everywhere it appears in the code. void process() { input(); incrementCount(); output(); } © Employment Hero, September 2016 ! 11
  • 12. Why all that ? costtotal = costdevelop + costmaintain costmaintain = costunderstand + costchange + costtest + costdeploy © Employment Hero, September 2016 ! 12
  • 13. Demo ! " # $ © Employment Hero, September 2016 ! 13
  • 14. References ☞ Implementation Patterns https://www.amazon.com/ Implementation-Patterns-Kent-Beck/dp/0321413091 ☞ Working Effectively with Legacy Code https:// www.amazon.com/Working-Effectively-Legacy-Michael- Feathers/dp/0131177052 ☞ Practical Object-Oriented Design in Ruby https:// www.amazon.com/Practical-Object-Oriented-Design-Ruby- Addison-Wesley/dp/0321721330 © Employment Hero, September 2016 ! 14