Re: [PHP] Re: classes v. functions
* Thus wrote Simon Fredriksson ([EMAIL PROTECTED]): [...] just got confused. Then, suddenly I got some class for something, checked out the code and my brain just snapped. aaah, THAT's how it's done!. It wasn't well documented, just nicely structured and easy to read and understand. I need a good brain snap sometimes, too :) Curt. -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: classes v. functions
--On Sunday, July 20, 2003 07:53:20 +0200 Simon Fredriksson [EMAIL PROTECTED] wrote: I've been working like that for about two years and just recently I got enlighted in the use of classes. The main reason I started this thread is that since I'm just beginning with php I thought I might as well start with a good methodology. I've seen on the net whole collections of classes some going as far as almost inventing a new language but having some experience I know everything comes at a price. Classes seem to provide advantages to plain functions but only sometimes, striking the right balance I guess, is what I'm after. One shouldn't apply industrial theories to just everything. Regards, Andu Novac -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: classes v. functions
On Sun, 2003-07-20 at 02:28, Andu wrote: One shouldn't apply industrial theories to just everything. Object Oriented Design is not an industrial theory. It's a tried and true practice with over a decade of computer science and practical use behind it. Procedural programming is a subset of Object oriented programming. Someday you'll need the higher level features OOD offers, but until then it probably just won't make sense unless you actually go and learn the principles from a good book or teacher. Trying to formulate an opinion about OOD from the PHP mailing list is like trying to form an opinion about nuclear physics from your buddy that watched some show on nuclear power plants (maybe not that extreme, but hopefully you get the point). 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
[PHP] Re: classes v. functions
Hi, am Friday 18 July 2003 23:08 schrieb Andu: 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? Im programming for a few years now in PHP. After trying to use classes i dont see their point either. In most cases if i need a class-like structure i do something like this: function thing_new() { return ++$GLOBALS['thing_resource']; } function thing_put($stuff, $res=NULL) { if (is_null($res)) $res = $GLOBALS['thing_resource']; $GLOBALS['thing_stuff'][$res] = $stuff; } function thing_get($stuff, $res=NULL) { if (is_null($res)) $res = $GLOBALS['thing_resource']; return $GLOBALS['thing_stuff'][$res]; } Because there is no constraint to be more OO like in Java it doesnt makes sense. And this way you are more flexible. bg Sam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: classes v. functions
I am sure someone will call this heresy, but if you really want OO don't do it in PHP. If you are new to OO and start with PHP you will do yourself a grat disfavour. OO programming in PHP is still not ready. If you try and program in OO in PHP you have to learn all of it's shortcomings and many "tricks" to get around them. And I promise that more than once you will scratch your head and wonder why your object seems to have lost it's state or some variable never seems to get set properly. Jean-Christian Imbeault -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: classes v. functions
Hi, I myself never really create classes to use in my projects, if I ever use classes its only because they come from someone else (eg phpclasses.org), I find using the non OO approach much easier to understand. Just my 2 cents. Cheers, -Ryan - Original Message - From: Sam Baum [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, July 19, 2003 11:59 AM Subject: [PHP] Re: classes v. functions Hi, am Friday 18 July 2003 23:08 schrieb Andu: 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? Im programming for a few years now in PHP. After trying to use classes i dont see their point either. In most cases if i need a class-like structure i do something like this: function thing_new() { return ++$GLOBALS['thing_resource']; } function thing_put($stuff, $res=NULL) { if (is_null($res)) $res = $GLOBALS['thing_resource']; $GLOBALS['thing_stuff'][$res] = $stuff; } function thing_get($stuff, $res=NULL) { if (is_null($res)) $res = $GLOBALS['thing_resource']; return $GLOBALS['thing_stuff'][$res]; } Because there is no constraint to be more OO like in Java it doesnt makes sense. And this way you are more flexible. bg Sam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: classes v. functions
Sam Baum [EMAIL PROTECTED] wrote: Hi, am Friday 18 July 2003 23:08 schrieb Andu: 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? Im programming for a few years now in PHP. After trying to use classes i dont see their point either. In most cases if i need a class-like structure i do something like this: function thing_new() { return ++$GLOBALS['thing_resource']; } The biggest thing classes do is resolve name space issues, even with this method you have namespace issues with your function name and your variables. This rather effects a lot of people who create libraries to share with. A big downfall with classes, however is there speed. Benchmarking a function call vs. a class-method call, results in a significant difference and even more if your using a lot of classes. In general, I only use small and nicely bundled classes that don't have to do a lot of work, ie authentication, session. Because there is no constraint to be more OO like in Java it doesnt makes sense. And this way you are more flexible. And besides php wasn't designed/developed to be an OO language. Curt. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: classes v. functions
Hi there, am Saturday 19 July 2003 16:30 schrieb Curt Zirzow: Sam Baum [EMAIL PROTECTED] wrote: Hi, am Friday 18 July 2003 23:08 schrieb Andu: 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? Im programming for a few years now in PHP. After trying to use classes i dont see their point either. In most cases if i need a class-like structure i do something like this: function thing_new() { return ++$GLOBALS['thing_resource']; } The biggest thing classes do is resolve name space issues, even with this method you have namespace issues with your function name and your variables. Sure i have to add and take care of the namespaces myself, but thats it and the amount mental work compared to designing a class is imho lesser in my way. And most times only 1 object of a class gets instanciated, which is to much overhead in an application. And then u dont even need my construct. And if you dont create an object and call the function in an static way (via ::), then the whole benefit of the associated data is gone anyway and the only thing you have is the namespace. So i dont give the Parser the challenge of preparing a class representation and keep it simple. And at last: no more copied objects. A big downfall with classes, however is there speed. Benchmarking a function call vs. a class-method call, results in a significant difference and even more if your using a lot of classes. Ok i just assumed that, but good to know for sure. Sam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: classes v. functions
I'm quite new to OOP myself, but these two articles helped my understanding a lot See the sidebar - Classes and Object Oriented Programming http://webreference.com/perl/xhoo/php1/5.html Taking PHP the OO way http://phpmag.net/itr/online_artikel/psecom,id,284,nodeid,114.html olinux --- Sam Baum [EMAIL PROTECTED] wrote: Hi, am Friday 18 July 2003 23:08 schrieb Andu: 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? Im programming for a few years now in PHP. After trying to use classes i dont see their point either. In most cases if i need a class-like structure i do something like this: function thing_new() { return ++$GLOBALS['thing_resource']; } function thing_put($stuff, $res=NULL) { if (is_null($res)) $res = $GLOBALS['thing_resource']; $GLOBALS['thing_stuff'][$res] = $stuff; } function thing_get($stuff, $res=NULL) { if (is_null($res)) $res = $GLOBALS['thing_resource']; return $GLOBALS['thing_stuff'][$res]; } Because there is no constraint to be more OO like in Java it doesnt makes sense. And this way you are more flexible. bg Sam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: classes v. functions
I've been working like that for about two years and just recently I got enlighted in the use of classes. I've built a few sites and after a while on each of them I run into a problem. Say I wanna add a meta-refresh tag or send a cookie; with my earlier code, that brought out hell... more or less. Sure I solved it, but it never felt like it was the best thing to do. Since I first used a class, I've tried to figure out how they work. I got them running but I had no idea what I did, I just used the examples provided. I read through some tutorial and the docs at php.net, but I just got confused. Then, suddenly I got some class for something, checked out the code and my brain just snapped. aaah, THAT's how it's done!. It wasn't well documented, just nicely structured and easy to read and understand. You'll get it one day. Until then - do what you feel is the best thing for you to use and understand. This might not have helped you at all, it's just my story. //Simon Ryan A wrote: Hi, I myself never really create classes to use in my projects, if I ever use classes its only because they come from someone else (eg phpclasses.org), I find using the non OO approach much easier to understand. Just my 2 cents. Cheers, -Ryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php