Made Media Ltd, 97 Icknield Street, Birmingham B18 6RU +44 (0)121 200 2627

Made Media Ltd

Posted in technology by jake on March 16th, 2006

A Brand New Prototype

With all the chaos over separation of style (CSS) and content (XHTML) as being pushed by luminary bodies such as the The Web Standards Project finally dying down, and AJAX appearing as one of the new standards in web development, Javascript is getting a chance to paint itself a new responsible image. No longer relegated to drifting 'DHTML' snowflakes over holiday periods, it now has some actively developed and highly useful libraries to make the 'net better for the people using it.

All recently used on a large project here at Made, the 'Javascript Trinity' of libraries makes javascript a joy to code:

  • Prototype, the workhorse of the tree, extends the default Javascript functionality available in browsers to provide a standardised and well-structured base for further Javascript development.
  • Built on top of Prototype, provides effects, drag-and-drop events, sliders and AJAX update-in place fields amongst its many features. Accessible controls exist to make data entry easy (and sometimes even fun), stop relying on a page full of nothing but text boxes.
  • When AJAX was coined, a lot of people dropped the only-recently-celebrated notion of clean markup and and started dumping Javascript into the middle of their otherwise-lovely XHTML. Behavior solves this problem by using CSS-style selectors for attaching events to certain elements.

Prototype is rapidly approaching a new release, adding some brand new features:

Extending elements

One of Prototype's new features is the ability to add additional methods to XHTML element objects. While this has been possible in some circumstances by extending the prototype of an object, the new Element.extend functionality can add methods to individual objects. Whats more, it automatically happens when you call...

... the $() and $$() functions

Handy functions, especially because of their terseness. The $() function in its normal use is mere shorthand for the oft-used and oft-misspelled getElementById() function, but supplied with multile parameters it will return an array of the elements with those ids. Now it will even extend each one.

The $$() is an even more flexible beast, returning all elements for a CSS selector *and* extending them. Powerful stuff, for example:

$$('div#main').each().hide() // Would hide all photos within the 'main' container element


Many other functions exist in prototype or will appear in the next version to make our lives easier and the users' lives better. The $F() function to get the value of any form field, an each() method for ruby-style loops, $R() for creating iteratable-ranges between specified bounds, all exciting additions to a language on the up.


Posted in design,technology by jake on March 15th, 2006


Posted in culture,local by jake on March 6th, 2006

The Public – Closed Before it Opened?

Today’s news that The Public are appointing administrators is sad. Hopefully the project can be put back on track.

Having worked in West Bromwich for six weeks in 2001, I don’t take much convincing that the area is deserving of serious investment in cultural regeneration. It’s too early to guess at the root of the problem or its possible solutions, but if it does turn out that £54million has been financially mismanaged into a dead-end then the people of Sandwell will have every justification in feeling angry about it.

I always thought there was something slightly millenium-domelike about the building project, and you do have to wonder what’s been keeping 84 people so busy, but when your organisation has been making do with next-to-nothing for 30 years it must seem inconceivable that a cheque for £40m will ever run-out. Looking at this page on The Public’s website you get a sense of yearning for the early years touring the Black Country in a beaten-up bus…


Posted in technology by jake on March 4th, 2006

ActiveRecord Angst… ReActivated.

Surely the last thing PHP needs is yet another interpretation of Active Record right?

Maybe, but this stuff is such fun to code, and for me all of those valiant copycat attempts still fall short in comparison to the elegant Ruby on Rails version.

The thing I admire most about Rails' ActiveRecord is the total clarity with which sub-classes represent the database table, and instances of those classes represent a row in that table. For well documented reasons, PHP5 still can't pull off this representation, and so most attempts use workarounds that kind of get there in the end, but sacrifice all of the Ruby elegance along the way.

My own hack is to use static methods in the base class to retrieve instances of subclasses, so that you can use:

$person = MyActiveRecord::FindById('Person', 12);

to find an instance of the Person subclass, rather than the preferable, but impossible:

$person = Person::FindById(12);

You can consider the base MyActiveRecord class as a kind of static Object/Relational Mapper whilst instances of its subclasses represent specific table rows.

It's a kludge, but still better than something like:

$dummy = new Person();
$person = $dummy->find_by_id(12);

Which in my view is just plain wrong architecturally, and also more awkward in use.

Here's a proof-of-concept class you can download under a BSD license. It has some limitations but in fact these might be advantages if you're after a quick and convenient ORM class to do your bidding, rather than a full-stack regime to tell you what to do. The double-edged limitations in question are:

No Upfront Declarations

To represent a table as a class you need do the following:

define ('MYACTIVERECORD_CONNECTION_STR', 'mysql://un:pw@yourhost/yourdb');
include 'MyActiveRecord.php';

class Person extends MyActiveRecord {}

And that is all. Obviously this requires some strict schema rules in your database. Each database table is named identically to the class that will represent it (is that really so bad?). Each table must have an auto-incrementing id and foreign keys must be named in the form ForeignTable_id.

The point is that you don't need to make any declarations in a constructor or configuration file. This holds for relationships too. There's no need to declare a one_to_many relationship upfront if you're going to use methods like this:

$articles = $person->find_children('Article');

Of course you might want to add composite properties, validation rules, clean-up routines and so on, but these can be achieved very simply by overloading the methods set_properties(), save() and destroy().

MySQL only

It's LAMP right? Not LAPP, LAOP, LASSP or LADP. Despite the accusations regularly levelled at MySQL, I think that's what most of us use and if you believe in getting everything through your ORM then there's a good argument that you really want your database to play dumb.

Apart from taking out the overhead of a database abstraction layer, knowing that it's MySQL we're connecting to enables us to leverage some vendor-specific retrieval methods, and offload type-conversion to the database server.

PHP 4 Compatible

If anything, the class runs better under PHP5, but PHP4 is still prevalent in most hosting environments including MADE's main web-server and this is intended to be a convenient, simple class rather than a paragon of PHP architecture. For that reason PHP4 compatibility is maintained, but that means

  1. triggering errors rather than exceptions
  2. 'StaticMethods' are implied by naming convention rather than enforced by the static keyword
  3. not leveraging __get(), __set() or __call(), all magic methods that could be really handy in a class like this...

It's quite big

You might easily argue that the class is monolithic and attempts to take on too much of the problem. It might be nicer to abstract the database-connection, table, column, errors and validation-routines into their own classes, but then before you know it you have an ORM framework that requires a book of its own to understand and that's absolutely what I'm NOT trying to do.

Not transactional

It's really not ACID and I'm not sure how I would rework it to make it so. That's actually a really strong argument for looking at a separate Mapper Class/Data Object Class, as the Mapper can also double as a Unit Of Work. This is the approach we take in our own framework StageBlocks...

So if none of the above puts you off, download the class and give it a whirl. I'm not aware of anything that plain doesn't work, but would really welcome any bug-fixes or suggestions for improvement.

1 Comment

Posted in culture,local by jake on March 4th, 2006

City of Culture

Reading this article it’s easy to draw parallels with last week’s news from West Brom. Both feature the cancellation of an ambitious, Alsop-designed building of questionable purpose, the disconnect between bid-winning visions and grass-roots reality and the promotion of cultural funding as a regeneration tool.

I’d like to believe that Birmingham would’ve done a better job. We do have a healthy selection of current cultural assets to draw on in this city, so I don’t imagine we’d have been struggling quite so hard just to think of something to put on. Fitting all of the funder-logos on the flyers might have been a different story. (link via d’log)