3 ms·
I'm dealing with functions thousands of lines long with switch/case and if/else statements five or six levels deep, and it really is the wrong abstraction. It's
by Cthulhu_ 6y ago
I'm dealing with functions thousands of lines long with switch/case and if/else statements five or six levels deep, and it really is the wrong abstraction. It's massive 'handle request' functions, with a switch over a 'ok what kind of request, fetch or update or restore from backup?', then a switch over 'ok what data do you want to fetch or update or restore from backup'. That kinda thing.
That's a bad example. A better example - and yes, I'm totally biased - is the main() method for the rebuild I'm working on - it's basically 'read config', 'set up logger', 'set up service x', 'set up service y', 'validate runtime dependencies like files and scripts', 'create & start http server', 'wait for shutdown signal', 'gracefully shut down http server on shutdown signal', etc. All in one place, no need to extract methods in my opinion. That said, it really is not the critical path of the application.
- ensiferum 6y agoSounds like something you can refactor into a N dimensional table with "function pointers" for handling each case.
- mangamadaiyan 6y agoThat could blow your instruction cache sky high. Depending on what you're doing, that could be something you want to avoid.
- imtringued 6y agoYou don't need function pointers. Just call the functions directly. The problem isn't the switch/if, it's the complete lack of structure.