Aside from unit testing, the importance of refactoring and the correct way of doing it is one of the most valuable things you can learn early in your career as a software developer. If you want to properly refactor your or other people’s code, you’ll have to learn all you can about best coding practices, and you’ll have to be able to pick up on anti-patterns that need to be broken down, rearranged, and cleaned up.
Ironically, doing a proper refactoring of a codebase requires years of experience, which you probably don’t have yet. So why am I bothering to talk about it? Because you can’t get experience doing proper code refactors if you don’t know what a proper code refactor involves. You need to understand what to look for and what you should do when you find something that needs to be reworked.
It’s that simple. This chapter won’t make you an expert on the subject, but it’ll give you a glimpse of what you have yet to learn. I’ll cover the basics—everything you need to understand about refactoring, and the tools that senior developers use when they read and refactor code. The rest will come once you start doing it over and over.