Untangle branch-heavy code
23 katasTurn pricing rules, eligibility trees, state machines, and calculators into smaller decisions without changing an answer.
Clean-code practice with executable limits
Inherit C# that works and that nobody wants to maintain. Refactor it without changing behavior, then prove the result against tests and Roslyn-measured quality gates across 54 focused katas.
Six free preview katas. No local setup required.
Passing tests are half the job
A green suite proves that your refactor still works. It does not prove that you removed the branch maze, split the god method, or eliminated the pasted blocks. Katabench checks both halves on every submission.
The exercise defines structural limits. Roslyn reads your submitted source and measures it directly, while hidden tests keep the original behavior pinned. Clean is no longer a matter of whether the diff feels nicer.
Read the full test-first refactoring playbook or see how structural grading works.
method length
limit 25 lines
cyclomatic complexity
limit 8
nesting depth
limit 3 levels
✓ 9 / 9 tests still passing (behavior never changed)
Four refactoring skill families
These are not syntax quizzes. Each family repeats a recognizable maintenance problem until you can see the shape quickly and choose a behavior-preserving move.
Turn pricing rules, eligibility trees, state machines, and calculators into smaller decisions without changing an answer.
Replace arrow code, flags, and nested loops with guard clauses, focused queries, and a readable happy path.
Extract responsibilities from importers, scorers, writers, and classic katas until each method has one coherent job.
Find the stable shape behind pasted validators, renderers, templates, calculators, and exporters, then give it one home.
Free C# refactoring exercises
Open any preview in the browser, inspect the already-green starter, and refactor until the behavioral and structural gates agree. No project download or SDK setup is required.
An address printer hiding at the bottom of four nested ifs.
Open this kata →Three fields, three identical validation blocks.
Open this kata →The tennis kata: love, deuce and advantage in one long method.
Open this kata →Letter grades with bonuses, written as a wall of nested ifs.
Open this kata →Untangle a copy-pasted discount calculator until every quality gate passes - without changing a single answer.
Open this kata →The canonical refactoring kata, one item per call, gated on method size.
Open this kata →The refactoring loop
01
The starter already passes its behavioral tests. Read the mess, identify the pressure point, and decide which small move will improve it.
02
Edit C# in the browser and run the visible tests as often as you need. The goal is better structure with exactly the same behavior.
03
Submit against hidden behavior tests and authored Roslyn limits for complexity, nesting, method length, and duplicate blocks.
Stuck after a serious attempt? Reveal the reference solution, compare its structure with yours, reset the exercise, and make the same moves from memory. That turns a solution into another rep instead of an answer to copy.
C# refactoring exercise FAQ
They are working C# programs with deliberately poor structure. You improve the design without changing the behavior, then use tests and structural measurements to prove both constraints still hold.
Yes. Katabench includes the canonical Gilded Rose behavior in C# and grades the result on behavioral tests, method length, cyclomatic complexity, nesting depth, and duplicated blocks.
Six refactoring katas are free previews, including Gilded Rose, Tennis Score, null-check flattening, and duplication removal. Katabench Pro unlocks all 54 exercises and unlimited submissions.
Yes. You can reveal a correct reference solution after trying an exercise, study the resulting structure, then reset the kata and solve it again. Daily reveal limits depend on your plan.
The behavioral suite checks that the program still does the same work. A Roslyn-based analyzer separately measures cyclomatic complexity, nesting depth, method length, and duplicated blocks against limits authored for that exercise.
Start with the free Gilded Rose kata and let the tests plus structural metrics tell you when the refactor is actually done.
Try Gilded Rose freeA short note when fresh kata land, plus the C# and performance tricks behind the grading. No spam, unsubscribe anytime.