in reply to Better solution for code reduction?

Block1 if $condition1 and $condition2 Block2 if !$condition2

update:
This solution is neat but, sadly, wrong! See 5mi11er below.

Replies are listed 'Best First'.
Re^2: Better solution for code reduction?
by 5mi11er (Deacon) on Mar 10, 2005 at 20:01 UTC
    I'd stared at this option a long time, and finally had to write out the truth table to fully see that this is not the same as the conditions originally put forth.

    Original code truth table: wfsp's code truth table: Condition1 Condition2 Execute Condition1 Condition +2 Execute ---------- ---------- ----------- ---------- --------- +- ----------- True True Block1 True True + Block1 True False Block2 True False + Block2 False True Block2 False True + none False False Block2 False False + Block2
    Also, since Block2 seems, in this generic example, to be the more important block of code, the unless form of the statement helps point that out (as I'd used in my original reply above)...

    -Scott

      5mi11er++

      I'd stared at this option a long time...

      So did I - but not long enough!

      Thanks for straightening it out.

      John

      And even if the second line was fixed so the truth tables would match, it's still wrong. The problem is that if the first set of conditions is true, Block1 will be run, before the second set of conditions is tested. However, running block1 may well change the true/false value of the second set of conditions.

      So it could not be the "generic solution" the OP was looking for.