Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: A new idiom -or- I Hate Unlessby grinder (Bishop) |
on Aug 22, 2004 at 22:36 UTC ( [id://384989]=note: print w/replies, xml ) | Need Help?? |
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
In Section
Meditations
|
|