PHP Off Road

posted May 8, 2009 by daniel

Programming frameworks provide tools to solve common problems so developers can focus on the task at hand rather than waste time reinventing the basics. For years as a MS Windows C++ programer, I used the MFC application framework because that was the standard. MFC is a grand object-oriented design where each of the classes inherits from CObject. It seems like a clever idea and a good strategy for organizing a complex system, but I noticed that for some tasks using direct API calls — bypassing the framework — was simpler and easier.

I started working on an existing project much different from the typical MFC application. This project used no framework at all, which meant solving common problems all over again. It was sometimes tedious, but also a good lesson about what MFC did behind the scenes. I realized that MFC provided a lot of support, but the clever object-oriented design actually created extra work sometimes. Curious about alternatives, I tried a framework called WTL which provides simple wrappers for common tasks, without the seemingly-clever CObject design — and it actually made development easier because it didn't add unnecessary layers of complexity. I wished I'd taken a chance and tried WTL much earlier.

What makes one framework different from another is the design goals. MFC's designers set out to make a clever framework making full use of the object-oriented style. WTL was an internal project intended to allow developers to write small and efficient code, which was eventually released as a framework for others to use. It seems that the key difference between frameworks is not the design of the framework itself, but what kind of code is written when using the framework. A framework that helps a developer write easy to read, concise code will be a better framework regardless of how clever the internal workings of the framework are.

When I switched to PHP development, I researched various PHP frameworks and eventually settled on one. It took me some time to become familiar with PHP and realize that the framework I chose is bloated because the code I'm writing is more complex than it needs to be. Unsurprisingly, the design of the framework centers around a seemingly clever object-oriented tree structure that actually adds unnecessary complexity. It's not that object-oriented design is flawed, but that not every design benefits from being coerced into objects. The goal of a framework should be to make the life of the developer easy by solving the common issues they'll encounter in a way that allows them write concise, readable code, and while this framework is nowhere near as bad as MFC, it seems to focus more on clever design of the framework, rather than making development simpler.

I researched more PHP frameworks and didn't find anything that suited my needs, so I decided to write my own framework which I call PHP Off Road. I started with the code I wanted to write and built the framework to support that. The framework — like many other PHP frameworks — is divided into Controllers, Models, and Views. It's not revolutionary, but it's no more complex than it needs to be — the core of the framework is a single 200 line file. The rest is optional extensions (or plugins) and a fairly simple contract between Controllers, Models and Views. It's working now (this site uses it). Besides simplicity, the other key to a good framework is documentation. I've started documenting PHP Off Road, so check it out.