DebtRatchet alerts you whenever technical debt increases, enabling you to systematically reduce debt in legacy codebases. It has been used in a large enterprise codebase succesfully, where it greatly increased the pace at which debt was reduced.
DebtRatchet is implemented as a diagnostic for the .NET Roslyn compiler. To use it, simply install the NuGet package into your project. DebtRachet runs when you compile, but also while you code. Note that using DebtRatchet requires VS 2015 update 3.
DebtRatchet uses some rules to determine what it considers debt. These rules are kept simple so that a programmer is never confused over why code contains debt. Also, these rules can be configured, which should be done defensively to prevent false positives. The rules used are these:
- Method has too many parameters
- Method is too long
- Type has too many fields
- Type is too long
- git-ratchet: a tool that allows you to track metrics and apply a ratchet to them.
- Quality: a debt ratchet tool for Ruby.
- git-code-debt: a dashboard for monitoring code debt in a git repository.
The screenshot below shows DebtRatchet in action. The code contains an interface with four methods. Two of these methods are fine, but DebtRatchet finds the other two methods have increased in technical debt, resulting in an error.
In the example you will see the attribute MethodHasDebt
above two methods. This indicates already existing debt, allowing us to differentiate between new and old debt.
You can see that hovering the mouse over a method with an error from DebtRatchet shows a tooltip. From the tooltip you can generate the MethodHasDebt attribute to quickly eliminate the error, in case you don't want to refactor your code at this time.
- Install the NuGet package into your solution.
- Restart Visual Studio to see that it now reports errors on methods with technical debt.
- Optionally configure DebtRachet using assembly level attributes.
- Run the tool AttributeUpdater, which is included in the NuGet package, on your solution. This records where technical debt is already present in your code, by adding the attributes
MethodHasDebt
andTypeHasDebt
. - Program away while DebtRatchet makes sure you don't increase your debt.
- Once you've reduced technical debt in your code a bit, run AttributeUpdater on your solution again. This will tighten the parameters on the debt attributes, so that you can't regress into old debt. This tightening is where DebtRatchet gets its name from.
- That's it!