http://qs321.pair.com?node_id=401088


in reply to Re^3: if variants
in thread if variants

I can understand avoiding the != in an if statement, since using unless covers that functionality. I don't know why unless . . . else would be "bad", however. Explain?

- apotheon
CopyWrite Chad Perrin

Replies are listed 'Best First'.
Re^5: if variants
by DrHyde (Prior) on Oct 22, 2004 at 09:22 UTC
    In English, saying "if this, do that, else do the other" makes sense and is easy for a person to parse. However "unless this, do that, else do the other" is much harder to parse because the "else" clause is a double negative (or even a triple negative if you have "unless not this"). Same applies to perl.

    While you could, perhaps, argue that "if not this, do that, else do the other" is also a double negative, it's still easy to parse because it's familiar. We see it in every programming language ever.

      In short, then, it's a readability issue. Got it. Thanks.

      I think my facility for formal and symbolic logic systems probably makes it more difficult for me than for most people to recognize when some complex representation of a logical expression is difficult to parse by eye.

      - apotheon
      CopyWrite Chad Perrin