"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 the "Software Production Coaching You & Me", asked Francesco Cirillo how he would have developed that same kata in an evolutionary way and without applying the "IF Strategy". In this Challenge, Francesco will show his solution.
Here you can find the next sessions of this course series:
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. |
This Challenge was born out of a request from Damir, one of my best students, in the Software Production You and Me Coaching Programme.
One day Damir asks me, "I would like to see how you would develop the Bowling Kata."
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?
Ready to work together?
—Francesco Cirillo
Who is it for?
Ideal for Software Developers and Technical Coaches. Helpful for Product Developers and Business Coaches interested in understanding how to organise requirements and user stories and see how to turn them into effective working code.
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.
In the 1990s he worked as a Senior Consultant and Mentor for Sun Microsystem, expert in Software Architectures and Software Development Processes and Java and Object-Oriented Evangelist.
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.
In 2000 ha created XPLabs, the first company in Europe to offer comprehensive services on XP: software development, training and consulting.
In 2007 he created the Anti-IF Campaign to raise awareness in the international community of software developers to apply good design principles to grow software in a sustainable way.
Since 2008 Francesco stopped actively working on Agile Methods and started to develop RRP, a new method of software development.
In 2013 he created Cirillo Consulting based in Berlin to offer professional training and consulting on productivity and software development.
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.
Here you can find the next sessions of this series:
Can't make it on any of our dates?
We can discuss other options with you
The following is the report of the first session of the Accounting Adventure. The time is 31 March 2021 at...
The following is the report of the first session of the Accounting Adventure. The time is 27 April 2021 at...
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....
Time is limited. We can't have as much as we want, neither stop it nor slow it down. When our...
Interruptions and procrastination are one of the most dangerous productivity killers. How to deal with the Predator while we're working...