http://qs1969.pair.com?node_id=506371


in reply to Re^2: Parsing named parameters
in thread Parsing named parameters

But don't do the optimisation unless you need it!

What would be the penalty of performing the optimisation if you don't need it?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: Parsing named parameters
by robin (Chaplain) on Nov 07, 2005 at 15:28 UTC
    What would be the penalty of performing the optimisation if you don't need it?

    Why make something more complicated when it doesn't bring you any benefit? Some obvious disadvantages:

    1. You waste time writing more complicated code, with no benefit for your application;
    2. You make life harder for whoever has to maintain the code later (whether that’s you or someone else), again with no benefit;
    3. The optimised code, being more complicated, is more likely to have bugs;
    4. etc.

      I was enquiring after the specific case of your example code, rather than the general case. How many of those still apply?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        How many of those still apply?

        All of them, I think. I suppose you could argue that (1) doesn't apply if you're copying and pasting the code from Perl Monks, but you still have to understand the code and adapt it to your precise requirements, both of which are more difficult when the code is more complicated.

        I'm bewildered by your objection, to be honest. Do you seriously think it's a good idea to optimise code that’s already fast enough? There’s an interesting debate to be had about “premature optimisation”, but I've never heard anyone advocate needless optimisation.

        Perhaps I'm missing your point. Would you care to elaborate?