Rails Software Metrics
-
Upload
chiel -
Category
Technology
-
view
2.048 -
download
0
description
Transcript of Rails Software Metrics
Rails software metricsRoderick van Domburg
Nedforce COO
http://www.nedforce.nl
Roderick van Domburg
Lines of codeUsing stock Rails
rake stats
Occam’s Razor
Of two equivalent theories or explanations, all other things being equal, the simpler one is to be preferred.
Wikipedia, 6 June 2008
Comparative quality
Mephisto 0.8 Typo 5.0.3
Lines of code
Test lines of code
Code to test ratio
3694 6178
211 3298
1:0.1 1:0.5
Code to test ratio
Low Medium High
Ratio < 1:0.8 1:0.8 - 1:1.5 ≥ 1:1.5
1.000Average lines of code
per developerper year
Cost estimation
Can’t estimate lines of codebased on requirements!
Fenton & Pfleeger (1997)
Cost estimation
Line test coverageUsing rcov gem
Line coverage
• Formally: C0 coverage
• Lines of code that ran during tests
• Using rcov gem and rails_rcov plugin
rake test:units:rcov
Comparative quality
Mephisto 0.8 Typo 5.0.3
Lines of code
Test lines of code
Line test coverage
3694 6178
211 3298
34.5% 83.3%
71,4% coverage
def is_odd?(number) if number % 2 == 0 return true else return false endend
assert is_odd?(2)
100% coverage
def is_odd?(number) number % 2 == 0end
assert is_odd?(2)
Branch test coverageUsing heckle gem
Line coverage
• Formally: C1 coverage
• Possible branches that ran during tests
• Using heckle gem
Original
def is_odd?(number) if number % 2 == 0 return true else return false endend
assert is_foo?(2)
Mutation 1
def is_odd?(number) if number % 2 == 0 return false else return true endend
assert is_foo?(2)
Mutation 2
def is_odd?(number) if nil % 2 == 0 return true else return false endend
assert is_foo?(2)
Code complexityUsing flog gem
test.rb
class Test def blah a = eval “1+1” if a == 2 puts “yay” end endend
flog test.rb
Test#blah: (11.2) 6.0: eval 1.2: branch 1.2: == 1.2: puts 1.2: assignment 0.4: lit_fixnum
Comparative quality
Mephisto 0.8 Typo 5.0.3
article.rb
tag.rb
user.rb
325 574
97 67
124 81
Cyclomatic complexityUsing saikuro gem
Cyclomatic complexity
• Academic, formal
• Loosely: the number of statements that can not be expressed as simple flow structures (e.g. if, else, while)
Comparative quality
Mephisto 0.8 Typo 5.0.3
article.rb
tag.rb
user.rb
67 124
17 16
25 24
flog vs. saikuro
• Cyclometic complexity is disputed
• Flog is not academically proven
• Flog has better Ruby understanding
Tracking over time
• Snapshot metrics not very useful
• Comparisons very difficult
• Tracking over time spots problems
• Use CruiseControl.rb plus metric_fu