The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

If you have a gripe with nested if-then-else statements in any language, then usually it’s time to refactor some code…

Posted by jpluimers on 2019/12/10

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:

  1. the code blocks into separate methods
  2. 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: [WayBackAnybody 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

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.