Ree wrote:The fact is, that most sophisticated projects are always coded using OOP paradigm.
Thats not really a fact. Of course, it all depends on your definition of sophisticated. I would however say that any project deployed on hundreds of sites, or in widespread use and development for years is fairly sophisticated.
In reality, the vast majority of sophisticated projects (by that definition) in php today arent purely OOP. On freshmeat, the top three most vital and most popular php projects (excluding PHP itself) are: PHPMyAdmin (procedural), PHPBugTracker (procedural), The Gallery (procedural), SquirrelMail (procedural), and EZPublish (Mixed). Lets not forget phpbb, powering this forum and dozens of others.
Its much the same in the corporate world, where you are generally tasked with migrating legacy apps that were written in procedural long ago.
So to answer your question about why you would spend time coding in procedural, its because its the most common coding style for the vast majority of projects out there. However, no one in this thread suggested coding in pure procedural - just the opposite. All of us encourage some level of OOP, just varying degrees.
Ree wrote:Use OOP from the start, it works in all kinds of projects while strict prcedural does not.
Please cite some examples where procedural can't work. Unless the definition of the project requirement is "OOP only", procedural can "work" in all kinds of projects too.
Ree wrote:And I've noticed that very often in more serious job offers they include OOP knowledge as a must.
Agreed. Again, everyone in the thread has been supportive of OOP.
Ree wrote:Now, why would you want to validate email by using a separate object just for that? What methods/properties would you code in the class? I'm really not sure, because with email validation (or any other field) it's a pretty simple process: is the field empty - for that you have PHP's native function, no need to use your own, is the value an email - for that you would probably use a simple regex method. I can see only one method here (validation). Is it worth to create a new class just to contain one method and probably only one property (the value to validate)?
Thats the example I used, and I think its telling. McGruff's answer is essentially, yes, you'd have two methods. Since a function can return either (yes its valid, no its not), it accomplishes the same goals. McGruff's argument that it bolsters testing (in this specific case) isn't quite valid either: By using the definitive regex, which has (itself) been tested in a huge variety of applications, we ensure quality.
I'd argue that the number of tests required to duplicate that level of certainty would easily turn a one-page function into a prime example of why OOP *can* yield bloated code to accomplish the same task.
I'll be very fair and say I chose email validation because it was a totally loaded question. There actually is a definitive best way to validate, and choosing to NOT copy that is the literal equivalent not of reinventing the wheel, but of recreating an entire car. Using sheet metal and a hammer.
OOP has strengths.. I can give a half-dozen examples where the opposite is true. Places where procedural would stumble, look extremely fragile, spaghetti-like, and possibly run slower.
Which of course brings me full circle to my point: Screws need screwdrivers and nails need hammers. OOP and procedural are both valuable. Ignore either, and you ignore a significant tool in your arsenal.