rubyconf uruguay 2011
DESCRIPTION
Talk given in Montevideo in 2011 for 30mins. Focussing on code quality and understanding what that means.TRANSCRIPT
Ola.
@nigelfds
github.com/nigelfds
(Talk + Examples) ~ 1hour
(Talk – Examples) ~ 30mins
Refactoring?
a change made to the internal structure of soFware to make it easier to understand and cheaper
to modify without changing its observable behavior
-‐ MarLn Fowler
Don't touch anything that doesn't have coverage.
Otherwise, you're not refactoring; you're just changing shit.
a change made to the internal structure of soFware to make it
easier to understand and cheaper to modify without changing its observable behavior
-‐ MarLn Fowler
SomeLmes it just feels
right.
Step 1: Measure the
toxicity.
Smells in the code
CyclomaLc Complexity
5 to 7 is decent for most ruby code
Saikuro
Assignments, Branches, Calls with Flog
Watch for scores greater than 40
Flog
DuplicaLon with Flay
Watch for scores greater than 30
Flay
Control Couples and more with Reek
Simulated Polymorphism Feature Envy ULlity Methods
LinLng with Dust/Nitpick
Branch Checks
Common smells in Ruby
PrimiLve Obsession
Feature Envy
class Cart def price @item.price + @item.tax
end end
Meta-‐programming
Keep it simple. Keep it declaraLve
Toxicity is more than code smells
“The real problem I have with the CK suite and similar metrics is that they only measure a single module (or class in this case). I claim that the quality of the design of a system is not something that can be determined by looking at individual classes. It is conceivable that every class in a system could be considered reasonable by whatever single-‐class metrics are being used, but the overall design is considered bad.”
hDp://www.cs.auckland.ac.nz/~ewan/
Ewan Tempero: A Research Agenda
Duplicity vs Coupling
DEPENDENCY
Tangles
Step 2: Make it visible
Treemaps (Max CC)
hbp://mbostock.github.com/protovis/
Treemaps
Dependency matrix
Step 3: Agree on the fix
Step 4: Go fix it
“I do believe that complexity is the enemy. UnKl we beDer understand complexity, our chances of building beDer IT systems is limited. The first thing we must understand about complexity is that not all complexity is equal. And the complexity on which most people focus is probably the least complex complexity of all.”
hbp://simplearchitectures.blogspot.com/2009/03/cancer-‐of-‐complexity.html
Roger Sessions
Gracias