Rails Software Metrics

30
Rails software metrics Roderick van Domburg Nedforce COO http://www.nedforce.nl

description

 

Transcript of Rails Software Metrics

Page 1: Rails Software Metrics

Rails software metricsRoderick van Domburg

Nedforce COO

http://www.nedforce.nl

Page 2: Rails Software Metrics

Roderick van Domburg

Page 3: Rails Software Metrics

Lines of codeUsing stock Rails

Page 4: Rails Software Metrics

rake stats

Page 5: Rails Software Metrics

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

Page 6: Rails Software Metrics

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

Page 7: Rails Software Metrics

Code to test ratio

Low Medium High

Ratio < 1:0.8 1:0.8 - 1:1.5 ≥ 1:1.5

Page 8: Rails Software Metrics

1.000Average lines of code

per developerper year

Cost estimation

Page 9: Rails Software Metrics

Can’t estimate lines of codebased on requirements!

Fenton & Pfleeger (1997)

Cost estimation

Page 10: Rails Software Metrics

Line test coverageUsing rcov gem

Page 11: Rails Software Metrics

Line coverage

• Formally: C0 coverage

• Lines of code that ran during tests

• Using rcov gem and rails_rcov plugin

Page 12: Rails Software Metrics

rake test:units:rcov

Page 13: Rails Software Metrics

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%

Page 14: Rails Software Metrics

71,4% coverage

def is_odd?(number) if number % 2 == 0 return true else return false endend

assert is_odd?(2)

Page 15: Rails Software Metrics

100% coverage

def is_odd?(number) number % 2 == 0end

assert is_odd?(2)

Page 16: Rails Software Metrics

Branch test coverageUsing heckle gem

Page 17: Rails Software Metrics

Line coverage

• Formally: C1 coverage

• Possible branches that ran during tests

• Using heckle gem

Page 18: Rails Software Metrics

Original

def is_odd?(number) if number % 2 == 0 return true else return false endend

assert is_foo?(2)

Page 19: Rails Software Metrics

Mutation 1

def is_odd?(number) if number % 2 == 0 return false else return true endend

assert is_foo?(2)

Page 20: Rails Software Metrics

Mutation 2

def is_odd?(number) if nil % 2 == 0 return true else return false endend

assert is_foo?(2)

Page 21: Rails Software Metrics

Code complexityUsing flog gem

Page 22: Rails Software Metrics

test.rb

class Test def blah a = eval “1+1” if a == 2 puts “yay” end endend

Page 23: Rails Software Metrics

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

Page 24: Rails Software Metrics

Comparative quality

Mephisto 0.8 Typo 5.0.3

article.rb

tag.rb

user.rb

325 574

97 67

124 81

Page 25: Rails Software Metrics

Cyclomatic complexityUsing saikuro gem

Page 26: Rails Software Metrics

Cyclomatic complexity

• Academic, formal

• Loosely: the number of statements that can not be expressed as simple flow structures (e.g. if, else, while)

Page 27: Rails Software Metrics

Comparative quality

Mephisto 0.8 Typo 5.0.3

article.rb

tag.rb

user.rb

67 124

17 16

25 24

Page 28: Rails Software Metrics

flog vs. saikuro

• Cyclometic complexity is disputed

• Flog is not academically proven

• Flog has better Ruby understanding

Page 29: Rails Software Metrics

Tracking over time

• Snapshot metrics not very useful

• Comparisons very difficult

• Tracking over time spots problems

• Use CruiseControl.rb plus metric_fu

Page 30: Rails Software Metrics

Questions

http://www.nedforce.nl