in reply to A new idiom -or- I Hate Unless
Hear, hear. As a statement modifier I have no problem with unless, but I cringe when I see it used as the block form. I find it interesting to note that perlsyn doesn't even bother mentioning it, so I'm surprised that it pops up so often.
The main reason for my dislike is the puzzlement factor that a newcomer to Perl will have when encountering the statement. It's obvious to me, because I'm familiar with Perl, but I can also see that someone coming from another language could have considerable difficulty realising that unless is the opposite of if. I can imagine such a person wondering if there isn't some subtle distinction if using it instead of simply negating the if. So for me it falls into the Too Clever For Its Own Good category. Doubly so when the code becomes unless( $cond ) {...} else {...}. That's just perverse.
My own approach to avoiding block unless statements is to simply use if( not $cond ) {...}. Works for me.
My main rule is to arrange to have the if part be the shortest, and the else part the longest, so that at the beginning of the else it's easy to see the conditional that led you here. Locality is more important.
- another intruder with the mooring of the heat of the Perl
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A new idiom -or- I Hate Unless
by chromatic (Archbishop) on Aug 23, 2004 at 00:36 UTC | |
by kappa (Chaplain) on Aug 23, 2004 at 12:52 UTC | |
by demerphq (Chancellor) on Aug 24, 2004 at 16:19 UTC | |
|
Re^2: A new idiom -or- I Hate Unless
by ambrus (Abbot) on Aug 23, 2004 at 09:11 UTC | |
by BrowserUk (Patriarch) on Aug 23, 2004 at 09:23 UTC |