Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Useless unless

by chromatic (Archbishop)
on Aug 06, 2005 at 00:58 UTC ( [id://481412]=note: print w/replies, xml ) Need Help??


in reply to Useless unless

Perl should have an otherwise for use as a modifier:

That's an immensely huge syntax change, making expressions span statements.

Many people find if ! $o at least as readable as unless $o...

I can believe they think they find it as unreadable, but I think they're wrong. How can it be as readable as unless? It's two distinct units instead of one, and one of the units is symbolic. It's worse when you nestle the bang against another symbolic unit, such as an opening parenthesis.

I hate to sound like a self-proclaimed usability expert, but I do not see how this could be.

Replies are listed 'Best First'.
Re^2: Useless unless
by Tanktalus (Canon) on Aug 06, 2005 at 02:37 UTC

    /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.

      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.

      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. :)

Re^2: Useless unless
by jdporter (Paladin) on Aug 08, 2005 at 15:38 UTC
    That's an immensely huge syntax change, making expressions span statements.
    Is it? Is such a thing unprecedented in perl? At any rate, it seems entirely consistent with Perl's philosophy.
      Yes, expressions spanning statements would be unprecedented. And the 'otherwise EXPRESSION;' construct would be an syntax construct spanning statement, which also would be unprecedented. And it's omision doesn't contradict Perls philosophy - I bet Larry's first reaction would be:

      What would
      print "Hello"; otherwise print "world";
      do?
      And the smartass who would say otherwise looks at the last expression evaluated, and hence would only print "Hello", as print returns 1, I'd like to point that in such a case:
      $x = 0 if 3 > 2; print "foo" otherwise;
      will both assign 0 to $x, and print "foo" - as the assignment to $x is the last expression evaluated.
        an syntax construct spanning statement
        I'm not sure what that is supposed to mean.
        it's
        its
        Perls
        Perl's
        I bet Larry's first reaction would be
        Guessing Larry's reaction is a game some of us know better than to play.
        What would ... do?
        It would raise a compile error.
Re^2: Useless unless
by Anonymous Monk on Aug 08, 2005 at 15:01 UTC
    Most programmers are only semi-literate; they never learned English well in the first place.

    Things like word order, natural language flow, and the basic concept of structuring code like well-written prose doesn't occur to them, because they can't write prose to begin with.

    It's all just a string of wierd symbols to them: 'u','n','l','e','s','s' is more characters than 'i','f',' ','!', and thus harder to understand.

    I'm no grammarian, nor do I claim to be good at English, but I can't count the number of comments I've read that don't even start with a capital letter, let alone clearly explain the topic at hand. :-(

    It's not just foreigners, either. :-( One native speaker who I worked with wrote endless run on sentences fragments, which were often self-contradictory. He capitalized things randomly.

    When you don't know what readable prose should look like, everything looks equally readable. :-(

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://481412]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-16 04:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found