Transformation Priority Premise: TDD Test Order Matters

2,241 views

Published on

When coding using TDD, do you often run into a point when you have to “implement the whole thing”? The sequence of tests that we write significantly impacts where are code ends up! We’ll explore Uncle Bob’s Transformation Priority Premise, looking at the transformations that code goes through and how our tests can drive the code in different directions.

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,241
On SlideShare
0
From Embeds
0
Number of Embeds
385
Actions
Shares
0
Downloads
24
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide
  • Familiarity with TDDFamiliarity with Principles of Simple Design
  • Where’s the love?There’s been an assumption that this is “regular” programming.
  • Code has mass, some constructs have more mass than others
  • Transformation Priority Premise: TDD Test Order Matters

    1. 1. Transformation Priority Premise:TDD Test Order MattersMike Clement@mdclementmike@softwareontheside.comhttp://blog.softwareontheside.comhttp://agilecodegames.com
    2. 2. XP Simple Design• Passes all tests• Clear, expressive, consistent• No duplication• Minimal
    3. 3. TDD ReviewTDD• Red• Green• RefactorWays to get Green• Fake it• Obviousimplementation• Triangulation
    4. 4. Example Transformations• ({}–>nil) no code at all->code that employs nil• (nil->constant)• (variable->assignment) replacing the value ofa variable.• (statement->statements) adding moreunconditional statements.
    5. 5. Uncle Bob’s Three Laws of TDD• You are not allowed to write any productioncode unless it is to make a failing unit testpass.• You are not allowed to write any more of aunit test than is sufficient to fail; andcompilation failures are failures.• You are not allowed to write any moreproduction code than is sufficient to pass theone failing unit test.
    6. 6. Rule ofPerpetualInconsequence
    7. 7. Proposed Transformations• ({}–>nil) no code at all->code that employs nil• (nil->constant)• (constant->constant+) a simple constant to a more complex constant• (constant->scalar) replacing a constant with a variable or an argument• (statement->statements) adding more unconditional statements.• (unconditional->if) splitting the execution path• (scalar->array)• (array->container)• (statement->recursion)• (if->while)• (expression->function) replacing an expression with a function oralgorithm• (variable->assignment) replacing the value of a variable.
    8. 8. WORD WRAPA Fork in the Road
    9. 9. Problem definition• function named Wrap that takes twoarguments, a string, and a column number• The function returns the string, but with linebreaks (n) inserted at just the right placesto make sure that no line is longer than thecolumn number.• Try to break lines at word boundaries.
    10. 10. LET’S CODE!
    11. 11. "I cant seem to get this testto pass without writing a lotof untested code."
    12. 12. They are the wrong tests,because you could not figureout how to pass them.
    13. 13. "[W]hen faced with aproblem you do notunderstand, do any part of ityou do understand, thenlook at it again."
    14. 14. The Premise Applied• Prefer higher priority transformations.• Choose tests that can be passed with higherpriority transformations.• When a low priority transformation seemsrequired, backtrack to see if there is a simplertest to pass.
    15. 15. WHAT ABOUT SOLUTION QUALITY?Sorting Algorithms
    16. 16. The Premise Applied• Prefer higher priority transformations.• Choose tests that can be passed with higherpriority transformations.• When a low priority transformation seemsrequired, backtrack to see if there is a simplertest to pass.
    17. 17. Proposed Prioritized Transformations• ({}–>nil) no code at all->code that employs nil• (nil->constant)• (constant->constant+) a simple constant to a more complex constant• (constant->scalar) replacing a constant with a variable or an argument• (statement->statements) adding more unconditional statements.• (unconditional->if) splitting the execution path• (scalar->array)• (array->container)• (statement->recursion)• (if->while)• (expression->function) replacing an expression with a function oralgorithm• (variable->assignment) replacing the value of a variable.
    18. 18. ABSOLUTE PRIORITY PREMISE“Cousin” Micah
    19. 19. Action Items!• Read the original posthttp://cleancoder.posterous.com/the-transformation-priority-premise• Sorting: http://cleancoder.posterous.com/transformation-priority-and-sorting• Fibonacci: http://cleancoder.posterous.com/fib-the-transformation-priority-premise• Flash Card: http://cleancoder.posterous.com/flash-tpp• Uncle Bob on TPP: https://vimeo.com/60561303• “Cousin” Micah on APP: https://vimeo.com/57851350 andhttps://vimeo.com/59265614• Experiment!
    20. 20. Software Craftsmanship!• Participate in a local Software Craftsmanshipgroup wherever home is for you.
    21. 21. My Contact Info• @mdclement• mike@softwareontheside.com• http://blog.softwareontheside.com• http://agilecodegames.com• Utah Software Craftsmanship Group– http://utahsc.org– @utahsc

    ×