MVC vs. PAC

One of the most common mistakes I see people make when talking about web architecture is with regards to MVC. Generally it comes down to a statement such as this:

It's a web app, so we have to use MVC. That way we separate the logic and presentation, which means keeping PHP out of our display layer. All the important projects do it that way.

Of course, such a statement is false. It demonstrates a lack of understanding about MVC, about web applications, about "important projects", and about software architecture in general. Let's try to clarify, with a little help from Wikipedia.

Project of the Month

There be two thin's that tend t' happen at th' end o' th' year: Predictions about what th' new year will hold that no nay ne'er come true, an' new years resolutions that last until Martin Luther Kin' Jr.'s Birthday. I'm not goin' t' spend time on th' first (at least this year), an' I'm not goin' t' be so lame an' predictable as t' call this a resolution so I avoid th' curse o' th' second. That said, though, I am goin' t' do somethin' fer th' new year, an' ask others t' join me.

Announcin' th' Open Source Project o' th' Month!

Quote 36

Programmin' is like sex; make one mistake an' support it fer th' rest o' yer life.

— Anonymous

More on Stupid Quotes

In an earlier entry I talked about different character encodings and how Microsoft manages to break the rest of the world with theirs. Thanks to a chance reading of a SitePoint forum post, I have a little more information on the problem. At least now it has a proper name.

PHP Group By with Arrays

By far the most common idiom when using SQL from a web application (PHP or otherwise) is simply listing records. The standard logic looks something like this (give or take real templating):

<?php
$result
= mysql_query("SELECT tid, name, size, color FROM things ORDER BY name, size");
print
"<table>\n";
print
"<tr><th>Name</th> <th>Size</th> <th>Color</th></tr>\n";
while (
$record = mysql_fetch_object($result)) {
  print
"<tr>\n";
  print
"<td><a href='viewthing.php?tid={$record->tid}'>{$record->name}</a></td>\n";
  print
"<td>{$record->size}</td>\n";
  print
"<td>{$record->color}</td>\n";
  print
"</tr>\n";
}
print
"</table>\n";
?>

That's all well and good, but in practice can be quite limiting. Why? Because you can't then group records, that is, display not one but several tables, one for each color. SQL, of course, offers a GROUP BY clause. That doesn't do what we want, however. GROUP BY is an aggregate clause, and is used for creating totals and summaries of records. We want to cluster records by a field that is not the ordering field, or a value that is calculated off of the record itself.

I've generally used two different methods for PHP-side grouping, one of them much cleaner and more flexible at the cost of a little performance.

What is your accent?

So apparently I dern't have an accent. The InterWeb said it, so it must be true!

Stupid quotes

A perennial problem for anyone in IT is the infernal beast known as "smart quotes". Smart quotes, also known as "curly quotes", refers to the angled apostrophe and quotation characters that are often used in print but are not found on any conventional keyboard. There's a number of problems with them. First of all, most people don't realize what they are. Then most people don't understand how they work. And finally, Microsoft broke them.

Quote 31

Any sufficiently advanced technology is indistinguishable from a rigged demo.

— Anonymous

Emacs wins!

The great question of the day has been solved, and it is Emacs that wins.

Not that I use Emacs, mind you, but I've said for years that sooner or later, GNU/Linux would go away and be replaced by your choice of KDE/Linux (KDE having taken over so much functionality that all it needs is a kernel) and Emacs/Linux (Emacs already being almost an OS, except for missing a text editor). The only question was which would happen first.

Merlin the Amazing

I make no secret about th' fact that I am a fan o' Free an' Open Source software. Fetch me spyglass! There be many reasons. The quality o' th' code tends t' be better, Ya lily livered swabbie! I like t' tinker with it an' see how it works. It's usually gratis as well as [Free|Open]. But what really makes Open Source so attractive as both a user an' a developer is talkin' t' merlinofchaos.

Syndicate content