Page 2 of 3

Posted: Tue Aug 19, 2003 3:23 pm
by Gen-ik
I use 'standard' functions in PHP more or less all the time but it doesn't mean the code is messy or can't easily be changed. I have a collection of seperate PHP files each containing a function.. an email sorting and sending function for example.. and simply include() the functions if and when they're needed. This way only the code that is required will be included in the pages.. which helps to keep the speed up.

Posted: Tue Aug 19, 2003 7:23 pm
by lastcraft
Hi...
BDKR wrote:You now Marcus, that was a rather simple black and white response.
Sorry, I did not intend to be rude and apologies if I was :(. Consider the pace of writing enthusiasm rather than aggression...please.
BDKR wrote:I'm presently digesting the QIII engine, which is written in C FYI, and it's not tough to extend or change. Not to the point you make it out to be.
Well, I am first and foremost a C programmer so I know what you mean. Now C has functions as first class objects (albeit with pointers and the C type system) which makes it possible to do OO or functional programming to some extent. The fact that C can be bent this way does not make it the best solution, however. By comparison C++ is a hideously complicated language which makes C preferable for small projects. It becomes worth the extra expense of C++ developers when the code base gets beyond 30000 lines or so (in my experience). If you like the extra skill cost balances the the large project leverage you get from OO. I am not saying that it is impossible to write flexible systems with non-OO languages or less than fully functional languages, only that there is a cost involved in reduced flexibility. It is simply more work.
BDKR wrote:...as much as the C language will allow that is.
But bending a non-OO language into an OO one simply demonstrates the desirability of that quality. I have seen C chosen most often because of the lack of C++ experience (I do this too) or because of a lack of knowledge of more radical solutions (a domain language say) not because it is prefereable to use the simpler paradigm.

Quake 3 is a good example of this, adding it's own partly declarative language on top of the C core. By changing language the number of lines of code is kept below the number that triggers the need for strong encapsulation.
BDKR wrote:This isn't as clean as you portray it too be.
OO does take a couple of years to get a handle on, but at that point I disagree. It is very much as clean as I make it out to be. The example I quoted was a grand total of three hours work (including tea breaks). Now the example was very suited to OO (no relational database involved for example) I grant you, but I am now well into the domain where my 3 years OO is more productive here than my seven of non-OO.
BDKR wrote:You've just raised the same old battle cry that other dedicated OOP'rs out there do, and you've cried it out in the same old simplistic fashion.
Hm...I am in the OO camp for the PHP apps I do now, but I was not out to expouse OO as such. Simply I wanted to point out that rejecting OO for performance reasons was a bad choice. There are reasons for rejecting OO, mainly when encapsulation is going to cause trouble. For example if there is a large amount of configuration or you are interfacing with a system that uses it's own language or there is very little state in the system. All of these will cause development overhead if done with OO.
BDKR wrote:OO just makes it easier to attain a clean, modular, easy to maintian code base.
Which are exactly the qualities that you most need for performance tuning.
BDKR wrote:Cheers,
BDKR
Thanks for not letting me get away with it so easily! :)

yours, Marcus

Posted: Tue Aug 19, 2003 9:33 pm
by BDKR
Hm...I am in the OO camp for the PHP apps I do now, but I was not out to expouse OO as such. Simply I wanted to point out that rejecting OO for performance reasons was a bad choice. There are reasons for rejecting OO, mainly when encapsulation is going to cause trouble. For example if there is a large amount of configuration or you are interfacing with a system that uses it's own language or there is very little state in the system. All of these will cause development overhead if done with OO.
OK. I see what you're getting at. My outlook isn't so much one of 'code-smithing' (a cool term that I'll have to remember), though I've been known to tinker and try some crazy things here and there, but instead, to do what I know performs better up front. Then, when I feel the size of the project justifies incurring the performance hit, I'll go OO.

But oh well...., it's all good. I'll prolly hit you up with some questions concerning C. :wink:

Cheers,
BDKR

oop not oops :)

Posted: Fri Sep 19, 2003 10:29 am
by evilMind
OOP is the best way to go. Especially when php5 comes out ( since there will be major changes). See http://www.php.net/zend-engine-2.php for the new features. OOP takes a little more programming at first but once you get it to do what you want it runs like a well oiled machine...

Posted: Fri Sep 19, 2003 6:43 pm
by cybaf
OO or nono...:) I'm all for OO even with the extra amount of coding... seams weird maybe because a good programmer is a lazy programmer... but the time you put in building nice reusable classes will spare you a lot of time in the long run.

//cybaf

Posted: Fri Sep 19, 2003 8:21 pm
by qads
voted for functions, i have't really found a good use, but i do make a class once a while to stay in shape lol...

Posted: Fri Sep 19, 2003 10:46 pm
by jason
Writing a class and writing an Object Oriented program are two different things. Not to anyone in particular, I just want this to be clear.

The fact that you use classes in your program does NOT make your program object oriented.

Posted: Tue Mar 23, 2004 12:34 pm
by Buddha443556
I voted for functions because that's what I use with PHP. I like to write tight, fast code for my web projects. I don't feel that using classes helps me write tight, fast code.

Posted: Tue Mar 23, 2004 4:46 pm
by timvw
Using "speed" as an argument not to choose for OOP is most of the times just silly.

Posted: Tue Mar 23, 2004 9:35 pm
by Buddha443556
timvw wrote:Using "speed" as an argument not to choose for OOP is most of the times just silly.
I'll just refer you to Jason's last statement just above. :)

Posted: Wed Mar 24, 2004 4:43 am
by McGruff
Jason was talking about procedural v OOP code not speed.

Lastcraft nailed the often-stated (but mistaken) speed issue, I think.

Posted: Wed Mar 24, 2004 4:51 am
by markl999
One of my favorite posts on the whole procedural vs OOP thing...

http://www.sitepoint.com/forums/showpos ... stcount=14

Posted: Wed Mar 24, 2004 6:19 am
by Zay
I never had an idea that required classes to make it better...

I worked with classes with Delphi and Java, so know what I can use them for... I just haven't had much that required classes on PHP... but it will most likely change with my next idea that I will be working out in a few months...

Posted: Wed Mar 24, 2004 11:00 am
by JayBird
jason wrote:Writing a class and writing an Object Oriented program are two different things. Not to anyone in particular, I just want this to be clear.

The fact that you use classes in your program does NOT make your program object oriented.
Good point. I have seen code in the past using classes, just for the sake of saying they used classes. Not a valid reason.

Mark

Posted: Wed Mar 24, 2004 11:53 am
by malcolmboston
ive never used classes, but have downloaded many, which unfortunately ive never used i do think that they are bloated just by looking at the size of the script

i have started to use functions, and cant praise them enough :wink: