Anti-IF Bowling Kata

Defusing the "IF Strategy"

A 4-day course by Francesco Cirillo // 10 May 2024

Register 10:00am Register 07:00pm Upcoming Events

Starts on

May 10, 2024
at 10:00 am EU/AS/ME or 07:00 pm EU/AM

(May 10,11,17,18)

Duration

4 interactive days
2 hours of hands-on coding per day

Where

Streamed live, right into your favorite IDE

Course Fee

$225

For your team

Ignite team synergy! Enroll collectively to foster a unified coding approach.
Request Info

The Bowling Kata: Develop One Object at a Time, One Pattern at a Time

Introduction

"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?"

Damir, a participant of our Programming with Francesco Mentoring Programme asked Francesco Cirillo how he would have developed that same kata in TDD and with no bad IFs.

The Bowling Kata Challenge is a Course in which Francesco Cirillo, develops one or more features of an application that can calculate the score of a bowling match. Francesco demonstrates how he makes software design decisions, applies TDD, emergent design principles, his choices of one pattern over another, and his preferences of certain practices.

The Bowling Kata Challenge is a Course in which Francesco Cirillo, develops one or more features of the Bowling Kata: an application that can calculate the score of a bowling match. Francesco demonstrates how he makes software design decisions, applies TDD, emergent design principles, his choices of one pattern over another, and his preferences of certain practices.

Benefits

TDD

Apply Test-Driven Development

Emergent Design

Grow software by applying Emergent Design Techniques.

Software Metrics

Use Product and Process Metrics to assess the effectiveness of software design.

Business Analysis

Apply User Stories, Scenarios and Requirements.

Anti-IF Practices

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 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 Programming with Francesco 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 Damir'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;
	}

TRAINER

...

Francesco Cirillo

Francesco’s journey in software spans over 30 years, influencing startups, corporates, and individual consultants.

A seasoned mentor, he has impacted countless professionals and teams. From his early days with Sun Microsystems to pioneering Agile Methods and creating XPLabs, Francesco's mark on the software industry is profound.

Notably, he's the creator of the groundbreaking Pomodoro Technique, a time management method embraced worldwide, as well as the visionary behind the Anti-IF Programming philosophy, challenging conventional coding practices.

Testimonials

Nicole Lemke

"If you not only want to know what “Object-Oriented Programming” means, but are also interested in its origins and what it can achieve, start here, at the very beginning. Let Francesco take you on a journey. Learn about the essence of good objects and write good stories that those objects can tell."

The Bowling Kata: defusing the "IF Strategy"

Upcoming Events

Faq

Originated by Francesco Cirillo in 2007, the Anti-IF Programming approach has transformed how many perceive IFs and conditionals in software design. At the heart of software design lies a simple yet potentially dangerous tool: the conditional 'IF' statement. Undeniably foundational, its use to handle changes in a growth context, dubbed the "IF Strategy", can be a silent saboteur, complicating code and tangling logic. The IF Strategy can lead to debugging problems, never-delivered user stories, technical debt, entangled design, frictions in the team and other inefficiencies. In essence, the IF Strategy can escalate costs and delay software delivery times while degrading internal quality.

Questions