Defusing the "IF Strategy"
A 4-day course by Francesco Cirillo // 10 May 2024
4 interactive days
2 hours of hands-on coding per day
Streamed live, right into your favorite IDE
$225
Ignite team synergy! Enroll collectively to foster a unified coding approach.
Request Info
"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.
Apply Test-Driven Development
Grow software by applying Emergent Design Techniques.
Use Product and Process Metrics to assess the effectiveness of software design.
Apply User Stories, Scenarios and Requirements.
Replace the "IF Strategy" with more effective design strategies capable of reducing the complexity of the software system and favour its change and evolution.
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:
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; }
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.
"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."