DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Migrate, Modernize and Build Java Web Apps on Azure: This live workshop will cover methods to enhance Java application development workflow.

Modern Digital Website Security: Prepare to face any form of malicious web activity and enable your sites to optimally serve your customers.

E-Commerce Development Essentials: Considering starting or working on an e-commerce business? Learn how to create a backend that scales.

Related

  • Atomic Habits and Software Engineering: Unlocking Career Success
  • Unlocking Game Development: A Review of ‘Learning C# By Developing Games With Unity'
  • Mobile DevOps Playbook
  • Five Java Books Beginners and Professionals Should Read

Trending

  • Should I Start My Job Search Now?
  • Securing REST APIs With Nest.js: A Step-by-Step Guide
  • The Top 5 Tools for Automated Front-End Testing
  • How To Get Cell Data From an Excel Spreadsheet Using APIs in Java

A different kind of kata: Harry Potter books

Giorgio Sironi user avatar by
Giorgio Sironi
·
Nov. 04, 13 · Interview
Like (0)
Save
Tweet
Share
8.1K Views

Join the DZone community and get the full member experience.

Join For Free

During a day off I stumbled upon a kata that had a simple definition: the Harry Potter books kata. It is old enough that it considers 5 as the total number of Hary Potter books instead of 7, but it has aged well.

Unlike for the bowling kata, there is nothing specific to Harry Potter in the problem. The domain is that of e-commerce and the problem consists in calculating the discount a given set of books is eligible for; for example, considering every copy has a list price of 8 pounds, how much a purchasing 2 Philosopher Stone books and 1 Chamber of Secrets would cost.

I don't want to talk much about the problem itself here to avoid spoilers for you; suffice to say that it took me 8 hours to get to a solution that I could be proud of (the first couple of which to get to a potentially shippable solution, still not being confident of it being bugs-free or of its extensibility.)

I want instead to enumerate some of the traits of the problem that make it interesting with respect to the more popular katas. Some of these traits could even invalidate the problem as a kata; still it's a challenging exercise.

Difficulty

First of all, the Harry Potter kata does not have a trivial solution. Some katas focus on learning a new technique like TDD or how to follow the Open/Closed Principle; they keep the related problem simple enough not to change two different variables of the experiment at the same time.

Still, most programmers that take the time to perform katas can see the solutions to these problems once they have read it. They can in principle write a long procedure that will solve the problem, satisfying functional requirements and probably not the non-functional ones such as maintainability or extensibility.

Following a discipline even when you see an easy solution is probably a useful skill; however I feel that too simple problems prime the head of a programmer with the first design he can think of, so that applying TDD becomes a way of putting the design into practice instead of let it emerge bit by bit while adding new specifications.

Instead, consider a problem which is just out of your reach. You can's solve it in a single shot and when you take a look at the problem you see some statements that can make you panic: "I don't know how to do that... yet". This problem is a much better simulation of real world conditions. It forces you to add assumptions to simplify the problem and follow an incremental path towards the solution instead of adding now components that you will only use later, if only to keep the cognitive load manageable.

Incrementality

The Harry Potter kata divides nicely into almost-independent test scenarios. The input and output state are simple to express and the same API used for the first test can be used without much expansion for the last ones.

For example, the first test comprehends 0 or 1 book. Intermediate ones get to 4 or 5 books some of which are duplicated copies with the same title. Large acceptance tests get to more than 20 books (there's a reason for that.)

Breaking assumptions

I can't say too much about the steps I took to solve the problem without ruining your fun.

However here are some beliefs I think are challenged by the experience:

  • One new test case does not result in wild modifications to the production code.
  • You can follow a monotonic path to the solution: you don't ever have to abandon functionality that you have already written when refactoring.
  • Code organization and documentation are really a secondary aspect as code can be self-documenting.
  • Once you have added a few corner cases you don't have to worry about the code working even if the solution is difficult to understand.
  • Worry about efficiency later. First make it work.

Conclusions

The Harry Potter kata is a nice and challenging exercise, in the category that keeps you glued to the keyboard for a long time. It's definitely more time-consuming than smaller katas, like for the application katas, so you have to allocate a sensible amount of time to solve it. However, the benefits I feel from this kind of training are different from the ones of toy problems: problem-solving is a different art than training a particular practice.

Kata (programming) Book

Opinions expressed by DZone contributors are their own.

Related

  • Atomic Habits and Software Engineering: Unlocking Career Success
  • Unlocking Game Development: A Review of ‘Learning C# By Developing Games With Unity'
  • Mobile DevOps Playbook
  • Five Java Books Beginners and Professionals Should Read

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: