Dan Joseph wrote:

Hi,


        Are there any performance differences that are noticable in a
300-400 line PHP script if you overuse classes rather than straight
functions?

This is a loaded question. If you overuse classes, there will be a performance hit :). However, in a 300-400 line script, you might find the performance improve if using OO allows you to elegantly solve the problem. There is no definitive answer. It's like asking if you'll get fat from eating 1500 calories every day for a week. A bit more information is needed :)


        lol..  I guess it could be taken as one.  Re-reading it, I can see it
definitely appearing as one.  I just have a feeling that I overuse objects.
Sometimes I don't even take advantage of what they can do, and use 'em as
glorified functions.  I can atleast say it keeps me organized, but then
again, if its sloppy in the performance area, I'll probably change my ways.
So, I guess we're all right, depending on the situation, it could or hinder
performance.  As for more information right now, don't really have anything
specific I could toss out there.  I think I'll stop before I confuse
everyone further.

The rule of thumb I use for deciding whether to use OO is: is there any chance I'm going to change this later? If the functionality you need is very static, use a function or a static method (class::method()) if you need namespace protection.


Otherwise, a year down the line, you find yourself stuck with a thing that needs a small modification which will take you hours and hours and hours and probably turn your little project into spaghetti (speaking from experience).

I now follow a few rules when designing:
- every function/method must do one thing and use other functions for other things (modularity)
- design with extensibility in mind. How hard is it to extend this method to add in some other neat functionality that we didn't imagine today? (inheritance)
- all class variables should be accessed indirectly unless speed is of paramount concern (encapsulation)


The last one is likely to spark a big debate, but the reasoning is quite concrete: it is slightly slower in realtime to access variables indirectly (through methods), but the time you save in programming is intense. If you decide later to change the format of a variable, you will be forced to write a hack to maintain backwards compatibility, again leading you down the pasta road. At the very least, you will have to spend hours combing the source for every reference to the variable, and more hours debugging the ones you miss.

:)
Greg


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to