Every time I run into complex nested if/then/else statement in any language with truckloads of code blocks, it usually means it is time to refactor in two steps:
- the code blocks into separate methods
- the decisions and methods into a polymorphic structure
Of course this adds some overhead, but usually you end up with code that is easier to unit-test and understand both the overall structure and detailed implementations of.
I’m all for language enhancements that allow deeply nested logic to be more manageable (for instance by enhancing a case construct), but usually refactoring makes that less of a need and more of a nice to have.
Via: [WayBack] Anybody else have a gripe with nested if-then-else statements in Pascal? What if we had the following statement/syntax available in Pascal? … – Gerhard Venter – Google+
–jeroen
Like this:
Like Loading...