Suddenly, goats
True story:
Decked out with hiking boots and rain gear, I bounded up the forest trail... Ear-buds blaring a bouncy beat...
Ducking thorny branches, leaping over slippery rocks, I rounded a curve to find...
A giant herd of goats.
I did not expect that.
As I learned later, the park authority had "rented" this herd to clear (i.e., eat away) excess plant growth, on this part of the forested mountain. And eat they did. I stood there for a while, watching them devour leaves, grass, vines... Gorging non-stop, barely pausing to breathe...
Fascinating to watch.
This reminds me of cleaning up a large, overgrown Python code base.
I actually did this last week. Some noteworthy points:
Cutting Out Code
Reading through the code base, I found whole functions and methods that weren't even being used.
With a code base that's evolved and edited repeatedly over time, this happens more often than you think.
So in many cases, I was able to cut out huge chunks of code entirely.
Unit Tests Were Essential
I had a thorough set of unit tests for the application, especially on the more critical code paths.
This was a great asset: anytime I removed a chunk of code, and it broke something, my tests immediately told me to put it back in.
Simplifying Logic
The most common situation was reading some block of code, and realizing it was doing things it didn't need to do. Or doing them in an overly complex way.
While I'm sure that's sometimes because I coded it that way to begin with...
Other times, I bet it was because that complex logic was necessary at first. And then, as the code evolved, and requirements shape-shifted, the need for that complexity disappeared.
So like any healthy, hungry, growing goat, I grazed and cleared that superfluous complexity away.
(Again, unit tests were my safety net when I did this.)
So let's all learn from these magnificent goats.
How can you clear out overgrowth in your code today?