Upload
marc-rendl-ignacio
View
396
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Presented at Philippine Ruby Users Group Meetup last January 23, 2014
Citation preview
Marc Ignaciotwitter: @pd_igithub: @padi
Refactoring
RefactoringLong Methods
Definitions
Refactoring
● “…is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.”
- refactoring.com
Refactoring
● “…is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.”
- refactoring.com
Refactoring
● “…is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.”
- refactoring.com
Refactoring
● “…is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.”
- refactoring.com● “Tests are implied.” - Katrina Owen
Refactoring
● “…is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.”
- refactoring.com
Refactoring
a technique for restructuring code without changing
behavior
Refactoring
a technique for making code suck less without changing
behavior
Refactoring
Long Methods
● “a method, function, or procedure that has grown too large”
Long Methods
● “a method, function, or procedure that has grown too large”
Long Methods
● “a method, function, or procedure that has grown too large”
● IMO: a method with a flog score of > 20
Long Methods
● ruby gem for analyzing code pain● “Flog reports the most tortured code in an
easy to read pain report.”● “The higher the score, the more pain the
code is in.”
Flog
Flog Scores● 0-10 Awesome● 11-20 Good enough● 21-40 Might need refactoring● 41-60 Possible to justify● 61-100 Danger● 100-200 Whoop, whoop, whoop● 200 + Someone please think of the children
Long Methods● If a method is long, it’s likely that it does too
many things.● “Methods, like classes, should have single
responsibility.” - Sandi Metz● SRP - every class should have a single
responsibility, and that responsibility should be entirely encapsulated by the class
Techniques
● Extract Method● Inline Method● Inline Temp● Replace Temp with Query● Replace Method w/ Method Object
Techniques
Examples
Resources
Resources- "Refactoring: Improving the Design of Existing Code", Martin Fowler- refactoring.com- jakescruggs.blogspot.com/2008/08/
whats-good-flog-score.html
Code:- "Refactoring, Ruby Edition", Martin Fowler et al.- "Therapeutic Refactoring", Katrina Owens
kk
Questions?
Thanks!