Coding Dojo:
Adding Tests to the
Ugly Trivia Legacy Code
Feb. 2014
Peter Kofler, ‘Code Cop’
@codecopkofler
www.code-cop.or...
Peter Kofler
• Ph.D. (Appl. Math.)
• Professional Software
Developer for 14 years
• “fanatic about code quality”
• I help ...
Expectations?
Coding Dojo Mindset
●
Safe place outside
work
●
We are here to learn
●
Need to slow down
●
Focus on doing it right
●
Colla...
Dojo Structure
●
Introduction 15'
●
Coding 60'
●
Break
●
Interim (Retrospective) 15'
●
Coding 60'
●
Break
●
Coding 60'
●
R...
Legacy Code Skills
●
Understanding Legacy Code
●
Breaking Dependencies
●
Bringing Code Under Test 
●
Refactoring Merciles...
Ugly Trivia
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
Legacy Codebase “uglytrivia“
●
Get the code
https://github.com/jbrains/trivia
●
An implementation of Trivial Pursuit
●
htt...
Requirements
●
Choose a testing framework
●
Create tests, cover all cases
●
May need to extract code to do that
PETER KOFL...
Don't Focus on
Getting it Done.
F0cus on Doing
It Perfectly.
→Practice
Extract Pure Functions
●
find a piece of code that can be moved
into a separate function by using
“Extract Method“
●
repla...
Extract Class
●
isolate functionality that somehow
relates and can be separated from other
behaviour
●
turn isolated metho...
Closing Circle
●
What did you learn today?
●
What surprised you today?
●
What will you do
differently in the
future?
PETER...
Peter Kofler
@codecopkofler
www.code-cop.org
Idea by
J.B.Rainsberger
@jbrains
https://github.com/jbrains/trivia
PETER KOFL...
CC Images
●
Dojo http://www.flickr.com/photos/49715404@N00/3267627038/
●
Todos http://www.flickr.com/photos/kylesteeddesig...
Upcoming SlideShare
Loading in …5
×

Coding Dojo: Adding Tests to Legacy Code (2014)

416
-1

Published on

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

  • Be the first to like this

No Downloads
Views
Total Views
416
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Coding Dojo: Adding Tests to Legacy Code (2014)

  1. 1. Coding Dojo: Adding Tests to the Ugly Trivia Legacy Code Feb. 2014 Peter Kofler, ‘Code Cop’ @codecopkofler www.code-cop.org Copyright Peter Kofler, licensed under CC-BY.
  2. 2. Peter Kofler • Ph.D. (Appl. Math.) • Professional Software Developer for 14 years • “fanatic about code quality” • I help development teams PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  3. 3. Expectations?
  4. 4. Coding Dojo Mindset ● Safe place outside work ● We are here to learn ● Need to slow down ● Focus on doing it right ● Collaborative Game PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  5. 5. Dojo Structure ● Introduction 15' ● Coding 60' ● Break ● Interim (Retrospective) 15' ● Coding 60' ● Break ● Coding 60' ● Retrospective 30' PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  6. 6. Legacy Code Skills ● Understanding Legacy Code ● Breaking Dependencies ● Bringing Code Under Test  ● Refactoring Mercilessly PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  7. 7. Ugly Trivia PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  8. 8. Legacy Codebase “uglytrivia“ ● Get the code https://github.com/jbrains/trivia ● An implementation of Trivial Pursuit ● http://en.wikipedia.org/wiki/Trivial_Pursuit ● players take turns to answer trivia questions ● questions are split into categories ● players collect coins for right answers PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  9. 9. Requirements ● Choose a testing framework ● Create tests, cover all cases ● May need to extract code to do that PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  10. 10. Don't Focus on Getting it Done. F0cus on Doing It Perfectly.
  11. 11. →Practice
  12. 12. Extract Pure Functions ● find a piece of code that can be moved into a separate function by using “Extract Method“ ● replace all external dependencies within this function with independent parameters ● add a test for that function ● refactor the tested code as needed PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  13. 13. Extract Class ● isolate functionality that somehow relates and can be separated from other behaviour ● turn isolated methods into pure functions ● extract these pure functions into a separate class ● add tests for that new class PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  14. 14. Closing Circle ● What did you learn today? ● What surprised you today? ● What will you do differently in the future? PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  15. 15. Peter Kofler @codecopkofler www.code-cop.org Idea by J.B.Rainsberger @jbrains https://github.com/jbrains/trivia PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  16. 16. CC Images ● Dojo http://www.flickr.com/photos/49715404@N00/3267627038/ ● Todos http://www.flickr.com/photos/kylesteeddesign/3724074594/ ● Trivia http://www.flickr.com/photos/thehoneybunny/207992667/ ● Wants you http://www.flickr.com/photos/shutter/105497713/ PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×