Off-road web technologies…

The internet is often described as an information superhighway. And on any highway there are vehicles, lots of different types of vehicles. I started to think about this over the last few days and realised that the two (server-side development) technologies I spend most of my time using these days represent two wildly different ‘vehicles’. And because I’m not averse to writing ill-thought out ramblings about the web, here are my thoughts.

ASP.net is a SUV

ASP.net is Microsoft latest attempt to take a lead role in web development. It’s a newer, shinier and much more powerful version of the old Classic ASP which I spent too many years using (and still do, regularly). It’s big and clever, does all manner of things for you, comes with a huge array of complex features, and is very picky what it runs on. The latest version of IIS for Windows only, please. (And yes, I know about Mono. Just bear with me.)

In short, ASP.net is a lot like this:

Sports utility vehicle

Yes, the Sports Utility Vehicle. Big, shiny, covered in chrome and brushed titanium. An interior made of plush leather with rare wood facias, and lots of slick gadgets. They say it will take you off-road anywhere, but let’s face it: these things are only owned by rich people living in posh suburbia. The dreaded Chelsea tractor factor, as some people have said.

They guzzle fuel, pollute the landscape, and if something goes wrong it goes really wrong and needs an expensive trip to the specialist garage to mend. No hacking away with a spanner and roll of gaffa tape on these, no way. But they have their good points. They are incredibly sophisticated, so don’t worry about reversing into a lamp-post because before you hit it a polite computerised voice will say “You’re just about to hit a lamp-post. Are you sure you want to do that?” and then offer you a latte.

They are comfortable; really really comfortable. You get so used to being inside one that when you have to drive in a Lesser Automobile you feel dirty. In fact they are so clean and nice to be in that you forget there’s an engine with messy things like oil and fuel squirting around in little tubes. Unscrew a little cap to check the oil? Not me, I just say “E-mail me a current oil level reading, car” and it does it.

And, let’s face it, everybody is jealous. They see me driving one of these and they know I’ve Made It. I must be some celebrity, or a director of a large company, because those sorts of people are the sorts of people to have these kinds of cars. I see them stare at the car from behind my tinted windows, as I press a touch-sensitive button to turn the air-con down just a fraction. And when I get home, I just twitch my left nostril a bit and the wrought-iron gates leading to my 400-yard drive swing open, and my digital TV automatically turns itself on to Footballers Wives. Bliss.

PHP is a Land Rover

PHP, on the other hand, is an old technology. Originally put together by just one bloke, and is now one of the foremost technologies in use on the web. From the page linked above:

Today, PHP is being used by hundreds of thousands of developers (estimated), and several million sites report as having it installed, which accounts for over 20% of the domains on the Internet.

Its open source roots, huge collective of developers, and ‘hackable’ nature have meant it is often the first server-side technology beginners have been able to get into without a steep learning curve.

In essence, PHP is quite like this:

Land Rover, the original and best

The classic British Land Rover. Originally built to be as simple to fix as possible, it has been a stalwart of not just the British Army, but many armies around the world, for over 50 years. It’s basic, uncomplicated, rugged and tough – exactly what you need for driving across difficult terrain. It’s so modular that what you can’t fix or find spares for you could probably make yourself. In fact I have a friend who makes spares for his Land Rovers in his garage using nothing but some simple tools.

So there you are, parts of your engine strewn across the desert floor after a particularly amorous rhino mistook you for a mate. It could have been worse – you have a set of spanners, a roll of gaffa tape and a flask of tea. Two hours later you’re back on your merry way, stroking your goatee in satisfaction and thinking of your collection of model steal engines waiting for you back in good old Blighty. What-ho.

Landys are classics, up there with Spitfires and red telephone boxes, pints of bitter and fish ‘n’ chips. They are reliable, and even when it does break you don’t need Jim to Fix It for you). But they aren’t comfortable or plush or stylish. They aren’t the sort of thing you turn up in to take a young lady to a restaurant. But they are just the thing to pull a posh SUV out of a muddy field with.

People also stare when you drive a Landy. Most people wonder why you don’t buy a ‘decent’ car, but those in the know understand. It’s not about the bells and whistles, the leather and chrome. It’s about an intimacy with the vehicle – knowing the nooks and crannies, knowing not just what everything does, but how and why. Landy’s hardly impress anyone, and turning up to a high-powered sales meeting in one will make people think you’re losing the plot. But put one up a mountain or in a desert and you’ll see why the heard of a free beast must run wild.

Image resizing with PHP…

One of the many things I love about the PHP scripting language is its support for image manipulation through the GD library. You want thumbnails? You got thumbnails. You want watermarks? You got watermarks. You want to create duplicates of 2000+ images in a folder with a slightly different filename, and a limited width/height? Use this script:

