The Bowling Kata Anti-IF Challenge

"Have you ever noticed how many IFs have been used in Bob Martin's Bowling Kata solution? Is this an effective solution from an evolutionary design perspective?"

In this Workshop, Francesco Cirillo will develop the Bowling Kata in an evolutionary way and without applying the "IF Strategy."

Here you can find the next session of this workshop:


About this Challenge

Francesco's Software Development Challenges are journeys in which Francesco, you and the other participants will develop one or more features of a real application. Francesco will lead the development of the feature to be created and show you how he makes software design decisions, how he applies principles and tools, why he chooses one pattern over another and why he prefers certain practices in specific contexts.

Workshop Info

Format
4 x 2-hour sessions (max 8 participants)

Length
Two weeks

Language
English

Delivery Options
Live online, onsite and in-house

Trainer
Francesco Cirillo

Who is it for
Ideal for Software Developers and Technical Coaches


The Story Behind this Challenge

Francesco Cirillo tells the story behind the Bowling Kata Anti-If Challenge.

"This Challenge was born out of a request from Damir, one of the participants in the Software Production You and Me Mentoring Programme. One day, he asked me: 'I would like to see how you would develop the Bowling Kata without IFs.'

I admit that I did not know of the Bowling Kata. This Kata is about developing an application that can calculate the score of a bowling match. Robert Martin provided a solution in 2005 to demonstrate how he applies TDD. Robert Martin's solution is considered by many as a 'procedural solution.' The result of applying the 'IF Strategy' several times to deal with new tests. I understand the reason for my client's request.

	public int score() {
		int score = 0;
		int frameIndex = 0;
		for (int frame = 0; frame < 10; frame++) {
			int frameIndex = 0;
IF=>		if (isStrike(frameIndex)) {
			score += 10 + strikeBonus(frameIndex);
			frameIndex++;
IF=>		} else if (isSpare(frameIndex)) {
      				score += 10 + spareBonus(frameIndex);
					frameIndex += 2;
IF=>		} else {
					score += sumOfBallsInFrame(frameIndex);
					frameIndex += 2;
      		}
      	}
      	return score;
      }
      

