Refactoring case studies
Refactoring entails restructuring code while preserving its initial functionality. The objective is to enhance the internal structure through incremental modifications without affecting the code’s external behavior. To check the integrity of our code, we use unit tests (see Chapter 1 of this book). Refactoring is the last step in the test-driven design process.
This section showcases a small piece of code containing bad practices. We will see how to fix these issues efficiently with the help of Visual Studio. Remember that norms and practices must be discussed with all teams and can change from one team to another.
Handling common bad practice
Here’s a code with bad naming and a condition check that can be easily simplified:
public static bool canregister(int age) { if(age > 18) { ...