Forum Moderators: coopster

Message Too Old, No Replies

Objects and Classes in PHP

Do you use them, and why or why not

         

olwen

7:41 pm on Apr 5, 2003 (gmt 0)

10+ Year Member



I'm a old school programmer. I started in COBOL when many of today's developers were only a twinkle in the father's eye. I've woven my fair share of spaghetti, and had to be dragged kicking and screaming into structured code. :o In my daytime job I write PICK basic which has no OO facilities at all.

But in my own time I use PHP, and I've looked at quite a few open source scripts, and some I inherited along with a website, and it seems to me that either all these programmers have a background like mine, or there is a reason to not use objects and classes. Or is it that like me they find it's easier just to throw together some code and maybe use an include and a function call.

Fischerlaender

8:00 pm on Apr 5, 2003 (gmt 0)

10+ Year Member



I started with Basic and machine code, so I too had no OO background 'til Sun released this Java thing in 95 ...

But I could watch a lot of younger web developers - even with a CS degree - that were producing pure spaghetti code. I think this is because most projects are started without any design strategy.

For people like me of course, who did a lot of programming with machine code ("What was that f..ing opcode for a Z80 GOSUB?" - "216" - "Oh, thank you.") when they grew up, all those classes and methods are nothing but a waste of useful bytes. ;-)

dingman

5:41 am on Apr 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've got a community system I originally wrote in procedural PHP - no classes or objects. The more I worked on it, though, the more things I was doing made me sit back and say "you know, this looks like what those OO folks would call a method". Having never done anything OO before (unless you count using 'cin' and 'cout' and therefore having to compile my program with g++ instead of gcc), it was a bit of a learning curve, but I think it really cleaned up the structure of my code. Made it easier for *me* to understand whet I did last month.

I'm sure a true OO programmer would look at my code and tell me that it's still disgustingly proceedural - my message board, for example, doesn't have a class fro message objects - but I think it did do some good. And on the rare few occasions when I've written an actual interactive, stateful program with a GUI, I've found that OO just made sense. Less so with web apps that have to operate over a stateless protocol, and even less than that if I'm dealing with a command-line program. (For that matter, less so if the language is Perl, but that's just the result of some bad experiences with trying to do OO perl.)