Refactoring: Extract a Method, When It’s Meaningful

Big Functions Hell

Well, now it’s hard to remember the moment, when I first time realized that it’s actually a good idea to extract functions from the massive chunks of useful code. Either I got this knowledge from the “Complete Code” or “Clean Code” – it’s hard to recall. Actually, it does not matter so much. We all know that we should split the business logic into well named functions. The longest function I’ve seen in my life was longer than 5k lines. I’m personally acquainted with that “programmer”. I remember when I first time faced that function. It’s not difficult to predict, that my very first reaction was – “WTF!!! Who made this piece of shit???” Yep, and that “programmer” is still hanging around in the office where I’m working on. I don’t want to get deeper into this story, but I want to mention that the 5k-lines-function was the core of the ~150k-lines program. That program was eventually driven to a corner because of that piece of shit, which tremendously influenced on the whole architecture of the application. In the end, the decision was made to rewrite that program completely from the ground.

Continue reading