function resizeImage($source, $target, $width, $height){
$quality = 65;
$size = getimagesize($source);
// scale evenly
$ratio = $size[0] / $size[1];
if ($ratio >= 1){
$scale = $width / $size[0];
} else {
$scale = $height / $size[1];
}
// make sure its not smaller to begin with!
if ($width >= $size[0] && $height >= $size[1]){
$scale = 1;
}
$im_in = imagecreatefromjpeg ($source);
$im_out = imagecreatetruecolor($size[0] * $scale, $size[1] * $scale);
imagecopyresampled($im_out, $im_in, 0, 0, 0, 0, $size[0] * $scale, $size[1] * $scale, $size[0], $size[1]);
imagejpeg($im_out, $target, $quality);
imagedestroy($im_out);
imagedestroy($im_in);
}
foreach (glob("images/products/*_l.jpg") as $filename) {
$medium = str_replace("_l.jpg", "_m.jpg", $filename);
resizeImage($filename, $medium, 125, 100);
}

Notice the neat ‘glob’ function? That, my dear readers, is *nix brevity at its best.

Content management – getting fresher…

I’ve been doing some more thinking about content management idea and I’ve figured out how – I think – the database is going to work. Bear with me, because this might get pretty geeky.

Firstly I wanted to have an unlimited number of items; an item could be a page, a blog, a gallery, a forum etc. It doesn’t really matter what type the item is, but it is VERY important that we understand the relationships between them. So the Parent ID thing I mentioned in my original post has immense importance. Without that, there is no system. Let me give you a quick example in case you dont get what I mean.

I have a homepage for my site, which is called “homepage”. It has an ID of 1 and a Parent ID of 0. The ID is 1 because it’s the first item in my database. The Parent ID is 0 because if is the lowest level item.

I have another item called “about” which has an ID of 2 and a Parent ID of 1. The ID of 2 is because it’s the second item to be added to my database. The Parent ID is 1 because it’s a child of the item with ID 1 – homepage. This way we can build up hierarchical relationships between any number of items. Spiffing.

My tables will look more than a little like this:

Table: items

id (auto integer)
item_type (id of the type of item this is, from the item_types table)
status (the id of the status of the item, from the statuses table)
parent_id (the id of the parent of this item)
name (the name for this item)
permalink (the URL-safe version of the name, used for clean URLs)
created_on (datestamp of the create date)
created_by (id of the user that created this item, from the users table)

Table: statuses

id (auto integer)
status (the description of this status)

status values: [draft, public, private, deleted]

Table: item_types

id (auto integer)
item_type (the description of this type, more in this later)

I’ll let you guess what the users table will look like.

So, we have a basic database. Now what we need to do is start populating it with some data. But where? There doesn’t seem to be any fields in the items table to store the page content in, so where does it go? Well, I’m glad you asked, because the answer is ‘it depends’.

What content gets displayed when each item is called depends entirely on the type of that item. We know what type each item is because it’s stored in the database, but what types could we have – and what data can be attached to each type? Here’s a quick list.

Type: page
Data: page_title [text], page_description [text], page_keywords [text], page_body [text], allow_comments [bool]

Type: blog
Data: blog_title [text], blog_description [text], allow_comments [bool]

Type: blog_entry
Data: entry_title [text], entry_body [text], allow_comments [bool], categories [array]

Type: blog_comment
Data: commenter_name [text], commenter_email [text], commenter_website [text], commernter_ip [text], comment_body [text]

Type: gallery
Data: gallery_title [text], gallery_body [text]

Type: photo_set (just to make it clear, I thought each gallery – you could have more than one, of course – could have multiple photo sets)
Data: set_title [text], set_description [text], allow_comments [bool]

Type: photo
Data: photo_name [text], photo_description [text], allow_comments [bool]

Type: forum
Data: forum_title [text], forum_description [text], anonymous_posts [bool]

Type: forum_thread
Data: thread_title [text]

Type: forum_post
Data: post_body [text], poster_name [text], poster_email [text], poster_website [text], poster_ip [text]

So, of course, there could be more types than this. And, of course, quite a few of the types share the same kind of data which could well be normalised in some table somewhere. But hopefully you see that most item types are pretty similar in the data they require. The lesson from all of this is: do we really need different tables for all of these data types? I don’t think we do.

One last note. This system borrows heavily from the ethos of 37signals Ruby on Rails which is ‘convention over configuration’. That makes a lot of sense to me.

Folksonomies – a different perspective…

There’s been a bit of brou-ha-ha recently over and essay on folksonomies written by Elaine Peterson, Associate Professor and Information Resources Specialist at Montana State University. She talks about the disadvantages with using folksonomies – the posh word for data tagging – and ends with this bold statement:

Folksonomy is a scheme based on philosophical relativism, and therefore it will always include the failings of relativism. A traditional classification scheme will consistently provide better results to information seekers.

