Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Prime Factors Code Kata
(Practicing TDD in PHP)
ViennaPHP, Sept. 2014
Peter Kofler, ‘Code Cop’
@codecopkofler
www.code-cop...
Peter Kofler
• Ph.D. (Appl. Math.)
• Professional Software
Developer for 15 years
• “fanatic about code quality”
• I help ...
Deliberate
Practice
How do musicians practice?
Then how do coders practice?
Code Kata
Code Kata Definition
●
A kata as a detailed choreographed
pattern of movement.
●
A code kata is an exercise in
programming...
Code Kata
●
simple problem (max. 20 minutes)
●
solve every day
●
memorization
●
create reflexes
●
experiment with solution...
Why repeat the same kata?
●
de-emphasise the generation of code
●
concentrate on
●
the process of writing the code
●
namin...
Don't Focus on
Getting it Done.
F0cus on Doing
It Perfectly.
The Prime Factors
Kata
What Exactly Will We Do?
●
write code together
●
using TDD
●
see techniques
●
discuss
PETER KOFLER, CODE-COP.ORG FANATIC A...
The Requirements.
• Write a class named “PrimeFactors”
that has one static method: generate.
●
The generate method takes a...
First Some Math.
●
Prime Number: number > 1 that has
no divisors other than 1 and itself.
●
e.g. 2, 3, 5, 61, 67, ..., 997...
Don’t
Hurt
Me!
Demo
See step by step code: https://bitbucket.org/pkofler/primefactors.php
Unit Testing
• test individual units
• isolate each part
• show that individual parts are correct
• regression testing
• s...
Test-Driven Development
●
add a test
●
run all tests and see if the new one fails
●
write some code
●
run all tests and se...
“I write unit tests for one
reason: so my coworkers
don't f*** up my code.”
(David Angry)
Coding Dojo Vienna
●
Biweekly Coding Dojo in Vienna
●
Every other Wednesday 6PM
●
Changing locations
●
Follow
#CodingDojoV...
Global Day of Code Retreat
●
A world-wide event celebrating passion
and software craftsmanship.
●
GDCR 2014:
15th November...
Peter Kofler
@codecopkofler
www.code-cop.org
PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
CC Images
●
karate
http://www.flickr.com/photos/the-consortium/5301698212/
●
music
https://www.flickr.com/photos/jeremyhie...
Upcoming SlideShare
Loading in …5
×

Prime Factors Code Kata - Practicing TDD (2014)

1,432 views

Published on

PrimeFactors Code Kata as performed during my presentation on katas at ViennaPHP.

Published in: Technology
  • Be the first to comment

Prime Factors Code Kata - Practicing TDD (2014)

  1. 1. Prime Factors Code Kata (Practicing TDD in PHP) ViennaPHP, Sept. 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 15 years • “fanatic about code quality” • I help development teams PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  3. 3. Deliberate Practice
  4. 4. How do musicians practice?
  5. 5. Then how do coders practice?
  6. 6. Code Kata
  7. 7. Code Kata Definition ● A kata as a detailed choreographed pattern of movement. ● A code kata is an exercise in programming which helps a programmer hone their skills through practice and repetition. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  8. 8. Code Kata ● simple problem (max. 20 minutes) ● solve every day ● memorization ● create reflexes ● experiment with solutions ● stretch yourself PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  9. 9. Why repeat the same kata? ● de-emphasise the generation of code ● concentrate on ● the process of writing the code ● naming test cases ● the Red/Green cycle 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. The Prime Factors Kata
  12. 12. What Exactly Will We Do? ● write code together ● using TDD ● see techniques ● discuss PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  13. 13. The Requirements. • Write a class named “PrimeFactors” that has one static method: generate. ● The generate method takes an integer argument and returns a List<Integer>. ● That list contains the prime factors in numerical sequence. PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY http://butunclebob.com/ArticleS.UncleBob.ThePrimeFactorsKata
  14. 14. First Some Math. ● Prime Number: number > 1 that has no divisors other than 1 and itself. ● e.g. 2, 3, 5, 61, 67, ..., 997, ..., 243112609 -1 ● Prime Factors: prime numbers that divide an integer without remainder. ● e.g. 2 = 2, 4 = 2 * 2, 24 = 2 * 2 * 2 * 3 288 = 25 * 32 PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  15. 15. Don’t Hurt Me!
  16. 16. Demo See step by step code: https://bitbucket.org/pkofler/primefactors.php
  17. 17. Unit Testing • test individual units • isolate each part • show that individual parts are correct • regression testing • sort of living documentation • executed within a framework PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  18. 18. Test-Driven Development ● add a test ● run all tests and see if the new one fails ● write some code ● run all tests and see them succeed ● refactor code mercilessly ● „Red Green Refactor“ PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  19. 19. “I write unit tests for one reason: so my coworkers don't f*** up my code.” (David Angry)
  20. 20. Coding Dojo Vienna ● Biweekly Coding Dojo in Vienna ● Every other Wednesday 6PM ● Changing locations ● Follow #CodingDojoVie PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY http://codingdojovie.github.io/
  21. 21. Global Day of Code Retreat ● A world-wide event celebrating passion and software craftsmanship. ● GDCR 2014: 15th November ● Follow #GDCR14 PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY http://globalday.coderetreat.org/
  22. 22. Peter Kofler @codecopkofler www.code-cop.org PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY
  23. 23. CC Images ● karate http://www.flickr.com/photos/the-consortium/5301698212/ ● music https://www.flickr.com/photos/jeremyhiebert/11474303315 ● code https://www.flickr.com/photos/slworking/7726767220/ ● questions http://www.flickr.com/photos/oberazzi/318947873/ ● puppy http://www.flickr.com/photos/davdunc/3706558237/ ● dojo http://www.flickr.com/photos/49715404@N00/3267627038/ PETER KOFLER, CODE-COP.ORG FANATIC ABOUT CODE QUALITY

×