SlideShare a Scribd company logo
Code Refactoring
in Javascript
Ilias Bartolini
Agenda
●
Introduction to Refactoring
●
Initial setup exercise
- break -
●
Refactoring examples
●
You own refactoring
journey
Where are my black socks?
Where are my black socks?
I need a 12mm spanner...
I need a 12mm spanner...
Coding activity
Writing code
Reading code
“Any fool can write code that a computer
can understand. Good programmers write
code that humans can understand.”
- Martin Fowler
Refactoring
Refactoring
“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.”
- Martin Fowler
Hello demo exercise
●
Set up in pairs
...and exchange keyboard often!
●
Get the codebase
$ git clone
github.com/iliasbartolini/code_refactoring
$ cd code_refactoring
$ npm install
$ npm test
●
Check the /1_hello/ example
See: https://refactoring.com/catalog/
See: https://refactoring.guru
Some refactoring...
Rename method, variable, class, …
Replace magic numbers
Extract / Inline method or function
Extract / Inline variable
Move method, Extract class
Replace if/switch with polymorphism
Pull up / Push down method, Extract interface
Replace inheritance with delegation
And some smells...
Source: iStock Michał Ludwiczak
Code smells and refactoring
Treatment
●
Extract duplicate part
●
Extract & split
●
Introduce class
●
Move responsibility
●
Split responsibilities
●
Introduce polymorphism, ...
●
Delete, delete, delete
●
Rename / Extract method
Symptom
●
Duplicated code
●
Long function/class
●
Long list of parameters
●
Code “envy”
●
Divergent changes
●
Common if/switch lists
●
Speculative generic code
●
Code comments
//are like a deodorant
Practice!
Check the examples in order
/2_date_parser/
/3_direction/
Tools & Language support
Let’s focus on baby steps!
1) Identify a smell
2) Make a refactoring
3) Run tests!
4) Repeat
●
Write down the list of
smells you see and
refactoring you apply
●
Remember to swap
keyboard ;)
Practice!
Check the examples in order
/4_order_receipt/
/5_rover/
Myths
“Refactoring takes time”
Good design makes you faster
https://www.martinfowler.com/bliki/DesignStaminaHypothesis.html
Myths
“You don’t need to refactor
your test code”
TDD
Test Driven Development
Write a
test first
Implement
solution
Refactor
Commit
Add more tests
“Test code” is “code”
...and should be maintained
with the same quality criteria
Myths
“We need to stop the project
for this refactoring”
Boy scout rule
“Leave the campground
cleaner than you found it.”
Summary
●
Change code in “baby steps”
●
Make use of a test suite
●
Learn to identify “smells”
●
Try to make your code “obvious”
●
Continuously improve the “code design”
●
Practice, practice, practice makes perfect
:)
Feedback
bit.ly /
<add a feedback link>
Thank you! :)
This work is licensed under a Creative Commons
Attribution-ShareAlike 3.0 Unported License.
It makes use of the works of...
Slides template:
Mateus Machado Luna
Images credits:
https://www.flickr.com/photos/dietjay/3140774470/
https://www.flickr.com/photos/147489968@N06/
https://www.flickr.com/photos/silvertje/2197752384/
https://www.flickr.com/photos/mtneer_man/7819976694/
https://www.flickr.com/photos/lingoflora/2331681471/

More Related Content

PDF
Language portfolio
ODP
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
PDF
Pmd naming-rules
PDF
Common design patterns in php
PPTX
Behat - human-readable automated testing
PPTX
Coding standards for java
PPSX
Coding standard
ODP
BDD with Behat
Language portfolio
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Pmd naming-rules
Common design patterns in php
Behat - human-readable automated testing
Coding standards for java
Coding standard
BDD with Behat

Similar to Code refactoring workshop (in Javascript) (20)

PPTX
Refactoring, 2nd Edition
ODP
Refactoring: Improving the design of existing code
PPTX
Code refactoring
PPTX
Refactoring
PPTX
SAD10 - Refactoring
PDF
Day2 - Refactoring (Lecture SS 2015)
PPTX
Refactoring code in .net
PDF
Introduction to refactoring
PDF
Refactoring
PDF
So You Want to Start Refactoring?
PDF
Refactoring 2TheMax (con ReSharper)
PPTX
Eurosport's Kodakademi #2
PDF
Refactoring
PDF
Refactoring
PPTX
Code Refactoring
PDF
Refactoring: Improve the design of existing code
PDF
The Power Of Refactoring (php|tek 09)
PDF
Code Refactoring
PPT
Refactoring Tips by Martin Fowler
PPTX
When to refactor
Refactoring, 2nd Edition
Refactoring: Improving the design of existing code
Code refactoring
Refactoring
SAD10 - Refactoring
Day2 - Refactoring (Lecture SS 2015)
Refactoring code in .net
Introduction to refactoring
Refactoring
So You Want to Start Refactoring?
Refactoring 2TheMax (con ReSharper)
Eurosport's Kodakademi #2
Refactoring
Refactoring
Code Refactoring
Refactoring: Improve the design of existing code
The Power Of Refactoring (php|tek 09)
Code Refactoring
Refactoring Tips by Martin Fowler
When to refactor
Ad

More from Ilias Bartolini (11)

PDF
Getting started with Ruby on Rails
PDF
Building and evolving microservices
PDF
Desing principles: tensions and synergies v3.0
PDF
Desing principles: tensions and synergies
PDF
Climate Change
PDF
Training and Coaching Agile Minds
PDF
Facilitation 101
PDF
The hidden beauty of the rainbow
PDF
Paul Collier - The Bottom Billion
PDF
A personal (self) review
PPTX
Lean startup And Occupy Movement
Getting started with Ruby on Rails
Building and evolving microservices
Desing principles: tensions and synergies v3.0
Desing principles: tensions and synergies
Climate Change
Training and Coaching Agile Minds
Facilitation 101
The hidden beauty of the rainbow
Paul Collier - The Bottom Billion
A personal (self) review
Lean startup And Occupy Movement
Ad

Recently uploaded (20)

PDF
top salesforce developer skills in 2025.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Digital Strategies for Manufacturing Companies
PDF
medical staffing services at VALiNTRY
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
L1 - Introduction to python Backend.pptx
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Transform Your Business with a Software ERP System
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
System and Network Administraation Chapter 3
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Design an Analysis of Algorithms II-SECS-1021-03
top salesforce developer skills in 2025.pdf
Understanding Forklifts - TECH EHS Solution
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Digital Strategies for Manufacturing Companies
medical staffing services at VALiNTRY
Odoo POS Development Services by CandidRoot Solutions
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
2025 Textile ERP Trends: SAP, Odoo & Oracle
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
L1 - Introduction to python Backend.pptx
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Transform Your Business with a Software ERP System
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
System and Network Administraation Chapter 3
Upgrade and Innovation Strategies for SAP ERP Customers
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Design an Analysis of Algorithms II-SECS-1021-03

Code refactoring workshop (in Javascript)