In my last post I tried to articulate some of the things I’d like to see in a PHP framework. Youngj posted a comment and suggested that I try Qcodo. I have a problem with Qcodo’s template system, and it is a problem that I have with a large number of other PHP frameworks: HTML that gets embedded in the PHP code (also known as PHP code that writes HTML). I’ll let this criticism of Qcodo stand-in for my criticism of all PHP frameworks that do this (which is most).
Please consider the example Qcodo gives on the front page of their site:
<? $this->RenderBegin(); ?>
Id: <? $this->txtId->Render(); ?>
Title: <? $this->txtTitle->Render(); ?>
<? $this->RenderEnd(); ?>
Bad. Really bad. Not from a programming point of view, perhaps, but from a work flow point of view, in a professional web design firm. In this example, the form is no longer being controlled by the designers. What happens if the designer decides that the Title should have a red background, but they don’t want to change the CSS values for all inputs on the page, so they need to give that particular input an id? They then need to come to me, the programmer, and say �Could you add an id to the Title input?� Thus, work is shifted from the designers to the programmers. This is bad economics, since in most web design shops the programmers are paid more than the designers. And why would I want extra work? Why would I want a framework that puts more work on me?
When the PHP code writes HTML, the programmers end up doing work which the designers can do better.
Much better would be something like this:
<form method="post" action="index.php">
Id: <input type="text" name="id" value="< ?= currentValue("id"); ?>” />
Title: <input type=”text” name=”id” value=”< ?= currentValue("title"); ?>” />
<input type=”submit” value=”Update this article?” />
</form>
This block of HTML is something the designer can control. What happens if the designer needs to add an id to any of these HTML elements? They can add it on their own, without bothering the programmer. And what happens if the client decides that the value of the submit button should be reworded? Who does the work go to? The designer or the programmer? Qcodo sends the work to the programmer, but in my example the work can go to the designer. That means Qcodo is bad economics, at least from the point of view of a professional web design firm.
I might ask why something like this is so popular among web application frameworks:
Title: <? $this->txtTitle->Render(); ?>
I believe that the programmers who write pages like this (and I used to be one of them) are hoping to achieve productivity gains by automating some of the work of creating forms. I believe this is a false economy. I don’t see that the number of characters is dramatically less in the Qcodo example than in my example. Whatever small gains Qcodo makes, they are lost as soon as a designer needs to come to a programmer to request a change.
I do believe these frameworks (such as Qcodo) achieve real efficiency gains if the programmer is working as a freelancer, and does both the programming and the designer work. If I was a single individual, unattached to any company, then I would probably use a framework with a template system just like Qcodo (in fact, I did, when I was just starting out). These template systems probably save programmers some time, but they waste time when non-programmers need to edit the pages. In a professional web design firm, one that handles large sites and therefore must have multiple people working on the site, I believe the best bet is to stick as close as possible to pure HTML. HTML is one of the few things that everyone in a web design firm will know.
Qcodo does a much better job of explaining itself and its philosophy than many other PHP frameworks. And from what I can tell, it seems to be well implemented. But it does not trust designers, and it writes too much HTML on it’s own. Consider the way it describes its code generation abilities:
Taking a quick look at the web front-end of codegen, you’ll see that only the top dozen or so lines (including comments) directly deal with the CodeGen object. Everything else past it is simply to paint a pretty HTML page to display the results.
“To paint a pretty HTML page”. Ah, yes. Well, I don’t think I’ll give it a try. I’ve a lot of PHP frameworks to test, and I’ve limited time, and this one sounds like it is taking too much power away from the designers.
If a programmer is also their own designer, then I can imagine why they’d want to write all the forms in PHP - it would save them some time. Peter Bowyer summed up that point of view with this post from 2003:
My current project is the biggest site I’ve had to design and build by myself. And in the process of planning the code I’ve realised why so many people have a framework they use. I’m having to do too much stuff here from scratch; code that should just plug in from existing projects. I’ve written a SQLBuilder library, polished up my own take on Fusebox, and am developing the FormProcessor library (the more I use it the more I realise why people do forms the “normal� - i.e. writing PHP to construct them - way: it’s such a pain writing these forms by hand. Dreamweaver really doesn’t speed up the generation much.
Right. But if the forms do need to be edited by a designer, perhaps using Dreamweaver, then it is better to have the form elements defined as pure HTML. If you are a lone, individual programmer you can do everything to suit your own taste, but when you’re working in a shop where several people work together on one site, then one needs a framework that maximizes how much the designers can do on their own.
The example you posted also has it’s flaws. Short tags are not portable and usually frowned at… so you’d have to add in another 3 characters (”php”) just to start a tag.. and then change the “=” to “echo”. Also, what does the “currentValue” function name mean to anyone looking at it out of context? Current value of what? It is a function now, not a method of an object… which means there is no state, and no member properties or methods… and that means it’s in the global namespace… which means the only way for that function to gain access to “id” or “user” is to have other global variables, and let’s hope there’s not another function called “currentValue” somewhere out there. Yikes! Anyway…
Your question, “Why would I want a framework that puts more work on me?”. You don’t, but Qcodo is also doing a lot of work for you, probably more work than you’d be doing without it. So really, it’s probably not making you do more work which is your question. But it all depends on your problem of course.
It’s all relative. We’re going to have to do *some* work :). It just depends on what kind; if you want control that is. Less need for control = less work. More need of control = more work, probably. It’s the glass half empty or half full thing. Do your designers need absolute control of every visual aspect? I wouldn’t think so. We need a nice middle ground, logical assumptions. But we’re talking PHP here and there isn’t a de facto standard framework. It’s tough no doubt, which is why you see hundreds of frameworks for PHP, everyone is trying to solve the same problems. A new one seems to popup everyday. I myself have written about 10 completely different ones. If you think about it, it’s completely impossible to NOT mix code with html in some way or another. Once you realize that, you just need to decide which is it? Having html being generated from code, or have the html/templates embed code?
- matt