Join Jesse Freeman for an in-depth discussion in this video Use version control, part of C# Refactoring Tips and Tricks.
- [Instructor] Whenever it comes to refactoring, I can't stress this enough, make sure you use version control. Before you attempt to do any kind of refactoring on your own code, make sure that it's backed up and under version control. Now, when creating C# projects, there's usually two forms of version control you'll find, either Team Foundation Server or Git. I prefer Git because it's what I've used on my own projects, and it's what I've used for years now. Some of the advantages of using version control are that you're able to track the change history.
You're also able to compare changes, which is especially important if you think you've messed up and you need to go back and see what you did previously from the baseline in order to fix the current problem. You're able to merge changes, which is critical when other people are working on the same codebase and you're performing a refactor that could affect their versions. So being able to take their versions and your version and merge it together and find the conflicts is instrumental in making sure that you don't create new issues.
And finally, being able to track author contributions in order to see what has been committed by who in order to roll back changes in case there's a break. When you're working in a large team, it's important to figure out who's in charge of merging. At best, one person should be in charge of merging changes into the baseline. This person is also in charge of verifying the test before creating a new baseline. While this is a lot of work to put on one person's shoulders, it's critical that one person is in charge of making sure that the codebase is always stable.
This should be the person who's most familiar with the architecture and has the most experience with version control in general in order to fix any conflicts. The baseline should always be the stable build of the codebase and is usually the master branch or trunk of the project. All refactoring should be done in separate branches. This helps keep everything clean. And when someone is new to the project, they're able to check out the master branch and compile it without getting any errors or partially completed work that's being done on a refactor or adding a new feature.
- Creating a baseline
- Removing unused code
- Refactoring in branches
- Using refactoring tools
- Optimizing code
- Creating clean code