in reply to Re: Useless unless
in thread Useless unless

/me waits for tye to rebut this ;-)

Anyway, I agree on both the spanning statements and the usability of unless. To me, unless is way better than "if not $foo". However, anything more complex is often easier to write and read as an if:

... unless $foo and not $bar->baz()
Switch that around to if, and it's easier to parse, I think.
... if not $foo or $bar->baz()
Still not easy, but I think that's an improvement of at least half a step.

Back to the otherwise statement. Here's just something to throw out there, more to provoke thought than as a serious suggestion. Rather than separating two statements, what would you think of:

$a if $b, otherwise $c;
Arguably, it's a single statement still. I think I still prefer the full if ($b) { $a } else { $c } version. But at least it deals with the "span statements" issue. Somewhat.

Replies are listed 'Best First'.
Re^3: Useless unless
by chromatic (Archbishop) on Aug 06, 2005 at 05:22 UTC

    The problem with not and unless is double-negation, which is complex. I only use unless in postfix statement form, and I never use it if there's a not.

    The problem with a negation and multiple conditionals is the same as in English -- ambiguity of the distributiveness of the negation. That's a case where parenthesizing helps.

Re^3: Useless unless
by friedo (Prior) on Aug 06, 2005 at 04:10 UTC
    I still don't think I quite get this otherwise groove. Would

    $a if $b, otherwise $c;

    Be equivalent to

    $b ? $a : $c;

    ?

    If so, I guess that's kinda cool, if a little confusing. We already have differently-binding text equivalents for the usual symbolic logical operators, why not the good ol' ternary conditional?

    FWIW, I use unless instead of if ! all the time. In fact, I am routinely dissapointed by the fact that we don't have a built-in elsunless. :)