What's your favorite Kata? 15

Posted by Brett Schuchert Tue, 30 Jun 2009 20:22:00 GMT

I’m looking to collect several katas for the OkC CoCo Dojo to make sure we have plenty of future practice sessions already in place. Ultimately I want it to be at least bi-weekly (or weekly) and self sustaining. Along those lines, I’d like to hear what are your favorite katas.

I’d prefer you mention things you’ve tried yourself. Please post links and your impressions in response to the blog. I’ll collect them here, and let me know if you’d like me to credit you with pointing me to the idea (or for the idea itself if you created it).

FWIW, after a little thinking, my favorite kata based on the number of times I’ve used it in one manner or another is Monopoly®.

Comments

Leave a response

  1. Avatar
    Philip Schwarz 1 day later:

    @Brett

    You said:

    my favorite kata based on the number of times I’ve used it in one manner or another is Monopoly®

    I followed the Monopoly hyperlink to your site and counted the number of times you say you have used this Kata (ignoring ‘some times’ and ‘a few times’), and came up with an astonishing 170+ times.

    This single figure has definitely improved my appreciation of the role that Katas can play in a professional’s work.

    Thanks for sharing the monopoly material on your site.

  2. Avatar
    Paul Holser 2 days later:

    Some suggestions:

    Given a set S of strings, decide whether a specific string t is a prefix of exactly one member of S. I found this useful in JOpt Simple, which allows abbreviations of command line switches if a switch is a unique abbreviation—so if your command line accepted -c and—cool, specifying—co would be interpreted as though you had typed—cool, whereas—c would still count as -c.

    Which reminds me: command line switch parsers might make a good kata.

    Data structures—Bloom filters, skip lists…

  3. Avatar
    Brett L. Schuchert 3 days later:
    Philip Schwarz wrote:
    This single figure has definitely improved my appreciation of the role that Katas can play in a professional’s work.

    Years ago, I was aware of the impact the Monopoly project had on my use of formal methodologies. Specifically The Fusion Method by Coleman and later the UML and UP.

    We used this problem in both language classes as well as process classes so that’s why such a large number of times for me.

    Until I wrote that page, I did not really understand how I had been using it as a Kata. That was quite of a realization for me.

    I just got off a flight from ORD -> LHR, where I worked on Monopoly again using Mockito and I found myself struggling to keep to a strict mock approach and also envision a different solution for one particular part of the problem where violating the LSP makes the problem easy to solve, but I cannot think of a “great” solution, I’m just selecting from the one that sucks the least.

    FWIW, that’s my definition of design: Select the solution that sucks the least. Somewhat modified now to include (for what I know now), with the assumption of automated test coverage…

    Glad you enjoyed it. I’m hoping to use it again in a future dojo at the OkC coco.

  4. Avatar
    Philip Schwarz 7 days later:

    @Brett

    In chapter 3 of ‘Holub on Patterns, Learning Design Patterns by Looking at Code’, Allen Holub says:

    This chapter provides an in-depth look at an implementation of John Conway’s Game of Life – probably the most widely implemented application on the planet. You’ll look at this particular program because my version applies ten distinct patterns, all jumbled together as they are in the real world. At the same time, the program isn’t so large as to be impossible to understand. ...
    ...the code in this chapter is toy code. Consequently I let myself get rather carried away with the patterns. The point of the exercise is to learn how design patterns work, however, not to write the best possible implementation of life.

    Holub has a goodies page dedicated to the game.

    It seems that quite a few people are using Life as a kata. I first came across the idea in Uncle Bob’s The Programming Dojo.

    Here is the opinion of someone at CodeRetreat:

    We have now settled on a disembowled Conway’s Game of Life Java applet, whose guts we shall test-drive, as the morning exercise. We are leaning toward being emergent about the afternoon exercise. We have two programmers (Corey and Bill) who will perform Kata/exercises for us around mid-day, and we may just as well decide to spend the afternoon elaborating one of those. Or we may go with Plan A, which is to test-drive from scratch a Ruby version of the Game of Life.
    And this chap goes as far as saying the following:
    My personal favourite is implementing the model behind Conway’s game of life.

    I had a go at coding Life a few months ago. Now I am doing it a second time using TDD: I want to see how different they turn out.

    Have you used it as a kata before?

  5. Avatar
    Philip Schwarz 7 days later:

    @Brett

    As Kirk Knoernschild says in Java Design – Objects, UML and Process:

    In The Mythical Man-Month, Frederick Brooks cites two complexities associated with software development. He categorizes them as essential complexities and accidental complexities [BROOKS95]. Essential complexities are those difficulties that are inherent in the nature of software, whereas accidental complexities are difficulties that attend the production of software but can be eliminated.
    There have been many attempts to eliminate accidental complexity. Examples of accidental complexity include a mismatch of tools or paradigms, a lack of formal methodologies or models, and awkward programming languages.

    If I do a kata with both an OO language like Java, and a functional language like Haskell, I can’t help observing that in the former, I am mostly practicing how to deal with accidental complexity, whereas in the latter I am mainly practicing how to deal with essential complexity.

    This begs the question: if I we are soon all going to be able to use functional languages in our day jobs, won’t all the skills we have acquired by doing katas in OO languages become worthless or seriously devalued?

    E.g. one of the Katas you have collected is Uncle Bob’s Bowling Game Kata.

    On the one hand, I like this Kata, and up to now it is the one I have practiced most, using Java. But some time ago I did the kata using a functional language like Haskell. If you look at the end result

    score [x, y]                             = x + y      -- Normal Frame
    score [10, x, y]                         = 10 + x + y -- Strike
    score [x, y, z]                          = 10 + z     -- Spare
    score (10:(x:(y:rest)))                  = 10 + x + y + score (x:(y:rest)) -- Strike
    score (x:(y:(z:rest)))  | (x + y) == 10  = 10 + z + score (z:rest)         -- Spare
    score (x:(y:rest))      | otherwise      = x + y + score rest              -- Normal Fram
    

    it is kind of obvious that the kata was mainly about dealing with essential complexity.

    In the Java version of the kata instead, while the end-result is relatively uncomplicated thanks to its cleanliness

    public class Game
    {
        private int currentRoll;
        private int[] rolls = new int[21];
    
        public void roll(int pins)
        {
            rolls[currentRoll++] = pins;
        }
    
        public int score()
        {
            int score = 0;
            int frameIndex = 0;
            for (int frame = 0; frame < 10; frame++)
            {
                if ( isStrike( frameIndex ) )
                {
                    score += 10 + strikeBonus(frameIndex);
                    frameIndex += 1;
                }
                else if ( isSpare( frameIndex ) )
                {
                    score += 10 + spareBonus(frameIndex);
                    frameIndex += 2;
                }
                else
                {
                    score += sumOfPinsInFrame(frameIndex);
                    frameIndex += 2;
                }
            }
            return score ;
        }
    
        private boolean isStrike(int frameIndex)
        {
            return rolls[frameIndex]==10;
        }
    
        private boolean isSpare(int frameIndex)
        {
            return (sumOfPinsInFrame(frameIndex)) == 10;
        }
    
        private int strikeBonus(int frameIndex)
        {
            return rolls[frameIndex+1] + rolls[frameIndex+2];
        }
    
        private int spareBonus(int frameIndex)
        {
            return rolls[frameIndex+2];
        }
    
        private int sumOfPinsInFrame(int frameIndex)
        {
            return rolls[frameIndex] + rolls[frameIndex+1];
        }
    }
    

    at some points in the TDD journey from first failing test to end-result, the code morphs into something quite ugly (see slides titled ‘Fourth Test’ in Uncle Bob’s Powepoint Presentation) whose complexity is accidental in that it stems from the fact that we are using an imperative language which requires us to tell the computer HOW to compute the score by manipulating state, rather than telling it WHAT to compute using side-effect free functions, like in Haskell.

    What do you think? Do you ever think that some of the refactoring we do in imperative language katas is a bit pointless?

  6. Avatar
    ??? ???? 7 days later:

    ? ? ?? ???

  7. Avatar
    Thomas Nilsson 9 days later:

    Have a look at http://www.codingdojo.org where some of us have been collection our own experiences.

  8. Avatar
    ed hardy 3 months later:

    Good post….thanks for sharing.. very useful for me i will bookmark this for my future needed. thanks for a great source.

  9. Avatar
    Mania 8 months later:

    I just love to read stuff like that

  10. Avatar
    1 9 months later:

    Right I understand what you say, I learned from you is very help me.

  11. Avatar
    FLV extractor 9 months later:

    so what ?

  12. Avatar
    han 10 months later:

    http://www.ipadvideoconverters.biz iPad Video Converter iPad Video Converter is a great software for iPad lovers to convert videos to iPad with super fast speed and high quality. Its easy-to-use interface makes iPad to videos conversion routine very simple. And also it can keep the original quality of video files.

  13. Avatar
    jingjia about 1 year later:

    MTS Converter can help you to convert mts files easily and quickly, and it is very easy to use. if you are in need, you can download it and experience by yourself.

    Main Features of MTS Converter

    • Convert AVC HD(.MTS) to all standard video formats like AVI, WMV, MPG, MOV, DVD, etc and various audio files like AAC, AC3, MP3, WAV, WMA, etc.
    • Support batch conversion, you can import more input mts files to the file playlist
    • Provide rich profiles, customize and save your profile for future use
    • Capture current pictures by click “snapshot” and save the current image to snapshot folder
    • Supports extract audio, pictures from video
    • Split one source file to several
  14. Avatar
    cheap vps about 1 year later:

    that it stems from the fact that we are using an imperative language which requires us to tell the computer HOW to compute the score by manipulating state, rather than telling it WHAT to compute using side-effect free functions, like in Haskell.

    What do you think? Do you ever think that some of the refactoring we do in imperative language katas is a bit pointless?cheap VPS

  15. Avatar
    FXG about 1 year later:

    Good post….thanks for sharing.. very useful for me i will bookmark this for my future needed.

Comments