This document discusses code refactoring in Javascript. It introduces refactoring and defines it as changing code without altering external behavior but improving internal structure. The document outlines an agenda including an introduction, examples, and a coding activity. It discusses code smells that indicate needs for refactoring, such as duplicated code. It emphasizes testing during refactoring and focusing on small, incremental changes. The overall message is that refactoring improves code quality and maintainability over time.
10. 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
11. 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
14. 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
19. Lets 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 ;)
28. 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
:)
30. This work is licensed under a Creative Commons
Attribution-ShareAlike 3.0 Unported License.
It makes use of the works of...
際際滷s 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/