Baseball TDD Kata

Watch it Live on Twitch.TV TDDAcademy (coming in November 2020)


If you google "baseball kata" you are more likely to find search results pointing to this player - Matt Kata. Here in The Swift Dojo a Kata is a practice session, not a second-base man. Yet - maybe we can use or reuse the name.

The Kata Intent:

Practice Test-Driven Development while creating a Model for use in an App (perhaps - a future project). The model of a baseball game and the score keeping techniques required. Up front I want to distinguish between score keeping on a baseball scorecard and counting the runs and outs as seen on a score board.

Step One:

Don't start coding... start talking about the problem domain. See if you and your partner or team agree upon what the problem domain is - where it is heading - what tools & techniques you will start with - to resolve the problem.

Step Two:

A simple brain-storm of the Baseball Object Model. A ball game happens at a place and time - this is a good candidate for a core object - Game. We will talk more about what type of object a bit later, perhaps. Other objects... a Team (really two teams). A set of Players within those teams. A set of Bases (First-Base, Second-Base, Third-Base, Home-Plate). A ball and a bat, players gloves, etc. The Field is an interesting object to model... in the real world there are fields with various dimensions and features. If there is a game - there is typically a rule book and a way to keep score. That process of keeping score is largely what we will model as the behaviour of the system.

Step Three:

Why model baseball? As it turns out the game is quite complex - just try to read one of the rule books. Our purpose here is more to learn some of the techniques of TDD as well as exercise our brains with the Swift language and toolkits. So at first we just want to model the basics of the game - not the physics of the ball and hits or throws. So that constrains our thinking and frees up some fears that this is a huge endevor... no, let's first just focus on the basic object model of the game and the actions and events that are very typical in a pick-up game on the local ball-park.

Step Four:

Where might this project go and how detailed do we wish to be in our modeling and our program? I (David) would like to see a program that could do a proper job of filling out a traditional scorekeeper's record for the game. This is much more that the score of the game (Example: 7 to 3 bottom of the 7th inning). A proper scorekeeping record is used to record all events in the game, and one can learn to read the keeper's record and get a very good understanding of the occurances in the game. For example look at the 3-up & 3-down pattern in this 1880 perfect game.

Step Five:

Let's first get a basic game and object model worked out by focusing the TDD upon the simplier process of what a Score Board would need. Ignoring the classic Scorecard issues for now.

References:

Watch it Live on Twitch.TV TDDAcademy

The Pragmatic Programmer - Wikipedia

Test Driven Development by Example - Kent Beck at Amazon

Baseball Scorekeeping - detailed records of all events in a game. - Wikipedia

A Perfect Game - 1880 Scorecard - Lee Richmond

The Baseball Scorecard - Examples

Matt Kata - Texas Ranger


A perfect game - from 1880

Scorecard for first ever MLB perfect game, by Lee Richmond, 1880. Abbreviations: A, B, C, for first, second and third, P and H for pitcher and catcher, S for shortstop, L, M, and R for left, center, and right field