Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rules

66ad01cf37c098bfdb76906a490e018f?s=47 Sandi Metz
September 15, 2013

 Rules

We're iconoclasts who reject arbitrary constraints yet long for
understandable, predictable, changeable applications. We want code that
follows rules yet we refuse to let rules to get in our way. We're
deeply attached to the little rules that help get things done (No
trailing whitespace! Indent using two spaces!) and despise the big,
complicated ones that impose one-size-fits-all straitjackets on
otherwise sane programming problems.

This talk proposes 5 'little' rules for writing object-oriented code.
These rules are determinedly simple yet produce code that experts love
and novices can be trusted to change; they fill the space between
anarchy and order with practical, common sense. The rules guide without
impeding, help without hindering and constrain without binding, and let
you create applications that are easy to change and fun to work their
whole life long.

66ad01cf37c098bfdb76906a490e018f?s=128

Sandi Metz

September 15, 2013
Tweet

Transcript

  1. @sandimetz Sep 2013 Sandi Metz Rules 1 Sunday, September 15,

    13
  2. @sandimetz Sep 2013 taboos 2 Sunday, September 15, 13

  3. @sandimetz Sep 2013 3 Sunday, September 15, 13

  4. @sandimetz Sep 2013 laws 4 Sunday, September 15, 13

  5. @sandimetz Sep 2013 5 Sunday, September 15, 13

  6. @sandimetz Sep 2013 norms 6 Sunday, September 15, 13

  7. @sandimetz Sep 2013 7 Sunday, September 15, 13

  8. @sandimetz Sep 2013 obedience? 8 Sunday, September 15, 13

  9. @sandimetz Sep 2013 1 self interest 9 Sunday, September 15,

    13
  10. @sandimetz Sep 2013 10 Sunday, September 15, 13

  11. @sandimetz Sep 2013 2 identity status 11 Sunday, September 15,

    13
  12. @sandimetz Sep 2013 12 Sunday, September 15, 13

  13. @sandimetz Sep 2013 13 Sunday, September 15, 13

  14. @sandimetz Sep 2013 14 Sunday, September 15, 13

  15. @sandimetz Sep 2013 15 Sunday, September 15, 13

  16. @sandimetz Sep 2013 16 Sunday, September 15, 13

  17. @sandimetz Sep 2013 3 authority 17 Sunday, September 15, 13

  18. @sandimetz Sep 2013 18 Sunday, September 15, 13

  19. @sandimetz Sep 2013 19 Sunday, September 15, 13

  20. @sandimetz Sep 2013 20 Sunday, September 15, 13

  21. @sandimetz Sep 2013 4 order 21 Sunday, September 15, 13

  22. @sandimetz Sep 2013 22 Sunday, September 15, 13

  23. @sandimetz Sep 2013 23 Sunday, September 15, 13

  24. @sandimetz Sep 2013 24 Sunday, September 15, 13

  25. @sandimetz Sep 2013 5 social sanctions 25 Sunday, September 15,

    13
  26. @sandimetz Sep 2013 26 Sunday, September 15, 13

  27. @sandimetz Sep 2013 6 inherent sanctions 27 Sunday, September 15,

    13
  28. @sandimetz Sep 2013 28 Sunday, September 15, 13

  29. @sandimetz Sep 2013 7 ignorance 29 Sunday, September 15, 13

  30. @sandimetz Sep 2013 30 Sunday, September 15, 13

  31. @sandimetz Sep 2013 8 habit 31 Sunday, September 15, 13

  32. @sandimetz Sep 2013 32 Sunday, September 15, 13

  33. @sandimetz Sep 2013 33 Sunday, September 15, 13

  34. @sandimetz Sep 2013 34 Sunday, September 15, 13

  35. @sandimetz Sep 2013 taboos laws norms 35 Sunday, September 15,

    13
  36. @sandimetz Sep 2013 self interest identity/status authority order social sanctions

    inherent sanctions ignorance habit 36 Sunday, September 15, 13
  37. @sandimetz Sep 2013 5 Rules 37 Sunday, September 15, 13

  38. @sandimetz Sep 2013 5 Constraints 38 Sunday, September 15, 13

  39. @sandimetz Sep 2013 100 lines per class 39 Sunday, September

    15, 13
  40. @sandimetz Sep 2013 5 lines per method 40 Sunday, September

    15, 13
  41. @sandimetz Sep 2013 4 parameters per method 41 Sunday, September

    15, 13
  42. @sandimetz Sep 2013 1 instance var per rails view 42

    Sunday, September 15, 13
  43. @sandimetz Sep 2013 2 class names per rails controller action

    43 Sunday, September 15, 13
  44. @sandimetz Sep 2013 2 class names per rails controller action

    (business, presenter) 43 Sunday, September 15, 13
  45. @sandimetz Sep 2013 44 Sunday, September 15, 13

  46. @sandimetz Sep 2013 Dispensation? 44 Sunday, September 15, 13

  47. @sandimetz Sep 2013 Dispensation? Convince your pair!* sdf *Rule #6

    44 Sunday, September 15, 13
  48. @sandimetz Sep 2013 100 lines per class    5 lines

    per method    4 params per method    1 ivar per view    2 class names per controller action No More Than 45 Sunday, September 15, 13
  49. @sandimetz Sep 2013 consequences 46 Sunday, September 15, 13

  50. @sandimetz Sep 2013 bias towards small objects 47 Sunday, September

    15, 13
  51. @sandimetz Sep 2013 bias towards POROs 48 Sunday, September 15,

    13
  52. @sandimetz Sep 2013 bias away from dependencies 49 Sunday, September

    15, 13
  53. @sandimetz Sep 2013 rule qualities 50 Sunday, September 15, 13

  54. @sandimetz Sep 2013 arbitrary cut-offs 51 Sunday, September 15, 13

  55. @sandimetz Sep 2013 consistent goals 52 Sunday, September 15, 13

  56. @sandimetz Sep 2013 tension 53 Sunday, September 15, 13

  57. @sandimetz Sep 2013 objects 54 Sunday, September 15, 13

  58. @sandimetz Sep 2013 objects vs 55 Sunday, September 15, 13

  59. @sandimetz Sep 2013 objects vs procedures 56 Sunday, September 15,

    13
  60. @sandimetz Sep 2013 objects vs procedures 57 Sunday, September 15,

    13
  61. @sandimetz Sep 2013 objects vs procedures 58 Sunday, September 15,

    13
  62. @sandimetz Sep 2013 perspective 59 Sunday, September 15, 13

  63. @sandimetz Sep 2013 Rails app 60 Sunday, September 15, 13

  64. @sandimetz Sep 2013 Rails app vs 61 Sunday, September 15,

    13
  65. @sandimetz Sep 2013 Rails app vs application that uses Rails

    62 Sunday, September 15, 13
  66. @sandimetz Sep 2013 why follow rules? 63 Sunday, September 15,

    13
  67. @sandimetz Sep 2013 self interest 64 Sunday, September 15, 13

  68. @sandimetz Sep 2013 signal others? 65 Sunday, September 15, 13

  69. @sandimetz Sep 2013 research 66 Sunday, September 15, 13

  70. @sandimetz Sep 2013 Erik O. Kimbrough Alexander Vostroknutov 67 Sunday,

    September 15, 13
  71. @sandimetz Sep 2013 Using Rules to Screen for Cooperative Types:

    Rule-Following and Restraint in Common Pool Resource Systems 68 Sunday, September 15, 13
  72. @sandimetz Sep 2013 Using Rules to Screen for Cooperative Types:

    Rule-Following and Restraint in Common Pool Resource Systems 69 Sunday, September 15, 13
  73. @sandimetz Sep 2013 study 70 Sunday, September 15, 13

  74. @sandimetz Sep 2013 study part 1 71 Sunday, September 15,

    13
  75. @sandimetz Sep 2013 identify followers vs breakers 72 Sunday, September

    15, 13
  76. @sandimetz Sep 2013 73 Sunday, September 15, 13

  77. @sandimetz Sep 2013 Task: Walk---------> 73 Sunday, September 15, 13

  78. @sandimetz Sep 2013 Task: Walk---------> 73 Sunday, September 15, 13

  79. @sandimetz Sep 2013 Task: Walk---------> 73 Sunday, September 15, 13

  80. @sandimetz Sep 2013 given 8€ 74 Sunday, September 15, 13

  81. @sandimetz Sep 2013 lose .08€ per second 75 Sunday, September

    15, 13
  82. @sandimetz Sep 2013 red light = 5 seconds 76 Sunday,

    September 15, 13
  83. @sandimetz Sep 2013 “Wait for green light.” 77 Sunday, September

    15, 13
  84. @sandimetz Sep 2013 some folks 78 Sunday, September 15, 13

  85. @sandimetz Sep 2013 79 Sunday, September 15, 13

  86. @sandimetz Sep 2013 79 Sunday, September 15, 13

  87. @sandimetz Sep 2013 80 Sunday, September 15, 13

  88. @sandimetz Sep 2013 80 Sunday, September 15, 13

  89. @sandimetz Sep 2013 81 Sunday, September 15, 13

  90. @sandimetz Sep 2013 82 Sunday, September 15, 13

  91. @sandimetz Sep 2013 82 Sunday, September 15, 13

  92. @sandimetz Sep 2013 83 Sunday, September 15, 13

  93. @sandimetz Sep 2013 etc... 83 Sunday, September 15, 13

  94. @sandimetz Sep 2013 other folks 84 Sunday, September 15, 13

  95. @sandimetz Sep 2013 85 Sunday, September 15, 13

  96. @sandimetz Sep 2013 85 Sunday, September 15, 13

  97. @sandimetz Sep 2013 study part 2 86 Sunday, September 15,

    13
  98. @sandimetz Sep 2013 separate into like groups 87 Sunday, September

    15, 13
  99. @sandimetz Sep 2013 play cooperative game 88 Sunday, September 15,

    13
  100. @sandimetz Sep 2013 89 Sunday, September 15, 13

  101. @sandimetz Sep 2013  4 players 89 Sunday, September 15, 13

  102. @sandimetz Sep 2013  4 players 10 rounds 89 Sunday, September

    15, 13
  103. @sandimetz Sep 2013  4 players 10 rounds draw tokens 89

    Sunday, September 15, 13
  104. @sandimetz Sep 2013 90 Sunday, September 15, 13

  105. @sandimetz Sep 2013 90 Sunday, September 15, 13

  106. @sandimetz Sep 2013 ∞ 90 Sunday, September 15, 13

  107. @sandimetz Sep 2013 1 1 1 1 ∞ 90 Sunday,

    September 15, 13
  108. @sandimetz Sep 2013 1 1 1 1 ∞ 90 Sunday,

    September 15, 13
  109. @sandimetz Sep 2013 1 1 1 1 360 ∞ 90

    Sunday, September 15, 13
  110. @sandimetz Sep 2013 1 1 1 1 360 2 ∞

    90 Sunday, September 15, 13
  111. @sandimetz Sep 2013 each player draws 60 tokens per round

    91 Sunday, September 15, 13
  112. @sandimetz Sep 2013 Round 1 92 Sunday, September 15, 13

  113. @sandimetz Sep 2013 Round 1 120 92 Sunday, September 15,

    13
  114. @sandimetz Sep 2013 120 Regeneration 93 Sunday, September 15, 13

  115. @sandimetz Sep 2013 120 * .5 Regeneration 94 Sunday, September

    15, 13
  116. @sandimetz Sep 2013 180 Regeneration 95 Sunday, September 15, 13

  117. @sandimetz Sep 2013 Regeneration 96 Sunday, September 15, 13

  118. @sandimetz Sep 2013 Regeneration 96 Sunday, September 15, 13

  119. @sandimetz Sep 2013 30 Regeneration 97 Sunday, September 15, 13

  120. @sandimetz Sep 2013 30 Regeneration 97 Sunday, September 15, 13

  121. @sandimetz Sep 2013 Round 2 180 remain?? 98 Sunday, September

    15, 13
  122. @sandimetz Sep 2013 Round 2 180 - 30 = 150

    99 Sunday, September 15, 13
  123. @sandimetz Sep 2013 Round 2 180 - 30 = 150

    150 / 4 = 37.5 100 Sunday, September 15, 13
  124. @sandimetz Sep 2013 Round 2 37! 101 Sunday, September 15,

    13
  125. @sandimetz Sep 2013 180 Round 2 1 1 1 1

    2 102 Sunday, September 15, 13
  126. @sandimetz Sep 2013 Round 2 103 Sunday, September 15, 13

  127. @sandimetz Sep 2013 Round 2 32 103 Sunday, September 15,

    13
  128. @sandimetz Sep 2013 32 Regeneration 104 Sunday, September 15, 13

  129. @sandimetz Sep 2013 32 * .5 Regeneration 105 Sunday, September

    15, 13
  130. @sandimetz Sep 2013 48 Regeneration 106 Sunday, September 15, 13

  131. @sandimetz Sep 2013 48 Regeneration Etc... 106 Sunday, September 15,

    13
  132. @sandimetz Sep 2013 (current - 30) / 4 107 Sunday,

    September 15, 13
  133. @sandimetz Sep 2013 results 108 Sunday, September 15, 13

  134. @sandimetz Sep 2013 followers 109 Sunday, September 15, 13

  135. @sandimetz Sep 2013 followers cooperate for mutual long term gain

    109 Sunday, September 15, 13
  136. @sandimetz Sep 2013 breakers 110 Sunday, September 15, 13

  137. @sandimetz Sep 2013 breakers throw team under bus 110 Sunday,

    September 15, 13
  138. @sandimetz Sep 2013 60! 60! 60! 60! 111 Sunday, September

    15, 13
  139. @sandimetz Sep 2013 mixed groups 112 Sunday, September 15, 13

  140. @sandimetz Sep 2013 mixed groups behave like breaker groups 112

    Sunday, September 15, 13
  141. @sandimetz Sep 2013 30! 30! 30! 50! 113 Sunday, September

    15, 13
  142. @sandimetz Sep 2013 50! 114 Sunday, September 15, 13

  143. @sandimetz Sep 2013 60! 60! 60! 50! 114 Sunday, September

    15, 13
  144. @sandimetz Sep 2013 consequences (reprise) 115 Sunday, September 15, 13

  145. @sandimetz Sep 2013 bias towards small objects 116 Sunday, September

    15, 13
  146. @sandimetz Sep 2013 bias towards POROs 117 Sunday, September 15,

    13
  147. @sandimetz Sep 2013 bias away from dependencies 118 Sunday, September

    15, 13
  148. @sandimetz Sep 2013 bias towards collaboration 119 Sunday, September 15,

    13
  149. @sandimetz Sep 2013 bias towards collaboration 119 Sunday, September 15,

    13
  150. @sandimetz Sep 2013 self interest identity/status authority order social sanctions

    inherent sanctions ignorance habit 120 Sunday, September 15, 13
  151. @sandimetz Sep 2013 9 signal cooperation 121 Sunday, September 15,

    13
  152. @sandimetz Sep 2013 rules matter 122 Sunday, September 15, 13

  153. @sandimetz Sep 2013 write better software 123 Sunday, September 15,

    13
  154. @sandimetz Sep 2013 find trustworthy humans 124 Sunday, September 15,

    13
  155. @sandimetz Sep 2013 Thanks 125 Sunday, September 15, 13

  156. @sandimetz Sep 2013 Credits http://www.flickr.com/photos/paul-w-locke/1792803096/ Cannibal Pumpkins http://www.flickr.com/photos/john_pp/3155064087/ 100K Speed

    limit sign on cliff with hiker http://www.flickr.com/photos/paphio/272769602/ Cops cheek kissing http://www.flickr.com/photos/pixel8-rcrd/5791227393/ kid winning contest http://www.flickr.com/photos/fluffy_steve/2537798898/ two goths http://www.flickr.com/photos/bobjagendorf/3064198102/ wall street shuffle http://www.flickr.com/photos/pdsphil/278060802/ rubyconf room 2006 http://www.flickr.com/photos/danicuki/6319528505/ konstanin and jose http://www.flickr.com/photos/lucasrenan/5142409437/ 3 ruby nerds, 10/26/2010 http://www.flickr.com/photos/85529750@N00/5200928365/ pope barcelona http://www.flickr.com/photos/nathaninsandiego/3783772122/ umpire http://www.flickr.com/photos/rrrodrigo/4664885112/ matz http://www.flickr.com/photos/85529750@N00/5200928365/ pope barcelona http://www.flickr.com/photos/nathaninsandiego/3783772122/ umpire http://www.flickr.com/photos/rrrodrigo/4664885112/ matz http://www.flickr.com/photos/z_wenjie/7820625836 pansies http://www.flickr.com/photos/haikugirl/4813516858/ trees http://www.flickr.com/photos/emsef/2407145479/ bus stop queue http://www.flickr.com/photos/theretrographer/9228096325/ rows of jail cells brightly lit 126 Sunday, September 15, 13
  157. @sandimetz Sep 2013 Credits http://www.flickr.com/photos/jakebouma/102485568/ Car cliff warning http://www.flickr.com/photos/burge009/5215723703/ free

    tatoos http://www.flickr.com/photos/singularitysummit/6261754179/ one swarming robot http://www.flickr.com/photos/singularitysummit/6262287656/ swarming robots swarming http://www.flickr.com/photos/osakasteve/17178084/ swarming robots in a line http://en.wikipedia.org/wiki/Social_rule_system_theory Kinbrough, Erik O., Vosroknutov, Alexander (2012 draft), Using Rules to Screen for Cooperative Types: Rule-Following and Restraint in Common Pool Resource Systems 127 Sunday, September 15, 13
  158. http://poodr.com Sandi Metz @sandimetz @sandimetz Sep 2013 128 Sunday, September

    15, 13
  159. @sandimetz Sep 2013 Questions? 129 Sunday, September 15, 13

  160. http://poodr.com Sandi Metz @sandimetz @sandimetz Sep 2013 130 Sunday, September

    15, 13