I am preparing an educational course on software legacy code and refactoring. Every topic is introduced as a group discussion to establish the vocabulary. It is then followed by a matching practical coding dojo with a kata dedicated to the same topic.

The target audience is a group of software engineers who are comfortable with the principles of coding dojos, they have completed a half dozen of dojos already. They are experienced with applying TDD to katas where the objective was to write new code from scratch.

The new course is focused on working with legacy code: getting it under test, isolation of dependencies, safe refactoring etc. One of the topics I want to explore is that removal of code that is no longer useful is a valuable approach when working with legacy code.

I am looking for ideas and inspiration for designing a matching kata. I.e. I need to prepare a body of code and formulate an assignment for it. One of the feasible solutions to this assignment should involve removal a significant portion of the original code.

There are many catalogues on the web of ideas for katas and even ready-made repositories to be used as starting points. But I am yet to find one that would closely match my intention.

Most of the katas that start from a pre-existing non-empty code repository expect a student to transform it to a repository of a roughly the same size. I am looking for ideas where the resulting code is notably smaller compared to the starting point. The reasons for the initial volume could be different and combined in the same project: plain old copy-paste abuse, violation of YAGNI principle (having features that nobody asked for), various code smells that provoke code bloat etc.

I am not looking for a ready solution, but for ideas of how I could create such a "Code Deletion Kata" for my course.


3 Answers 3


One of the main causes of a need to delete code is a changed requirement. Take the Bowling Kata for example. Imagine a student has completed this assignment. Now tell them, they need to create a version where spares are not a thing. That will lead to deleting code.

If you really want to throw them in the deep end of maintenance coding make them make this change in another students Bowling Kata. Obviously you will need to have reviewed this code so you understand just how much pain you're asking the student to endure but remember, this pain is what you're trying to teach them.

If the student that authored the code first is in the class this also offers a chance for a peer code review. But for the first year you'll likely find you have more students than useable Bowling Kata code. It's OK to pick a few good ones to share among the many.


The most common form of code re-factoring that involves code reduction in the absence of changed requirements is the replacement of common code sections by functions or methods. Secondly code can also be reduced by the use of exceptions and thirdly code can be reduced by better data structuring.

As a Kata is about repetition of small increments of learning, it would be best to do this in several distinct Kata. I imagine the following set of Kata might be instructive:

  • Replacement of repeated sequences of identical code by functions (or macros) that involve no arguments
  • Replacement of repeated sequences of identical code by functions (or macros) that require parameterisation
  • The use of exceptions, break and return to reduce long control structures
  • Replacement of several basic type variables by structured compound types

One could go further and start introducing the power of generics but at this stage start with sme basics.

  • $\begingroup$ Can you explain how exceptions reduce code (my experience is the opposite)? What language?, what type of exception (there are several)? $\endgroup$ Jul 15 at 21:05

As well as delete it because it is not used. I think generalisation, is a big reason to delete code.


  • functions and procedures, replacing sequences
  • parametrised functions and procedures, replacing non parametrised
  • function/procedure passing (lambdas), to provide strategies, to replace special purpose versions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.