Where Can I Find Small, Messy Codebases to Practice Refactoring?
Asked by
MellowOrbit42
I'm looking for realistic codebases to use as refactoring practice. I've already worked through several coding exercises, including the Golden Rose and Tennis katas, but I'd like to tackle something closer to an actual project with imperfect structure and design. Ideally, the codebase would be somewhere between 1,000 and 5,000 lines of code. Are there any open-source projects or other good sources for this kind of practice?
Answers
Open-source projects are probably your best bet. Look for smaller repositories that are active enough to have documentation and tests, but not so polished that every design decision has already been cleaned up. Before changing anything, get the project running, read the existing tests, and make small improvements one at a time so you can verify that behavior hasnโt changed.
Reply to this answer
Another effective approach is to build a small personal project, leave it alone for a few weeks, and then return to it. The code will probably feel unfamiliar, which makes its confusing structure and design problems much easier to notice. You can then refactor it with the perspective of someone maintaining code written by somebody else.
Reply to this answer
You donโt necessarily need a specially prepared โspaghettiโ project. Pick any small codebase that fits the size range and inspect it for duplication, overly large functions, unclear names, tight coupling, and missing tests. Real projects are often messier than kata exercises, and learning to decide what not to refactor is part of the practice too.
Reply to this answer
You can also deliberately generate a small application from vague requirements, or find an unfinished beginner project, and then treat it like legacy code. The important part is to establish expected behavior firstโthrough tests, examples, or manual checksโbefore restructuring anything.
Reply to this answer
Add your answer
Answers are reviewed before publication.
PixelHarbor18: A thousand lines may not be enough to become truly tangled, but even a smaller project can have awkward dependencies and poor separation of responsibilities. Adding tests before refactoring will make the exercise much more useful.