Exercises and Books on RefactoringSimon asked: "Do you know and can recommend any good exercises or books on refactoring." Certainly.
- To get started, I recommend the book Refactoring by Martin Fowler. Martin published a 2nd Edition using JavaScript examples and the original edition is for Java, depending on what suits you better. Refactoring has two parts: Code smells and refactoring techniques to handle them. Both are described in Fowler's book and also on his website. Refactoring Guru is also good in explaining code smells and their matching refactorings. Go study these.
- As for exercises - there are refactoring code katas. Emily Bache has many code katas available, including Gilded Rose, where the
Readmeoften explains which specific skill the particular kata lets you practice. I maintain a small list of exercises here. Refactoring is a practical skill, which means you need to exercise it repeatedly, sometimes following the same steps. This is practice, and repetition is what makes it stick. Today, when using AI, you might skip the manual steps of refactorings at work, but you need to work the practical skill to master it. - The third pillar of fluent refactoring is using IDE shortcuts. (Or maybe refactoring workflows or skill files, who knows.) You should investigate the IDE you use most often, whether it is IntelliJ IDEA, Eclipse, Visual Studio Code, etc. Figure out which refactorings are supported - maybe install plugins - and practice refactoring using the keyboard. Refactoring becomes powerful when you know the shortcuts, because that is where speed comes from and you are no longer distracted by mechanics. I collected flashcards to learn the shortcuts and a quick search dialogue for finding shortcuts.
Using C# and NUnit
You mention using C# with NUnit. The Java refactorings in the first edition of Fowler's book transfer directly to C#. When working in C#, ReSharper or JetBrains Rider are useful, they provide more refactoring menus than vanilla Microsoft Visual Studio. NUnit is like Java's JUnit 4, any older book with Java examples will map well. There is also a special edition of the Refactoring book for Ruby. Most techniques are language agnostic.
Learning Tips
I strongly recommend starting with simple code smells, i.e. the group of Bloaters and then the Couplers. Practise basic refactorings such as Extract Method, Extract Local Variable, etc. Most IDEs support them and they build a solid foundation. Keep it small in the beginning. There is no point changing complicated code when you lack the basics. You could repeat the same exercise more times and try different approaches. You can always make exercise harder - and people take too large steps in the beginning. Instead make the exercises easier and take smaller steps.
Try to find a learning partner. Studying any material and discussing it with someone else is awesome for learning. Verbalising learned materials makes it stick. Discussing it with someone else helps you make new connections between the material. Practising refactoring in pair programming, like working during a Coderetreat, is powerful. I used to meet people in coffee shops or online and we would refactor code together.






