Why are people always trying to accomplish things "all in one statement" or "all in one regular expression"? Usually when I see these questions it gives me the impression that the asker can think of a way to do it, but it would take two statements/expressions (and that would just be too many!). And often times it's on IRC where by the time they've asked the question and gotten an answer (which probably consists of "why don't you just use two statements?"), they could have already coded something that would have worked but not taken only one statement/expression.

Is this an instance of premature optimization? Do they believe in the false economy that "less text" equates to "more efficient code"? Or perhaps as delirium's meditation seems to imply, they think that "less text" equates to "more elegant code"? Granted, there are some instances where it would make the code read better if there were a way to get some complex functionality into one expression, but you know what? We already have a way to do that; they're called subroutines. I think people need to realize that clarity trumps cleverness always (okay, except when your goal is cleverness like with golf or obfuscations)

Or is that it right there? Perl has a reputation of being clever, so users always want to do something clever in their code.

Where do you guys think this pervasive meme comes from? And are current methods of education stemming the tide of ignorance?


In reply to All in one by duff

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.