Okay, I know it's fun to be a perl hacker and all, but is that one line of code really so much easier/faster/cooler than:

my $country = $card->country; if ($country eq 'gbr') { $country = ''; } else { $country = uc "[$country]"; }

Now someone will probably fuss that there's some border case where this expanded logic doesn't behave like the cryptic line. (Heck, I'm not even sure they do the same thing in the normal case!) They're probably right.

And that's all the more reason to spell it out. If someone (including the original author) needs to modify that code a year later (or even a week later), are they going to remember all the subtle influences of precedence and truthness that made it so slick the first time around?

So, I guess my answer to the original question is pretty much, "Yes, the code is doing too much on one line." Although it really isn't how much it's doing, just the fact that it's so non-obvious what it intends to do and what it actually does. Can anyone here (other than Ovid) be sure that the code does what the author intended it to do?

There's no point in writing code that makes 96% of perl programmers think really hard, if not pull out a reference or run tests, to figure out exactly what it does in all cases.

53% of all statistics are made up on the spot.

Okay, I'll go back to being a stick-in-the-mud (e.g. employed) perl hack now. ;-)

-dave


In reply to Re: How Much Is Too Much (on one line of code)? by perlplexed
in thread How Much Is Too Much (on one line of code)? by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.