Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I would prefer the code which states, most simply and obviously, what the intent of the designer is ... and, also, which builds the maximum flexibility for the future.

In case #1, if there was a legitimate other use for @tests as an array (versus using keys(%ntests)), and if the value-initialization of %ntests should always be zero .. likely .. then I would use a simple foreach my $key (@tests) { %ntests{$key} = 0; }, written on three source-lines.   Is it “shorter?”   Clearly not.   Is it “faster?”   (Rhett Butler, Gone With The Wind)   But it is clear, to almost anyone who’s written a program in any language out there.   And it’s easily maintainable going forward:   you can put anything you need to inside that block, at any time in the future.

In case #2, the first alternative is instantly “outed.”   (Say what you mean.)   And once again I would perhaps write something like:   my $mol = ""; if ($n == 42) { $mol = "forty-two"; }   Once again, I am looking towards the future, after two years of programmers meddled with this same bit of code and it grew over all those years into something totally different.

Basically, when someone writes the first bit of code, whatever it is, they have a very clear notion in their heads at that time of what they’re trying to write at that time, and they get the idea stuck in their heads that there are brownie-points for being “clever.”   We’ve even got a “golf” section here, and it’s fun, but it’s just for fun and we all know it ... or, we should.   But, what happens over the next several years?   Well, one day, a change surely comes to pass which negates the assumptions that allowed the O.C. to have been “clever” in the first place, and that means that his entire block of code must be replaced.   First, it must be correctly understood.   Then, it must be correctly replaced with code that correctly does, not only what the new-change needs to do (which is why the current coder is dealing with this code now at all), but also everything that it did in the past.   Depending on the code, that entirely-unwanted voyage of discovery can become huge, and profoundly de-stabilizing.   A great big cost and delay, maybe, and all for nothing.   “Thanks for nothing, clever-one wherever you are now ...”

In reply to Re: Two simple code style advice questions by sundialsvc4
in thread Two simple code style advice questions by eyepopslikeamosquito

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (5)
    As of 2018-05-27 14:23 GMT
    Find Nodes?
      Voting Booth?