imagine if the entire function is a single if-else statement which they kept adding onto, but could never refactor lest everything crashes down and burn.
Saw one once called something dangerously innocent like “run_validation” that turned out to be a 5K line hand built deserializer (no libraries used when then absolutely should have) with so many nested levels the editor put “expand this line?(2kb)” warnings at the end of most lines.
In the original author’s defence the garbage being deserialized was an Eldritch horror. We eventually moved to JSON.
I once worked on a project doing firmware that a lot of people have likely used (printer firmware for a big-name company). One of the more trafficked functions was something like 1500 lines of “if-elseif-elseif…” with something like 13 or 14 different cases.
It did end up getting refactored to something polymorphic and based on a configuration file to cut out any unnecessary steps, but it was like that for a while before I got there, and was like that for most of the year that I was part of the project.
To be fair, I think massive “switchboards” can be relatively clean. The key is that each step contains little enough logic. 1500 lines of 13-14 cases means the average block was > 100 lines, and at that point I definitely agree that it should probably have been refactored a long time ago. Just splitting that into 13-14 smaller functions, and using the switchboard as a delegator could be completely fine.
imagine if the entire function is a single if-else statement which they kept adding onto, but could never refactor lest everything crashes down and burn.
You’re dredging up some bad memories 😅
Saw one once called something dangerously innocent like “run_validation” that turned out to be a 5K line hand built deserializer (no libraries used when then absolutely should have) with so many nested levels the editor put “expand this line?(2kb)” warnings at the end of most lines.
In the original author’s defence the garbage being deserialized was an Eldritch horror. We eventually moved to JSON.
I once worked on a project doing firmware that a lot of people have likely used (printer firmware for a big-name company). One of the more trafficked functions was something like 1500 lines of “if-elseif-elseif…” with something like 13 or 14 different cases.
It did end up getting refactored to something polymorphic and based on a configuration file to cut out any unnecessary steps, but it was like that for a while before I got there, and was like that for most of the year that I was part of the project.
To be fair, I think massive “switchboards” can be relatively clean. The key is that each step contains little enough logic. 1500 lines of 13-14 cases means the average block was > 100 lines, and at that point I definitely agree that it should probably have been refactored a long time ago. Just splitting that into 13-14 smaller functions, and using the switchboard as a delegator could be completely fine.
4k+ nested if statements with comments.