RubyConf Uruguay 2011

44
Ola.

description

Talk given in Montevideo in 2011 for 30mins. Focussing on code quality and understanding what that means.

Transcript of RubyConf Uruguay 2011

Page 1: RubyConf Uruguay 2011

Ola.  

Page 2: RubyConf Uruguay 2011

@nigelfds  

github.com/nigelfds  

Page 3: RubyConf Uruguay 2011
Page 4: RubyConf Uruguay 2011
Page 5: RubyConf Uruguay 2011

(Talk  +  Examples)  ~  1hour  

(Talk  –  Examples)  ~  30mins  

Page 6: RubyConf Uruguay 2011
Page 7: RubyConf Uruguay 2011

Refactoring?  

Page 8: RubyConf Uruguay 2011

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  

Page 9: RubyConf Uruguay 2011

 Don't  touch  anything  that  doesn't  have  coverage.  

Otherwise,  you're  not  refactoring;  you're  just  changing  shit.  

Page 10: RubyConf Uruguay 2011
Page 11: RubyConf Uruguay 2011

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  

Page 12: RubyConf Uruguay 2011

SomeLmes    it  just  feels  

right.  

Page 13: RubyConf Uruguay 2011
Page 14: RubyConf Uruguay 2011

Step  1:  Measure  the  

toxicity.  

Page 15: RubyConf Uruguay 2011
Page 16: RubyConf Uruguay 2011

Smells  in  the  code  

Page 17: RubyConf Uruguay 2011

CyclomaLc  Complexity  

5  to  7  is  decent  for  most  ruby  code  

Page 18: RubyConf Uruguay 2011

Saikuro  

Page 19: RubyConf Uruguay 2011

Assignments,  Branches,  Calls    with  Flog  

Watch  for  scores  greater  than  40  

Page 20: RubyConf Uruguay 2011

Flog  

Page 21: RubyConf Uruguay 2011

DuplicaLon  with  Flay  

Watch  for  scores  greater  than  30  

Page 22: RubyConf Uruguay 2011

Flay  

Page 23: RubyConf Uruguay 2011

Control  Couples  and  more    with  Reek  

Simulated  Polymorphism  Feature  Envy  ULlity  Methods  

Page 24: RubyConf Uruguay 2011

LinLng  with  Dust/Nitpick  

Branch  Checks  

Page 25: RubyConf Uruguay 2011

Common  smells    in  Ruby    

Page 26: RubyConf Uruguay 2011

PrimiLve  Obsession  

Page 27: RubyConf Uruguay 2011

Feature  Envy  

class Cart def price @item.price + @item.tax

end end

Page 28: RubyConf Uruguay 2011

Meta-­‐programming  

Keep  it  simple.    Keep  it  declaraLve  

Page 29: RubyConf Uruguay 2011
Page 30: RubyConf Uruguay 2011

Toxicity  is  more  than  code  smells  

Page 31: RubyConf Uruguay 2011

“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  

Page 32: RubyConf Uruguay 2011

Duplicity  vs  Coupling  

Page 33: RubyConf Uruguay 2011

DEPENDENCY  

Page 34: RubyConf Uruguay 2011

Tangles  

Page 35: RubyConf Uruguay 2011

Step  2:  Make  it  visible  

Page 36: RubyConf Uruguay 2011

Treemaps  (Max  CC)  

hbp://mbostock.github.com/protovis/  

Page 37: RubyConf Uruguay 2011

Treemaps  

Page 38: RubyConf Uruguay 2011

Dependency  matrix  

Page 39: RubyConf Uruguay 2011

Step  3:  Agree  on  the  fix  

Page 40: RubyConf Uruguay 2011
Page 41: RubyConf Uruguay 2011
Page 42: RubyConf Uruguay 2011

Step  4:      Go  fix  it  

Page 43: RubyConf Uruguay 2011

“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  

Page 44: RubyConf Uruguay 2011

Gracias