Coding Dojo: 
Mars Rover 
Oct. 2014 
Peter Kofler, ‘Code Cop’ 
@codecopkofler 
www.code-cop.org 
Copyright Peter Kofler, licensed under CC-BY.
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
Peter Kofler 
• Ph.D. (Appl. Math.) 
• Professional Software 
Developer for 15 years 
• “fanatic about code quality” 
• I help development teams
Coding Dojo? 
Expectations?
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
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 
Two Basic Rules 
● Collaborative = Pair Programming 
● “Randori“ (pairing on the projector) 
● or programming in pairs 
● Test Driven Development 
● think about tests 
● write the test first
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
(Maybe Some) Constraints 
● Challenges during a dojo or coderetreat. 
● Moving to the extreme is a way of learning 
● Examples 
● Missing Tool (No Mouse, …) 
● Missing Feature (No IFs, …)
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
Dojo Structure 
● Introduction 15' 
● Coding 45' 
● Interim (Retrospective) 15' 
● Break 10' 
● Coding 45' 
● Retrospective 15'
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
Assignment
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
Mars Rover 
● Develop an API that moves a rover around on a grid. 
● You are given the initial starting point (x,y) of a rover and 
the direction ('N','S','E','W') it is facing. 
● The rover receives a character array of commands. 
● Move the rover forward/backward ('f','b'). 
● Turn the rover left/right ('l','r'). 
● Wrap the grid. (Planets are spheres after all.) 
● Detect obstacles before each move to a new square. If a 
sequence of commands encounters an obstacle, the rover 
moves up to the last possible point and reports obstacle.
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
Mars Rover Example 
● The rover is on a 
100x100 grid 
● at location (0, 0), 
● facing "N"ORTH. 
● The rover is given 
commands "ffrff" 
● and should end up 
at (2, 2). 
r f f 
f 
f 
(0,0) 
N 
(2,2)
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
Remember the Rules!
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
Pair Programming & TDD 
● regular Pair Programming 
– do not talk for too long 
– do not interrupt the other 
– no “keyboard hugging“ 
● use TDD (or at least “sort of” TDD) 
– write a test before you write code 
– refactor mercilessly 
– no debugger
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
With a Constraint
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
“Yes, and ...“ 
● When working in pairs none of the pairs 
is allowed to delete the code of the other 
person. 
● We are looking for a common solution, 
that both of the pairs will agree. 
● Learn to build on top of the ideas 
already presented.
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
“Yes, and ...“ Rules 
● improve existing code of the other 
● can not delete code of the other 
● whenever one tries to delete code, say: 
“You should improve the existing one. 
Please go back and say Yes, and… I will do…” 
● Can not be angry on request of not deleting code. 
● Only unused code can be deleted. 
● Both must agree that the code can be deleted.
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
Prepare 
● Find a pair. 
● Choose a programming language. 
● Set up the environment. 
● Create new project. 
● Add testing framework. 
● Check requirements. 
● Implement Mars Rover.
Don't Focus on 
Getting it Done. 
F0cus on Doing 
It Perfectly.
→ Practice
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
Short Closing Circle 
● How did it work out? 
● How do you feel? 
● What did you 
learn and want 
to share with 
the group?
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
Full 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 
Global Day of Code Retreat 
● A world-wide event celebrating passion 
and software craftsmanship. 
● GDCR 2014: 
15th November 
● Follow #GDCR14 
http://globalday.coderetreat.org/
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
Peter Kofler 
@codecopkofler 
www.code-cop.org 
Game by 
Adrian Bolboaca 
@adibolb 
http://blog.adrianbolboaca.ro/2013/12/pair-programming-game-yes-and/
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY 
CC Images 
● Rover Selfie http://www.flickr.com/photos/gsfc/7971341456 
● Dojo 
http://www.flickr.com/photos/49715404@N00/3267627038/ 
● Todos 
http://www.flickr.com/photos/kylesteeddesign/3724074594/ 
● Curiosity http://www.flickr.com/photos/mendhak/8162305237 
● Rule http://www.flickr.com/photos/phunk/4188827473 
● Model http://www.flickr.com/photos/eldave/8430367749 
● Wants you http://www.flickr.com/photos/shutter/105497713/

