in reply to Method calls expensive??

Why do you want to write faster code? Is this just a general want, or is it an issue directly affecting what you need to accomplish? Efficiency is nice, but so is clarity. Personally, if I have the luxury, I will always sacrifice speed for well designed, clear code.

Personally, I wouldn't try to put more in one method. The more things a particular method does, the more likely it is for things to go wrong and for you to have maintenance issues. For example, if you have a method that establishes your database connection, you may think "ah, they're starting a session, so I'll just pack all of my other session initialization code in the db->connect method". All that is well and good, until the day that you need to establish the database connection without starting a session. Then what do you do? Rewrite your code base? Create another connection method and thus have duplicate code which needs to be synchronized? Keep the methods simple, and you'll be happier in the long run.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: (Ovid) Re: Method calls expensive??
by Pin (Novice) on May 05, 2001 at 02:08 UTC
    I agree with Ovid. Design your code well first. You'll probably save more time in maintenance programming than you give up in run-time.

    If you need to optimize later, find what small percentage of the code does the program spend a large percentage of it's time in. Then optimize that. You'll get the most bang for the proverbial buck.

Re: (Ovid) Re: Method calls expensive??
by chorg (Monk) on May 05, 2001 at 02:06 UTC
    Thanks for the replys all! What I am trying to do in general is work out some techniques that will make my coding style more efficient on the first pass, without sacrificing the readability and flexibility of OOP. I am writing code that has to deal with more traffic and more load than I used to, and adding more memory, or more processors is not an option for me in this environment - ie: It might get done, but not when I ask. So I'd like to keep these issues in mind when I am coding, so that I don't have to come back to optomize as much , if I have to, or use C ++ or something like that.
    _______________________________________________
    "Intelligence is a tool used achieve goals, however goals are not always chosen wisely..."