I do a bit of Googling to see alternative solutions:

  • Most of the solutions repeat Martin's steps and generate the procedural solution.
  • Several people are surprised by the absence of an abstraction that emerged through his TDD solution and propose the introduction of a Frame class.
  • Matteo Vaccari and Antonio Carpentieri in their "Open/Closed Principle Dojo" propose a number of new interesting user stories (ie 20 frames instead of 10, 3 rolls per frame instead of 2 and other interesting stories). They show the IF tangle that Martin's solution would become by implementing those stories in continuing Martin's way of doing TDD.
	public int score() {
		int score = 0;
        int currentRoll = 0;
        int numFrames = isMartian() ? 12 : (isVenusian() ? 11: 10);
		for (int frame = 0; frame < numFrames; frame++) {
IF=>		if (callistoVariant() && isLastFrame(frame) {
        		while(isStrike(currentRoll, frame)) {
                	score += 10 + sumOfTwoRolls(currentRolls+1);
                    currentRoll++;
                }
IF=>		} else {
IF=>            if(isStrike(currentRoll)) {
                	score += 10 + sumOfTwoRolls(currentRolls + 1);
                    currentRoll++;
                }
            }
IF=>		} if (isSpare(currentRoll)) {
      			score += 10 + rolls[currentRolls+1];
				currentRoll += 2;
IF=>		} else if (isMartian() {
				score += sumOfThreeRolls(currentRolls);
				currentRoll += 3;
IF=>		} else {
				score = sumOfTwoRolls(currentRolls);
				currentRoll += 2;
			}
		}
      	return score;
      }
      
	public boolean isStrike(int currentRoll, int frame) {
IF=>	if (isVenusian()) {
			return rolls[currentRoll] == frame;
		}
		return rolls[currentRoll] == 10;
	}

Note

In the comments of this Blog Post you can find the design solution that Matteo seems to suggest: an implementation of the Chain of Responsibility Design Pattern.


Objectives

What are the objectives of this Challenge?

  1. To solve the Bowling Kata:
    • Develop the initial requirements presented by Bob Martin.
    • Develop the requests proposed by Matteo Vaccari.
    • Develop some other requirements that we can't even imagine right now.
  2. To apply an evolutionary and adaptive design process:
    • In particular, since the first time this Kata was done in a TDD way, we will use TDD.
  3. Obviously we will not apply the "IF Strategy" to deal with change, complexity and growth.

As a result of this workshop, you will learn to:

  • Apply test-driven development (TDD)

  • Grow software by applying emergent design techniques.

  • Use product and process metrics to assess the effectiveness of software design.

  • Distinguish User Stories, Scenarios and Requirements and know how to apply them.

  • Replace the "IF Strategy" with more effective design strategies capable of reducing the complexity of the software system and favour its change and evolution.

The Bowling Kata: defusing the "IF Strategy"

Structure

This workshop is organized in four sessions.

SESSION 01 - Development of the Original Kata

Let's start with the analysis of the problem defined by the Kata.

  • Francesco Cirillo and the participants will read together the text of the original Kata proposed by Bob Martin.
  • The participants will be shown the User Stories, Scenarios and Requirements prepared by the trainer.
  • The participants will be asked to define by which criteria to evaluate the effectiveness of software design.
  • Francesco Cirillo will develop Bob Martin's original Kata in TDD, one scenario at a time.
  • At the end of this session, the trainer and the participants will evaluate the result achieved in terms of design. What abstractions emerged? Was the TDD effective?
SESSION 02 - Completion of the Original Kata

Bowling Kata done!

  • In this session, Francesco Cirillo will complete the development of Bob Martin's original Kata.
  • A series of slides will help participants understand the evolution of our TDD-driven design.
  • At the end of this session, the trainer and the participants will assess the design emerged one test at a time.
SESSION 03 - Development of New Requests

Embrace Change!

  • In this session, Francesco Cirillo will show the new requests defined in the Open/Closed Principle Dojo by Matteo Vaccari and Antonio Carpentieri (ie. 20 frames instead of 10, 3 rolls per frame instead of 2 etc.).
  • The participants will be asked to improve the User Stories, Scenarios and Requirements prepared by the trainer.
  • Francesco Cirillo will show how he developed some of those Stories.
  • At the end of this session, the trainer and the participants will assess the design emerged. How much did it cost to deliver those stories? Had the current system helped us?
SESSION 04 - Let's Unleash our Imagination

Let's come up with new requests!

  • Let's free our imagination and define new requests!
  • The participants and the trainer will write the related User Stories, Scenarios and Requirements.
  • Francesco Cirillo will develop some new scenarios in TDD with the help of participants.
  • In this final session, there will be some space given to understanding the various evolutionary steps achieved through emergent design. Were we able to reduce the cost of change in our Bowling Kata? Is our software design "simple"? How can we define "simple"?

Price & Conditions

The price includes:

  • Attendance to the live streamed 4-session workshop.
  • Access to the pre-recorded workshop (available for a limited time).
  • Completed source code for the Kata.

Discounts for groups of four or more are possible. Please contact us for more details.


Choose Your Workshop

Here you can find the next session of this workshop:

Can't make it on any of our dates? We can discuss other options with you. Please contact us for more details.


About the Trainer

Francesco Cirillo

Francesco Cirillo has worked at the forefront of the software industry for more than 30 years. In a career spanning startups, corporations and freelance consulting, he has mentored thousands of professionals, developers, managers and software teams.

Francesco is one of the pioneers of Agile Methods. He started working on XP and TDD in 1999. He was chosen by Kent Beck to develop the XP community in Europe and as reviewer of the second edition of the book Extreme Programming Explained.

Francesco invented the Pomodoro® Technique, a renowned time-management method used by millions of people all over the world, while being a university student looking for a way to get more done in less time.

Read the Francesco Cirillo's complete profile.


Testimonials


Useful Resources

Pomodoro® Web App

The Pomodoro® Timer Web App will be your time tutor and help you stay focused so you can get more...


FAQ

Do you have a question not listed here?

Pomodoro® Web App

The Pomodoro® Timer Web App will be your time tutor and help you stay focused so you can get more...

Pomodoro® Sheets

To help you get started, check out the official templates of the Pomodoro Technique that you can download and print....

Pomodoro® Training Programme

Interruptions and procrastination are one of the most dangerous productivity killers. How to deal with the Predator while we're working...