(Boldification mine.) I don’t believe this is completely true, however I don’t believe it’s completely false either. And the reason? Well, anyone can hit a nail in with a heavy screwdriver, but using a hammer is much better. That’s right, it’s horses for courses between taxonomies on the right and folksonomies on the left.

Elaine Peterson makes some claims about why folksonomies are a dodgy classification system, but I believe in a lot of instances they don’t matter. She says:

The issue is that adding enough of those individual interpretations [how each user views a particular piece of data] through tags can lead to inconsistencies within the classification scheme itself.

Of course, different people can have different views on particular data and that’s a great thing. For example, one of my favourite bands could be labelled in any music shop under “rock”, “folk” and “jazz”, depending on which album, or indeed which track, you listen too. How would a traditional, inflexible taxonomy handle that?

The fact is it wouldn’t, you get what you’re given whether you like it or not. I’m not saying there aren’t times when that kind of classification isn’t needed, as it is.

For example, part of what I do during the working day involves the set of codes used to categorise every ailment, illness and disease known to man. ‘H33’ would mean something very specific, and it would have a parent, and that would have a parent, all the way up to the major groups – cardio-vascular, muscular etc. In that case, a very specific and rigid classification methodology is not just useful, it’s vital.

However, when it comes to things that people interact with in a more random and rambling manner, tags are the way to go. What Elaine Peterson sees as the weaknesses of folksonomies, I see as it’s strengths. For instance:

  • …user assigning a heading of “San Francisco”, while another uses “Frisco”…
  • …spelling white horse as whit horse…
  • …tagging White Horse when the image is of a white cat…
  • …using an esoteric tag known to very few…
  • Each Internet user is bringing to bear on the item a different linguistic and cultural background…
  • There are no right or wrong classification terms in a folksonomic world

That, to me at least, is wonderful. Let’s use these apparent ‘wrong’ things to make sure we cover every base. I may want to search for ‘Frisco’ and not ‘San Fransisco’, I may discover a fantastic picture of a white cat when I’m looking for white animals. I might find some items relevant to me based on esoteric and culturally-specific search terms. And that is all good.

If you want something more specific, or you want to reward tags that are more ‘right’ then by all means have some weighting in there. So, if only one person has tagged my picture as ‘whit horse’ and a thousand have tagged it ‘white horse’, guess which one has the higher weighting? But don’t penalise someone just for having a different opinion to you about something.

When it comes to the ever-expanding world of internet user-driven applications (a la Flickr etc) tagging is not just a useful tool, it’s vital to the growth and reach of the system. Tagging allows people to search and find, discover, create connections they would never have thought of by themselves, follow unexpected paths. And maybe they’ll find something that is just perfect.

I don’t believe any inflexible, rigid categorisation structure will give you that: the joy of unexpected discovery.

Iona live in Leeds…

Lat night I accompanied my good friend Dave to see the Celtic prog-rock band Iona live at St Georges Church in Leeds. The church turned out to be a large city-centre building with a warm atmosphere and extremely well-equipped interior. In fact I think it was one of the best modernisations of a traditional worship space I’ve ever seen.

Anyway, the gig. Wow. It’s been a long while since I last saw Iona in concert, but they’ve not lost any of their passion, skill or touch. At times rocking, at times deeply moving, this was an evening where a group of consummate professional musicians showed us what being a band was really all about. From the jigs and reels where they expertly mix traditional Celtic music with modern grooves, to ethereal soundscapes, to blisteringly fast virtuoso guitar solos, to haunting and compelling melodies, they are pretty darn fantastic. To be honest, words fail me; this is music that got into my soul a long time ago and will remain there for a long time to come.

I first got into Iona back in about 1992 or 1993, I remember having their Beyond These Shores album on continuous repeat in my Walkman until the tape snapped. In fact that was such a traumatic event for me I remember exactly where it happened, and that sad day comes to mind whenever I walk past that spot (by the allotments just off Willans Road). A couple of years later I saw them live at the Irish Centre in Leeds where they were recording their live album Heaven’s Bright Sun, and I remember standing right at the front of the crowd with my hands against the speakers, lost in rapture of this sound I was hearing.

In fact the recording of Inside My Heart from that album still brings me to tears every time I hear it. As I said to my wife earlier today, sometimes you experience something that, to you at least, is so close to perfection that it shows you a glimpse of a world which is to come. Something you can’t touch or fathom yet, but you know it will eventually be within reach. That’s what Iona’s music does for me.

Visit the site, listen to the samples. Then buy every album you can, because this is a band who (in my opinion) are one of the finest groups to ever come from these small islands. Heck, I think they are one of the greatest bands in the world.

So, thanks Dave, Troy, Joanne, Phil and Frank (and all the others who have played with them over the years). I owe to you no small part of my love for music, and, by extension, my love for life.