Monday, March 21, 2011

Introducing the Code Kata project

One of the common themes that people talk about when it comes to craftsmanship is practice.  Dave Thomas made the corollary for programmers a few years ago in this blog post.  He brings up great points about not worry about the answer but instead focusing on how you got to the answer that you implemented.  It also emphasizes repetition meaning you should practice a kata frequently.

I love the idea of the kata but I found I had a few ideas that could make the process more effective and prove to have wider adoption not only in the ruby community but all programming languages.  The ideas I had could be summarized as follows:


  • Authoring - I wanted a consistent way to write a kata that would clearly illustrate the requirements through details and examples.
  • Administering - How do you take a kata?  I wanted a way to step through the requirements and measure progress by how many requirements I completed and how much time it took to complete them.
  • Setup - I wanted to be able to chart my progress over time by using source control to keep track of the code for each time I took that kata in an automated fashion.

The result of these ideas is the kata gem.  Check the github page for all of the details but briefly it provides the following:

  • An RSpec like DSL for authoring katas using descriptive keywords like requirement, detail and example.
  • A command like tool to self-administer a kata by stepping through the requirements
  • The ability to automatically create a distinct github repo for the kata you wish to take allowing for later code review.
Now that we have tools in place to make us more productive in writing and taking katas we just need katas to test ourselves with.  I have created the code katas project so that everyone has the opportunity to contribute and take advantage of the efforts put forth. 

If you just want to take a kata that is part of the project it is very easy to get started if you are used to using rvm and bundler.  Just clone the repo:

wesbailey@feynman:~/tmp> git clone git@github.com:wbailey/code_katas.git
Cloning into code_katas...
remote: Counting objects: 25, done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 25 (delta 11), reused 0 (delta 0)
Receiving objects: 100% (25/25), done.
Resolving deltas: 100% (11/11), done.
view raw code_kata.rb hosted with ❤ by GitHub
change into the cloned repo:

wesbailey@feynman:~/tmp> cd code_katas/
...
Do you wish to trust this .rvmrc from now on?
============================================================
(y for yes, n for no) > y
Using /Users/wesbailey/.rvm/gems/ruby-1.9.2-p180 with gemset code_katas
view raw chdir.sh hosted with ❤ by GitHub

Install your bundle:

wesbailey@feynman:~/tmp/code_katas> bundle install
Using ZenTest (4.4.2)
...
Using bundler (1.0.10)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
view raw bundle.sh hosted with ❤ by GitHub

Now you can setup your github repo to take your kata:

wesbailey@feynman:~/tmp/code_katas> kata setup calculator.rb
Creating github repo...complete
creating files for repo and initializing...done
You can now change directories to calculator-2011-03-21-005535 and take your kata
view raw setup.sh hosted with ❤ by GitHub

At this point you can cd into the created directory and view the repo in your github account. You can commit to it but should ignore it in the code_kata project.  All the goodies like autotest and kata are installed so you can follow TDD best practices without any work on your part.

In a separate terminal window you can then administer the kata to guide you through the requirements for the code you need to write:

wesbailey@feynman:~/tmp/code_katas> kata take calculator.rb
Calculator Kata
Create a calculator that is initialized with a string expression
- detail: The expression is of the form digits separated by commas: "1,2"
- detail: The expression is accessed by a method named expr
- detail: The expression can be reset for evaluation at any time without re-initializing
- example: Calculator.new "1,2"
completed (Y|n):
view raw kata.sh hosted with ❤ by GitHub

You are off and running to practice regularly!

What the project needs though are obviously more katas.  String calculators are great and thanks to Roy and Katacasts for inspiration but more can be done.  Translation and updating of the original katas from Dave Thomas would probably be a good start but what ideas do you all have?  For the code kata project and submit your ideas for everyone to grow and get better!

2 comments:

  1. I learned about the kata gem from your talk at SCRC. I wrote about it (http://code-worrier.com/blog/kata/) and about something I learned from the calculator kata (http://code-worrier.com/blog/passing-symbols/).

    Thanks!

    ReplyDelete
  2. I think it's fantastic that there is a tool available like this gem to help make practicing code kata easier.

    ReplyDelete