Summary
In this chapter, we learned how to spot some – not all – code smells. We covered the ones that I think are the most common. Some of them you’ll pick up instinctively and avoid them as you write code. We tackled duplicated code, long methods, large classes, and repeated switches. We also learned to avoid our obsession with primitive types (using string for everything is a strong temptation!) and looked at feature envy methods. Finally, we talked about divergent change and its opposite, Shotgun Surgery. Oh, and let’s not forget about the god object. This is just a partial selection of all the existing code smells out there, but I believe it’s a good starting point to steer clear of them.
A crucial condition to perform any kind of refactoring, especially god object refactoring, is good test coverage. In the next chapter, we are going to tackle this extremely important matter.