Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: Coding style

by nyamned (Sexton)
on Jul 13, 2010 at 11:18 UTC ( #849234=note: print w/replies, xml ) Need Help??

in reply to Re: Coding style
in thread Coding style

But is it reasonable to add extra lines of "useless" code to such small subroutine, just to make it more readable?

Replies are listed 'Best First'.
Re^3: Coding style
by BioLion (Curate) on Jul 13, 2010 at 11:41 UTC

    IMHO, it certainly is - maintainability is an important part of good coding, and readable, well commented, well laid out code is a big part of that.

    In 6 months time could you (or someone else) look at the first example and quickly see what was going on? Or if you get an error, quickly see where it was coming from?

    Just my 2 cents.

    Just a something something...
Re^3: Coding style
by ruzam (Curate) on Jul 13, 2010 at 14:14 UTC

    When I need to speed up code I go looking for nested hash references as in your example. It's my believe the cost of creating a new variable is small(er) compared to the cost of looking up the value of a nested reference. If the same value is referenced more than once, it's worth creating a variable to skip as much dereferencing as you can.

    The fact that it's more readable is just a bonus.

      Wow, I was surprised to discover this. It is really faster with temporary variable.
      Thanks everyone for sharing your thoughts.
Re^3: Coding style
by Argel (Prior) on Jul 13, 2010 at 20:42 UTC
    Unless it causes a [significant ] performance hit you should always go with the more readable version. It's depressing that you even had to ask a question with such an obvious answer!

    Elda Taluta; Sarks Sark; Ark Arks

      Well, I was not sure about it - I'm new to Catalyst. First variant could be catalyst-way or something. So I decided to ask you guys.
        If you follow the thread you will see that I was specifically responding to this comment:
        But is it reasonable to add extra lines of "useless" code to such small subroutine, just to make it more readable?
        What does that question have to do with Catalyst? It's a pretty generic best practices type question, so I stand by my original comment.

        Regardless, what makes Catalyst so special anyway? Basic principles in writing maintainable code still apply.

        Elda Taluta; Sarks Sark; Ark Arks

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://849234]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2018-03-17 18:48 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (225 votes). Check out past polls.