Coding Dojo: Mars Rover (2014)

  • 1.
    Coding Dojo: MarsRover Oct. 2014 Peter Kofler, ‘Code Cop’ @codecopkofler www.code-cop.org Copyright Peter Kofler, licensed under CC-BY.
  • 2.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY Peter Kofler • Ph.D. (Appl. Math.) • Professional Software Developer for 15 years • “fanatic about code quality” • I help development teams
  • 3.
  • 4.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY Coding Dojo Mindset ● Safe place outside work ● We are here to learn ● Need to slow down ● Focus on doing it right ● Collaborative Game
  • 5.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY Two Basic Rules ● Collaborative = Pair Programming ● “Randori“ (pairing on the projector) ● or programming in pairs ● Test Driven Development ● think about tests ● write the test first
  • 6.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY (Maybe Some) Constraints ● Challenges during a dojo or coderetreat. ● Moving to the extreme is a way of learning ● Examples ● Missing Tool (No Mouse, …) ● Missing Feature (No IFs, …)
  • 7.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY Dojo Structure ● Introduction 15' ● Coding 45' ● Interim (Retrospective) 15' ● Break 10' ● Coding 45' ● Retrospective 15'
  • 8.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY Assignment
  • 9.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY Mars Rover ● Develop an API that moves a rover around on a grid. ● You are given the initial starting point (x,y) of a rover and the direction ('N','S','E','W') it is facing. ● The rover receives a character array of commands. ● Move the rover forward/backward ('f','b'). ● Turn the rover left/right ('l','r'). ● Wrap the grid. (Planets are spheres after all.) ● Detect obstacles before each move to a new square. If a sequence of commands encounters an obstacle, the rover moves up to the last possible point and reports obstacle.
  • 10.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY Mars Rover Example ● The rover is on a 100x100 grid ● at location (0, 0), ● facing "N"ORTH. ● The rover is given commands "ffrff" ● and should end up at (2, 2). r f f f f (0,0) N (2,2)
  • 11.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY Remember the Rules!
  • 12.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY Pair Programming & TDD ● regular Pair Programming – do not talk for too long – do not interrupt the other – no “keyboard hugging“ ● use TDD (or at least “sort of” TDD) – write a test before you write code – refactor mercilessly – no debugger
  • 13.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY With a Constraint
  • 14.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY “Yes, and ...“ ● When working in pairs none of the pairs is allowed to delete the code of the other person. ● We are looking for a common solution, that both of the pairs will agree. ● Learn to build on top of the ideas already presented.
  • 15.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY “Yes, and ...“ Rules ● improve existing code of the other ● can not delete code of the other ● whenever one tries to delete code, say: “You should improve the existing one. Please go back and say Yes, and… I will do…” ● Can not be angry on request of not deleting code. ● Only unused code can be deleted. ● Both must agree that the code can be deleted.
  • 16.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY Prepare ● Find a pair. ● Choose a programming language. ● Set up the environment. ● Create new project. ● Add testing framework. ● Check requirements. ● Implement Mars Rover.
  • 17.
    Don't Focus on Getting it Done. F0cus on Doing It Perfectly.
  • 18.
  • 19.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY Short Closing Circle ● How did it work out? ● How do you feel? ● What did you learn and want to share with the group?
  • 20.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY Full Closing Circle ● What did you learn today? ● What surprised you today? ● What will you do differently in the future?
  • 21.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY Global Day of Code Retreat ● A world-wide event celebrating passion and software craftsmanship. ● GDCR 2014: 15th November ● Follow #GDCR14 http://globalday.coderetreat.org/
  • 22.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY Peter Kofler @codecopkofler www.code-cop.org Game by Adrian Bolboaca @adibolb http://blog.adrianbolboaca.ro/2013/12/pair-programming-game-yes-and/
  • 23.
    PETER KOFLER, CODE-COP.ORGFANATIC ABOUT CODE QUALITY CC Images ● Rover Selfie http://www.flickr.com/photos/gsfc/7971341456 ● Dojo http://www.flickr.com/photos/49715404@N00/3267627038/ ● Todos http://www.flickr.com/photos/kylesteeddesign/3724074594/ ● Curiosity http://www.flickr.com/photos/mendhak/8162305237 ● Rule http://www.flickr.com/photos/phunk/4188827473 ● Model http://www.flickr.com/photos/eldave/8430367749 ● Wants you http://www.flickr.com/photos/shutter/105497713/