"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:
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.
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
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:
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. |
What are the objectives of this Challenge?
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.
This workshop is organized in four sessions.
Let's start with the analysis of the problem defined by the Kata.
Bowling Kata done!
Embrace Change!
Let's come up with new requests!
The price includes:
Discounts for groups of four or more are possible. Please contact us for more details.
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.
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.
The Pomodoro® Timer Web App will be your time tutor and help you stay focused so you can get more...
Do you have a question not listed here?
The Pomodoro® Timer Web App will be your time tutor and help you stay focused so you can get more...
To help you get started, check out the official templates of the Pomodoro Technique that you can download and print....
Interruptions and procrastination are one of the most dangerous productivity killers. How to deal with the Predator while we're working...