The eclectic musings of a bitter software engineer.

I’ve been developing PHP/MySQL applications for years, both professionally and as a hobby, and if there’s one thing I’ve learned, it’s that there are an infinite number of wrong ways to do it and very few right ways. The vast majority of open source PHP/MySQL web apps are horrendous pieces of garbage. Even the ones that look pretty and clean on the outside are, more often than not, an utter mess inside. This is because the vast majority of PHP/MySQL developers—even the ones who think they’re the hottest shit that was ever shat—place more importance on the end result than on how they get there. And believe me, the ends rarely justify the means when it comes to programming.

It’s an easy trap to fall into, especially in web development. The thing that makes web development so sexy is the instant gratification; you write some code, you click a button, and you’re looking at the result of the code you just wrote. Since the dawn of time (by which I mean the 1970s), books and teachers have been using the concept of instant gratification to get people interested in programming and to keep them coming back for more. This is why the first program you learn to write in a new language will always be “Hello World”; it gives you a very simple taste of the language, provides instant gratification, and leaves you thinking, “Well, that was easy. I want to learn more!”

This makes people lazy, and this laziness is enhanced when the language is as simple to learn and implement as PHP. Why spend a lot of time coming up with an elegant way to separate logic, content, and presentation when you could just toss everything together, copy some example code off a few websites, say a prayer, and get an instant result?

I was certainly guilty of this sort of thinking once upon a time. PHP makes it ridiculously easy to write messy, unsecure, unmaintainable code that nevertheless produces beautiful results. I should know; I’ve written my fair share of crappy PHP code. But with a little thought and some attention to detail, PHP also makes it easy to write beautiful, elegant, secure, maintainable code that produces beautiful results.

After years of writing framework after framework for my web applications and never being fully satisfied, I’ve finally hit on one that works well and makes me happy. It evolved over a period of about two years, gradually getting simpler, more elegant, and more maintainable, until it finally reached a stage where I was able to use the same concept in several web applications of various sizes without altering it. It does away with many of the most common PHP annoyances, makes security painless, and is simple enough and flexible enough that maintaining old features and adding new ones is a breeze.

Over the next few days, I’ll describe the concepts behind the framework, how they evolved, and how I’ve chosen to implement them. There will be lots of example code and lots of me making fun of old code I’ve written. So if this sort of thing interests you at all, stay tuned. Otherwise, be patient. It’ll all be over soon, I promise.

Comments

I can't wait to read the rest, this is something that I have experenced many times.

Thursday October 06, 2005 @ 05:20 PM (PDT) Posted by Professor

This sounds like it'll make interesting reading. Looking forward to it.

Thursday October 06, 2005 @ 09:06 PM (PDT) Posted by Cessen

.

Friday October 07, 2005 @ 01:43 PM (PDT) Posted by Bart D.

It occurs to me that I never got around to describing the evolution of most of the concepts I introduced in parts 2 and 3, nor did I make fun of my old code. Oops. Maybe some other time.

Saturday October 08, 2005 @ 06:48 PM (PDT) Posted by Ryan Grove

I completely agree with your observation about most open source PHP apps being garbage on the inside. However this is more true of apps that were written 5 years ago than apps written today. The tools for PHP development have evolved to allow developers to develop in a cleaner an more robust ways. One major contribution to this cause is Smarty (http://smarty.php.net), which opened the door to effective MVC development in PHP. Many of the PHP 5 frameworks that I have run across are very clean indeed and they have paved the way for clean applications as well. The public knowledge project at Simon Fraser University (http://pkp.sfu.ca/) is a good example of PHP developers focusing on keeping the internals clean. They have developed a core framework upon which they can now build clean and powerful applications in an orderly fashion. I have also developed a framework that makes PHP/MySQL development clean and easy (after all the web is not rocket science) called Dataface (http://fas.sfu.ca/dataface). Dataface reduces the time to develop applications and also reduces their complexity, making them easier to manage in the long run. The key, with PHP development, is to use the tools that are available and not try to reinvent the wheel. I find that PHP developers in general have a huge problem in this area. They all want to reinvent the wheel.

Friday June 01, 2007 @ 11:25 AM (PDT) Posted by Steve Hannah
Post a comment

Basic XHTML (including links) is allowed, just don't try anything fishy. Your comment will be auto-formatted unless you use your own <p> tags for formatting. You're also welcome to use Textile.

Don't type anything here unless you're an evil robot:


And especially don't type anything here:

Copyright © 2002-2008 Ryan Grove. All rights reserved.
Powered by Thoth.