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

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Deploying and Validating Kata Containers
  • Kata Containers: From Kubernetes Pods to Secure VMs
  • Top 5 Books to Enhance Your Software Design Skills in 2025
  • Top 5 Software Architecture Books to Transform Your Career in 2025

Trending

  • Beyond the Checklist: A Security Architect's Guide to Comprehensive Assessments
  • Tracing Stratoshark’s Roots: From Packet Capture to System Call Analysis
  • The Death of REST? Why gRPC and GraphQL Are Taking Over
  • Jakarta EE 11 and the Road Ahead With Jakarta EE 12

A different kind of kata: Harry Potter books

By 
Giorgio Sironi user avatar
Giorgio Sironi
·
Nov. 04, 13 · Interview
Likes (0)
Comment
Save
Tweet
Share
8.8K 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

  • Deploying and Validating Kata Containers
  • Kata Containers: From Kubernetes Pods to Secure VMs
  • Top 5 Books to Enhance Your Software Design Skills in 2025
  • Top 5 Software Architecture Books to Transform Your Career in 2025

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • 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
  • [email protected]

Let's be friends: