Answers.Body: <p>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.</p>
  <p>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:</p>
  <ul>
  <li>Replacement of repeated sequences of identical code by functions (or macros) that involve no arguments</li>
  <li>Replacement of repeated sequences of identical code by functions (or macros) that require parameterisation</li>
  <li>The use of exceptions, break and return to reduce long control structures</li>
  <li>Replacement of several basic type variables by structured compound types</li>
  </ul>
  <p>One could go further and start introducing the power of generics but at this stage start with sme basics.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-15T21:05:32.663Z
Answers.Text: Can you explain how exceptions reduce code (my experience is the opposite)? What language?, what type of exception (there are several)?
Answers.UserDisplayName: ctrl-alt-delor
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-13T11:14:28.943Z
Answers.LastActivityDate: 2023-07-13T11:14:28.943Z
Answers.UserDisplayName: Brian Tompsett - 汤莱恩
Answers.Body: <p>One of the main causes of a need to delete code is a changed requirement. Take the <a href="https://codingdojo.org/kata/Bowling/" rel="nofollow noreferrer">Bowling Kata</a> 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.</p>
  <p>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.</p>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-11T16:03:19.243Z
Answers.LastActivityDate: 2023-07-11T16:13:31.717Z
Answers.LastEditDate: 2023-07-11T16:13:31.717Z
Answers.UserDisplayName: candied_orange
Answers.Body: <p>As well as delete it because it is not used.
  I think <strong>generalisation</strong>, is a big reason to delete code.</p>
  <p>e.g.</p>
  <ul>
  <li>functions and procedures, replacing sequences</li>
  <li>parametrised functions and procedures, replacing non parametrised</li>
  <li>function/procedure passing (lambdas), to provide strategies, to replace special purpose versions.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-15T21:02:15.780Z
Answers.LastActivityDate: 2023-07-15T21:02:15.780Z
Answers.UserDisplayName: ctrl-alt-delor
Body: <p>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.</p>
  <p>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.</p>
  <p>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.</p>
  <p>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.</p>
  <p>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.</p>
  <p>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.</p>
  <p>I am not looking for a ready solution, but for ideas of how I could create such a &quot;Code Deletion Kata&quot; for my course.</p>
  
Tags: <programming>
Title: Designing of code kata focused on _deleting_ code as a primary goal
ThreadText: # Designing of code kata focused on _deleting_ code as a primary goal
  
  (Asked by: username_0 on 2023-07-11)
  
  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.
  
  **Tags:** programming
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2023-07-13. Score: 3
  
  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.
  
  > **Comments:**
  > **username_2**: Can you explain how exceptions reduce code (my experience is the opposite)? What language?, what type of exception (there are several)?  
  
  ---
  
  ### Answer by username_3 on 2023-07-11. Score: 3
  
  One of the main causes of a need to delete code is a changed requirement. Take the [Bowling Kata](https://codingdojo.org/kata/Bowling/) 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.
  
  
  ---
  
  ### Answer by username_2 on 2023-07-15. Score: 0
  
  As well as delete it because it is not used.
  I think **generalisation**, is a big reason to delete code.
  
  e.g.
  
  * functions and procedures, replacing sequences
  * parametrised functions and procedures, replacing non parametrised
  * function/procedure passing (lambdas), to provide strategies, to replace special purpose versions.
  
  
  ---
  
  