Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Code Efficiency: Trial and Error?

by oakbox (Chaplain)
on Oct 11, 2002 at 20:57 UTC ( #204662=note: print w/replies, xml ) Need Help??

in reply to Code Efficiency: Trial and Error?

I find that I stick to a few simple constructs: foreach over for or while, if-else in brackets over the ?: notation, etc. I write code faster when I'm using tools that I am very familiar with and only jump to other coding styles when there is a real need for optimization.

The main criteria is consistency. If you are consistent in your style, you can go back to your own code and immediately grok what's going on. Consistency also helps other people reading you code.

The question wasn't 'correct vs. bad' coding. If you are consistently writing bad code, then you need to change :) But if the choice is between 'good' and 'also good' consistency wins.


Replies are listed 'Best First'.
Re: Re: Code Efficiency: Trial and Error?
by Sihal (Pilgrim) on Oct 11, 2002 at 21:09 UTC
    Well... I often ask myself the same question. I often do things in a very readable way, that works well, no bugs etc... And then my boss will come, hack the code, make it two times shorter, and result in a faster more efficient way. Often not as readable though.
    I also often wonder when building regexes if Im using the fastest way. It would be nice to have examples of two regexes doing the same thing but one faster than the other, and explain why it is faster, so that we can understand how to write more efficient code.
      you might want to check Mastering Regular Expressions by Jeff E.F.Friedl for a deep coverage of regular expressions, with a whole chapter dedicated to perl's regexes.

      btw, that book review is for the first edition, so you might want to know there is a second edition published in july 2002.

      hope this helps,

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2020-03-30 11:09 GMT
Find Nodes?
    Voting Booth?
    To "Disagree to disagree" means to:

    Results (175 votes). Check out past polls.