Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^2: Two simple code style advice questions (tye)

by BrowserUk (Pope)
on Jan 18, 2013 at 05:23 UTC ( #1013953=note: print w/ replies, xml ) Need Help??

in reply to Re: Two simple code style advice questions (tye)
in thread Two simple code style advice questions

I find it significantly easier and faster to parse the intent.

Could you quantify (in some fashion) what you mean by "significantly easier and faster"?

my $mol = ( $n == 42 ) ? 'forty two' : '';

I find your version quite horrible to parse.

  • Is that one statement or three?

    Oh! It's two!

  • And why is it (are they) all squished up like that?

    It looks like the the code-wrap routine has been given some ridiculously narrow width limit.

  • Why is he comparing a literal against a variable?

    Is the literal's value likely to suddenly change?

    (Yes. I am aware of the justifiction for the backward logic. :)

As for your last example, I find it almost incredulous that you would code that; and almost impossible to parse without reformatting it.

Why not just:


I also find the concentration on the minutia of single statements far less important than the overall flow of the code.

That is, when scanning the code, I only need to recognise that $mol has been initialised, and then the next step and the next. I'll only be concerned with what it was initialised to once I understand the overall flow; and if I suspect that might be the source of the problem I'm looking for, or otherwise needs closer inspection.

I don't need to know all the details of each line (or 3 lines!) of code from an instantaneous glance. If I have to read the line twice to understand what it does -- maybe take 2 seconds instead of 1/2 a second -- it is no biggy in the scheme of things. But understanding the overall flow of the subroutine or block is far more important, and that -- for me at least -- means being able to see as much of that subroutine or block as -- clearly defined steps -- as possible. Which is why I infinitely prefer the one line versions to your 3 or 5 line examples.

In the absence of evidence, opinion is indistinguishable from prejudice.

Comment on Re^2: Two simple code style advice questions (tye)
Select or Download Code
by tye (Cardinal) on Jan 18, 2013 at 17:25 UTC






















    Your mileage may vary, obviously.






    - tye        

      Geez! And people call me contrary! But each to their own :)

      Which neatly segways to my theme of the month: Imposing opinions in the name of best practices or automated critique, is fundamentally flawed.

      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013953]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-12-27 12:57 GMT
Find Nodes?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?

    Results (177 votes), past polls