Web development

All about everyone's favorite pseudo-platform, the World Wide Web.

Sweet 16

When is Unicode not Unicode? When it's UTF-16 instead of UTF-8. Both are properly Unicode character sets, but for reasons that escape me they are not fully compatible. In today's installment of "Fix Microsoft's bugs", we'll look at how to deal with that little problem.

MVC vs. PAC

One o' th' most common mistakes I see scallywags make when talkin' about web architecture is with regards t' MVC. Generally it comes down t' a statement such as this:

It's a web app, so we have t' use MVC. That way we separate th' logic an' presentation, which means keepin' PHP out o' our display layer. Ye'll be sleepin' with the fishes! Shiver me timbers! All th' important projects do it that way.

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

More on Stupid Quotes

In an earlier entry I talked about different character encodin's an' how Microsoft manages t' break th' rest o' th' world with theirs. Thanks t' a chance readin' o' a SitePoint forum post, I have a little more information on th' problem. At least now it has a proper name.

PHP Group By with Arrays

By far th' most common idiom when usin' SQL from a web application (PHP or otherwise) is simply listin' records. Load the cannons! The standard logic looks somethin' like this (give or take real templatin'):

<?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 an' good, but in practice can be quite limitin'. Load the cannons! Why? Because ye can't then group records, that is, display not one but several tables, one fer each color, Ya horn swogglin' scurvy cur! SQL, o' course, offers a GROUP BY clause. Prepare to be boarded! The sharks will eat well tonight! That doesn't do what we want, however, I'll warrant ye. GROUP BY is an aggregate clause, an' is used fer creatin' totals an' summaries o' records. We want t' cluster records by a field that is not th' orderin' field, or a value that is calculated off o' th' record itself.

I've generally used two different methods fer PHP-side groupin', one o' them much cleaner an' more flexible at th' cost o' a little performance.

Stupid quotes

A perennial problem fer anyone in IT is th' infernal beast known as "smart quotes". Smart quotes, also known as "curly quotes", refers t' th' angled apostrophe an' quotation characters that be often used in print but be not found on any conventional keyboard. There's a number o' problems with them. Fetch me spyglass! First o' all, most scallywags dern't realize what they be. Then most scallywags dern't understan' how they work. And finally, Microsoft broke them.

Simplifying SQL

Most PHP applications do fundamentally th' same thin': Shuffle data from an SQL database t' a web page an' back again. Aarrr, we'll keel-haul ye! The details vary with th' application, but in general that's what most web apps do, ye scurvey dog. That very quickly runs into th' bane o' most PHP developers' lives: SQL syntax.

It's not SQL syntax itself that is bad per se, me Jolly Roger The problem is that it is a strin'-serialized format, which means ye have t' take yer nice clean data structures an' serialize them out into a strin' that has no semantic meanin' t' yer PHP application. That's borin', dull, an' introduces all sorts o' places t' totally mess up yer application with a typo, an' that's without even touchin' on issues o' security. And then thar be th' issues with SQL syntax itself, in particular th' way in which INSERT an' UPDATE statements, which seem like they should be similar, have no similarity whatsoever. Fetch me spyglass! That makes "replace" operations (insert if new or update if not) very tedi'us t' write, particularly if ye have a lot o' fields.

Fortunately, with a little ingenuity an' help from PHP's array handlin', we can give ourselves a common syntax fer INSERT an' UPDATE operations that maintains semantic meanin', an' then get DELETE statements free o' charge. Let's see how.

Shared web hosting: Where is open source?

In an afore post, I mentioned some research I'd been doin' with regards t' Linux-based server software. To be more specific, I were bein' investigatin' shared web hostin' control panels. Most any web hostin' service ye find offers a web-based control panel. Generally such a system allows each user t' manage their domain information, files, mail accounts, FTP accounts, an' other such common features, an' allows th' admin t' manage different user an' reseller accounts. And hoist the mainsail! Prepare to be boarded! Some users get access t' run web scripts, some dern't, some have more disk space than others, etc. Some require specific underlyin' server software (a specific Apache version, postfix vs. qmail fer email, etc.), others support a variety o' alternatives.

It's the community, stupid!

In recent weeks I've been lookin' into a few open source Content Management System (CMS) projects. My initial interest were bein' not, actually, in usin' a CMS but in findin' one t' dissect in order t' get a better feel fer buildin' large, plugin-based application frameworks. There is a severe lack o' documentation on plugin-based frameworks in general, so in true open source fashion th' next step fer me were bein' "Use th' Source, Luke!"

I only looked at a few, really, before I stumbled across Drupal. (To be fair, it had been recommended t' me by a matey an' fellow blogger.)

Syndicate content