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.
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. | [reply] [d/l] [select] |
|
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.
| [reply] [d/l] [select] |
|
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. :) | [reply] [d/l] [select] |
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.
| [reply] |
|
| [reply] [d/l] [select] |
|
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.
| [reply] |
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. :-( | [reply] |
|
|