Re: mini-quiz

Ron Isaacson <Ron.Isaacson-/PgpppG8B+R7qynMiXIxWgC/[email protected]> Mon, 18 Jun 2007 23:04:01 -0400
Newsgroups gmane.comp.lang.perl.qotw.discuss
Message-ID <[email protected]>
Joshua Kronengold wrote:
> 
> Yitzchak Scott-Thoennes writes:
> >    my $country = $card->country;
> >    $country = $country eq 'gbr' ? '' : uc "[$country]" if $country;
> 
> I personally don't like tail ifs, but that's (mostly) a personal
> prejudice.
> 
> I also don't much like testing string usefulness by truth (what if
> country is "0"?)

Agreed! But...

> my $country = map +(/^(?:|gbr)$/ ? '' : uc),$card->country;

> $country &&= $country eq 'gbr' ? '' : uc "[$country]";

Egad! You call those better?

I usually try to avoid these philosophical-type discussions, but I
have to say that constructs like the above contribute to perl's bad
reputation as a write-only language. How did people start coming up
with the idea that shorter code is better?

There is no shame in writing a C-style 3-line 'if' block. I often
teach perl courses, and advise people to consider the skill level that
would be required of a READER to understand each line of code they've
written. If it's more than beginner-to-intermediate, then rewrite to
make it simpler. In practice, the person who maintains this code and
will be called on to make minor changes in the future is likely to be
much less fluent in the language than the person who first wrote it. 
IMHO, optimizing for ease of maintenance is much more valuable than
optimizing for number of lines, operations, or pretty much anything
else.

I'm reminded of those trite "evolution of a programmer" sequences; for
perl, I'd think in most cases the Expert level would be a hideously
complex one-liner, and the Zen Master would be exactly the same as
Beginner.

--
Ron Isaacson
Morgan Stanley
ron.isaacson-/PgpppG8B+R7qynMiXIxWgC/[email protected] / (212) 762-1950