OO purists in php vs. functional purists in php

UGH...

I have a theory - anyone who wants to become a GOOD php programmer that comes from a purely procedural/functional background must spend three months or one largest project coding entirely in OO, a purely OO system.

On the other hand, anyone who comes from a purely OO background must spend three months or one large project coding entirely in procedural/functional code, with no classes/objects ANYWHERE.

Then they both must throw the entire project/codebase away and vow never to do it again.

Why you ask? People seem to forget that the biggest strength of php is it's simplicity, and also it's biggest handicap. Php is a hybrid language. It's object oriented, it's procedural, it can be embedded in web pages, it can be used for cli scripts, it's like a huge swiss army knife. Now a swiss army knife is a great thing until you attempt to use the huge frikin butcher knife portion to cut a loose thread off your shirt, or the tiny little scissors to hack the skin off your latest rabbit for stew.

The point is, php works best when you KISS (keep it simple stupid) and use the right tool for the job - if you have a large project that will need the ability to override behavior with outside modules - a purely functional/procedural approach is gonna leave you with a huge mess (hear that wordpress?), on the converse end writing a contact me script/mail form in OO with eight classes each ten lines long is INSANITY.

Let's find some common ground people - use classes judiciously, use functions and procedural code judiciously, and for heavens sake, comment the damn code. In php, if your class consists of two methods and one property, you probably need to rethink your design. No matter how hard you argue, an object containing two objects as properties is always going to be "heavier" than a multidimensional array. There's just more data present. On the other hand, encapsulating all your user's data in a user class for a large portal system will save you about three million headaches when you decide to change from ldap to straight sql or a flat file.

If code is poetry it needs to be a highly structured sonnet not a loose soliloquy, it should be a thought provoking haiku, not a ten thousand line epic. Cram as much as possible, as structured as possible, into as little space/memory use as possible.

And all purists must die.

Comments

Be the first to write a comment!

Post a Reply