Re: [PHP] classes v. functions
> Hi, > > am Wednesday 23 July 2003 11:48 schrieb Joel Rees: > > > (You know that $accesses->count and $accesses->resetCounter() are at > > least declared in the same class declaration. $accesses_count and > > accesses_resetCounter() could be declared in entirely unrelated include > > files for entirely different purposes.) > > That is the only benefit. But it's not OOP. If you need namespaces and can't > take care of them w/o misuse of a semi-OOP construct youre not any more > efficient with it. misuse? (I leaned sideways and cross my eyes, then I stood on my head, but that still makes no sense.) > >> Is there any performance benefit one way or the other? > > > > Programmer performance? > > > >> I used EZ_Sql which is cool but didn't seem to speed things up in > >> comparison to the said include file. > >> Still don't see the beef. > > > > Execution speed isn't all that matters. In fact, speed is not the point > > at all. > > Then you must be an PHPNuke or Typo3-programmer, beeing lucky to get at > least 1 request per second ;). Oh, yeah, gotta watch those bees. > Don't take it hard, but If you had ever been in computer-science > [school|college|...] you would know that speed is all that matters. Sure. ROFDDCI -- Joel Rees, programmer, Kansai Systems Group Altech Corporation (Alpsgiken), Osaka, Japan http://www.alpsgiken.co.jp Rate that troll, maybe a 4/10? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] classes v. functions
Hi, MM> troll. :) MM> Execution speed is most definitely /not/ all that matters, though it MM> really depends on the situation. It is often cheaper to throw MM> CPU/storage/RAM at a problem than it is to spend more developer time, MM> especially when one of the considerations is future maintenance or MM> upgrades. In regards to education, OOP-techniques and other lisp-isms MM> evolved in academic settings, in response to concerns about code MM> portability, maintenance, and elegance. Academic code frequently MM> sacrifices speed in the service of technique. I have just done a test to see how much is lost with using classes by changing a template class I use back to functions and globals. Over 10 iterations of a template file with 100 blocks the average speedup per iteration was 1.8ms on a total of 19ms (the class version) So the gains made by using a class structure far outway any loss of speed in my opinion. -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] classes v. functions
>> Execution speed isn't all that matters. In fact, speed is not the point >> at all. > >Then you must be an PHPNuke or Typo3-programmer, beeing lucky to get at >least 1 request per second ;). Don't take it hard, but If you had ever >been in computer-science [school|college|...] you would know that speed >is all that matters. troll. :) Execution speed is most definitely /not/ all that matters, though it really depends on the situation. It is often cheaper to throw CPU/storage/RAM at a problem than it is to spend more developer time, especially when one of the considerations is future maintenance or upgrades. In regards to education, OOP-techniques and other lisp-isms evolved in academic settings, in response to concerns about code portability, maintenance, and elegance. Academic code frequently sacrifices speed in the service of technique. - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] classes v. functions
Hi, am Wednesday 23 July 2003 11:48 schrieb Joel Rees: > (You know that $accesses->count and $accesses->resetCounter() are at > least declared in the same class declaration. $accesses_count and > accesses_resetCounter() could be declared in entirely unrelated include > files for entirely different purposes.) That is the only benefit. But it's not OOP. If you need namespaces and can't take care of them w/o misuse of a semi-OOP construct youre not any more efficient with it. >> Is there any performance benefit one way or the other? > > Programmer performance? > >> I used EZ_Sql which is cool but didn't seem to speed things up in >> comparison to the said include file. >> Still don't see the beef. > > Execution speed isn't all that matters. In fact, speed is not the point > at all. Then you must be an PHPNuke or Typo3-programmer, beeing lucky to get at least 1 request per second ;). Don't take it hard, but If you had ever been in computer-science [school|college|...] you would know that speed is all that matters. bg Sam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] classes v. functions
> Say I have a database class with all kinds of functions for connection, > data manipulation, errors, etc: > > $db = new db_sql; > $db->connect(); > $db->do_this(); > $db->do_that(); > > How would that be different from an include file with a bunch of functions > doing the same thing? As far as I'm concerned, the primary benefit of classes is that you don't clutter up your namespace. If you have, for instance, $accesses->count, you know more about that count than if you have just $count. It's a method of organizing your code that doesn't (once you get used to it) get in the way. Also, you can be really sure that $accesses->resetCounter() is somehow related to $accesses->count, whereas $accesses_count and accesses_resetCounter() might win your confidence incorrectly. Or maybe you slip and use access_resetCounter() instead, which might be the cause of no end of grief. (You know that $accesses->count and $accesses->resetCounter() are at least declared in the same class declaration. $accesses_count and accesses_resetCounter() could be declared in entirely unrelated include files for entirely different purposes.) > Is there any performance benefit one way or the other? Programmer performance? > I used EZ_Sql which is cool but didn't seem to speed things up in > comparison to the said include file. > Still don't see the beef. Execution speed isn't all that matters. In fact, speed is not the point at all. > Brad recommended I spend even more time with google looking for OOP, maybe > that's why I'm so confused:). I think he's trying to point you to the mind-set. Do you like complex puzzles with intricate interactions where you have to keep tens of thousands of lines of code constantly in your head? Or do you like to focus on several hundred lines at a time, get those to behave, then move on to another part with a fairly high level of confidence that you won't shoot yourself in the foot by using the wrong count or resetCount() somewhere? -- Joel Rees, programmer, Kansai Systems Group Altech Corporation (Alpsgiken), Osaka, Japan http://www.alpsgiken.co.jp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] classes v. functions
Whether it's the right move or not, I've put off my learning of PHP classes and OOP methods until PHP5.x, so I guess the time in near :) However, *especially* if you're the only programmer on a project, you can take the ideas & benefits behind OOP (for me, having clear, clean code that can be reused over and over again with minimal changes is my primary goal) and apply it to your own code. It takes strict naming conventions and some careful planning, but I don't see that as a limitation at all -- more like a benefit :) Justin On Saturday, July 19, 2003, at 07:08 AM, Andu wrote: This may show my ignorance or my refusal to take for granted something I don't fully understand but I have a hard time figuring out the advantage of using classes as opposed to just functions. I am certainly new to php and at first sight classes seemed to cut a lot of corners but so do functions (with which I have more experience). The more I read about classes the deeper the confusion. Anyone can enlighten me? Regards, Andu Novac -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- [This E-mail scanned for viruses] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] classes v. functions
Thanks to all for your input. Regards, Andu Novac -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] classes v. functions
Hi, Saturday, July 19, 2003, 7:08:55 AM, you wrote: A> This may show my ignorance or my refusal to take for granted something I A> don't fully understand but I have a hard time figuring out the advantage of A> using classes as opposed to just functions. I am certainly new to php and A> at first sight classes seemed to cut a lot of corners but so do functions A> (with which I have more experience). The more I read about classes the A> deeper the confusion. Anyone can enlighten me? A> Regards, Andu Novac Classes are good in that they group functions and variables into a re usable block. Trying to do everything by just loading functions will eventually lead to naming and include hell once you start doing complex things. PHP might not be an oo language but it sure helps me keep things togeher. I tend to make classes that do a function like authentication, I just need to include authClass.inc and fire it up and all my auth work is done. i know I can create other functions as they won't clash with the ones in the auth class. Another great thing with classes is you don't have to make common variables global all the time. If you haven't used any other type of OOP then you won't have any problems trying to make PHP look like java, you can just grab the benifits with whats available :-) -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] classes v. functions
Andu <[EMAIL PROTECTED]> wrote: > > > --On Friday, July 18, 2003 14:28:02 -0700 Chris Shiflett <[EMAIL PROTECTED]> > wrote: > > >--- Andu <[EMAIL PROTECTED]> wrote: > >>This may show my ignorance or my refusal to take for granted > >>something I don't fully understand but I have a hard time > >>figuring out the advantage of using classes as opposed to just > >>functions. > > > >They are entirely different. While OO fans will find my > >over-simplification disgusting, a class is basically a way to associate > >data with the functions that manipulate that data. > > Say I have a database class with all kinds of functions for connection, > data manipulation, errors, etc: > > $db = new db_sql; > $db->connect(); > $db->do_this(); > $db->do_that(); > > How would that be different from an include file with a bunch of functions > doing the same thing? > Is there any performance benefit one way or the other? classes are slower than functions. Remember php was not and is not (will not be?) designed for OO programming. its designed for web programming. now tools like a class::$db may be slower (like anyone will notice a difference cept in high crunch situations) it makes a lot easier for fexibilty. ie.. changing database servers down the line.. Curt -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] classes v. functions
On Fri, 2003-07-18 at 18:19, Andu wrote: > > Say I have a database class with all kinds of functions for connection, > data manipulation, errors, etc: > > $db = new db_sql; > $db->connect(); > $db->do_this(); > $db->do_that(); > > How would that be different from an include file with a bunch of functions > doing the same thing? > Is there any performance benefit one way or the other? > I used EZ_Sql which is cool but didn't seem to speed things up in > comparison to the said include file. > Still don't see the beef. > Using your above example, the above would keep all of the internal data that keeps track of the resource ID (for the connection), the current result set, and the current row, etc. within the object instance scope. Thus everytime you invoke a method on the object it works with it's own set of data. In all honesty you can do this with functions also, but then you would have something like the following: $dbId = db_connect(); $data = db_do_this( $dbId ); $moreData = db_do_that( $dbId, $data ) As you can see this quickly can become cumbersome becaus eof the lack of encapsulation. However, the OOP paradigm goes even further. Lets imagine you now want log all use of your functions (methods :). To do this in OOP you just extend the class and override the methods while still allowing invocation of the inheritted methods. Thus your usage of your new object code would look something like follows: $db = new custom_db_sql; $db->connect(); $db->do_this(); $db->do_that(); Whereas the function code would resemble the following: $dbId = custom_db_connect(); $data = custom_db_do_this( $dbId ); $moreData = custom_db_do_that( $dbId, $data ) As you can see updating the function based code required more work. It wasn't as modular since it couldn't take advantage of inheritance. This is a trivial example btw, it's not perfect since there are books and books written on this topic and I'm obviously glossing over a lot of details. Once you get into design patterns you'll also see other advantages of using objects versus functions. I hope this helps a teeny weeny bit. Cheers, Rob. -- .-. | Worlds of Carnage - http://www.wocmud.org | :-: | Come visit a world of myth and legend where | | fantastical creatures come to life and the | | stuff of nightmares grasp for your soul.| `-' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] classes v. functions
--On Friday, July 18, 2003 14:28:02 -0700 Chris Shiflett <[EMAIL PROTECTED]> wrote: --- Andu <[EMAIL PROTECTED]> wrote: This may show my ignorance or my refusal to take for granted something I don't fully understand but I have a hard time figuring out the advantage of using classes as opposed to just functions. They are entirely different. While OO fans will find my over-simplification disgusting, a class is basically a way to associate data with the functions that manipulate that data. Say I have a database class with all kinds of functions for connection, data manipulation, errors, etc: $db = new db_sql; $db->connect(); $db->do_this(); $db->do_that(); How would that be different from an include file with a bunch of functions doing the same thing? Is there any performance benefit one way or the other? I used EZ_Sql which is cool but didn't seem to speed things up in comparison to the said include file. Still don't see the beef. Brad recommended I spend even more time with google looking for OOP, maybe that's why I'm so confused:). Chris Regards, Andu Novac -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] classes v. functions
Chris Shiflett wrote: > --- Andu <[EMAIL PROTECTED]> wrote: > > This may show my ignorance or my refusal to take for granted > > something I don't fully understand but I have a hard time > > figuring out the advantage of using classes as opposed to just > > functions. > > They are entirely different. While OO fans will find my over-simplification > disgusting, a class is basically a way to associate data with the functions > that manipulate that data. > > Chris > AKA 'encapsulation' Of course you can achieve this by making a programmer imposed requirement saying that global variable X can only be altered by function Xf(), or Typedef X can only be altered by functions Xf(), but OO make this more of a hard requirement, and not the programmer imposed or 'soft' requirement. Of course there are other ideas like polymorphism and inheritance and such. Just google for Object oriented programming, and read some of the numerous exposes on the subject to get a general idea. http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=object+oriented+programming -Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] classes v. functions
--- Andu <[EMAIL PROTECTED]> wrote: > This may show my ignorance or my refusal to take for granted > something I don't fully understand but I have a hard time > figuring out the advantage of using classes as opposed to just > functions. They are entirely different. While OO fans will find my over-simplification disgusting, a class is basically a way to associate data with the functions that manipulate that data. Chris = Become a better Web developer with the HTTP Developer's Handbook http://httphandbook.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] classes v. functions
This may show my ignorance or my refusal to take for granted something I don't fully understand but I have a hard time figuring out the advantage of using classes as opposed to just functions. I am certainly new to php and at first sight classes seemed to cut a lot of corners but so do functions (with which I have more experience). The more I read about classes the deeper the confusion. Anyone can enlighten me? Regards, Andu Novac -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php