Archive for the 'Software architecture' Category

Meet us at LRUG

This monday I shall be giving a talk at the London Ruby Users Group. I’ll be giving a tour through our experiences building a modular composable Widget UI framework ontop of Ruby on Rails. Some of the steps we took along the way, problems we encountered, and a tour of the results.

There’s also a juicy debate to be had comparing the REST-driven web application architecture pushed by the Rails project, with our more modular widget-based approach, and in deciding what’s appropriate for your application. For those in the know, comparisons abound with the approach taken by Avi Bryant’s Seaside framework, and the Apotomo plugin already in development for Rails.

The framework comes with a client-side component too, and means of serializing Widgets to constructors for corresponding client-side javascript classes - so the talk may also interest those attempting to do Javascript in an unobtrusive, object-oriented way with Rails.

After that I believe (sincerely hope ;-) ) there are drinks.

The talk is open to all but the venue ask that you Register here; see LRUG for more details.

The more I have to hack ActiveRecord’s guts

to make it do something right - the more I’m tempted to rewrite it from scratch.

That whole “I never took (or never understood) a database theory course at university, so I’m just going to pretend it doesn’t matter, and that a relational database may be treated as nothing more than a glorified filestore for my Objects” attitude just doesn’t cut any ice with me, but seems sadly prevalent within the Rails community. Yes, good object-oriented design is really important - but you need a sophisticated relational approach in order to get a handle on the data model behind any kind of non-trivial inheritance & mixin hierarchy, and to persist it in a logically sound and efficiently-indexable fashion.

What’s more, I contend that your ORM tool needs to understand something of the relational algebra in order to represent what is going on in a sufficiently elegant, flexible way - otherwise you’ll always be piling hack ontop of hack whenever you want to map the results of a moderately complex query over to the OO side. Joining SQL strings together is not the way forward - these things are syntax trees with structure!

Ahem. Sorry if I sound exasperated. SQLAlchemy on the Python side gets this kind of thing ABSOLUTELY SPOT ON, and dare I say it, so do some of the Java ORM frameworks (shame about the XML config files and Java’s tendency towards boilerplate code and bloated syntax, but don’t throw the baby out with the bathwater Rails-ers)

The problem with Rails’ ActiveRecord is that it’s neither here nor there - neither the kind of lightweight, simple ‘map objects to database rows and nothing much else’ approach originally implied by Fowler’s Active Record design pattern - nor the kind of powerful ORM tool which is capable of turning the kind of tricks that are increasingly demanded of it in anything like an elegant fashion.

It seems the Rails team’s solution to some of the endemic problems with ActiveRecord’s messy guts is to wrap them up in a huge plastic bag known as caching - an acceptable pragmatic approach, I accept, in many situations, but one which would not be nearly so necessary had a different approach been taken to ActiveRecord’s architecture.

I feel that superior approach needn’t have come at the cost of ActiveRecord’s ‘convention over configuration’ and ‘easy to get started with’ benefits either - it just would have required a little more forethought and a little humility in learning about the Relational Model before attempting a tool which maps complex data models to a Relational Database.

Crap, I’m starting to sound like Fabian Pascal now aren’t I.

Of Nouns and Verbs

As the site develops we’ve been putting a lot of thought into how to architect things in a suitably general way - to build a playground for users with a set of objects they can play with, and a consistent set of actions they can perform. We found the following approach to be one rather nice way of thinking about it (cue monster diagram which Wordpress refuses to format nicely):

VERB \NOUN STASH (save / collect / organize) STALK (watch / observe / subscribe to) CHAT ABOUT WRITE ABOUT TAG BUY / DOWNLOAD UPLOAD / create
MUSIC / artist / label Save music for download queue; make playlists; organise music library Watch for new releases and events by artist or label; who’s listening to an artist/release/track? Bitch about music Review releases; Interview/profile artists; write music news Categorise music (genres?) Buy music! or download unlimited music if subscriber Upload your own tracks; create mixes and playlists
WORDS Bookmark content; compile your own editorial selections See who’s chatting about a piece Bitch about someone’s news/review/etc   Categorise writing; tell us what it’s about   Upload your own content
CHATS Organise your chat history; bookmark chats Get alerts about new posts in a chat     Categorise chats; tell us what they’re about   Start a chat! Participate!
PEOPLE Friends list; create user groups Get alerts on what friends are up to! Bitch about that guy/gal Profile / interview / write a testimonial about someone Categorize your friends (?)   Sign up! Invite friends!
EVENTS / venues / locations Bookmark events; add to your calendar Watch for new events at a venue / near to a location; Look for new attendees of an event Bitch about that band you saw the other night Review / preview events Categorise events Buy tickets; download flyers Add your own events
PICTURES Make photo galleries   Bitch about that pic your mate took Attach photos to content Tell us what photos are of; tag your friends Download photos and cover art Upload your photos and art

Obviously some of these things are a while off in terms of development - but this should give eager loudplayers an idea of what to expect!

From a software architecture standpoint, I found this an interesting exercise too. On a data modelling / OOD level, our Nouns correspond roughly with classes or data types, and our Verbs with interfaces / method signatures. Of course in practise it’s not quite as simple as the diagram’s layout suggests. But thinking about things in this way does help to identify a useful set of shared interfaces. Rather than keep tacking on additional, distinct modules of functionality (let’s throw in an events section!), we’d like to add nouns and verbs to our playground.

On the user interface level, too, this kind of analysis helped to clarify thinking on how to present a structured, consistent user interface, and how to structure navigation. We have a lot of work to do on this front too, but I feel we’re making great progress. John, our graphic designer and Tim our new recruit and go-to man for UI development, have been battling valiantly with photoshop, css, rails helpers, partials and view code. The task has been to build a suitably general and standardized way of presenting different types of object across the site - music, words, chats, people, artists and so on, all need representing consistently at different sizes and in different contexts, together with icons and links for the actions users can perform on them. It’s been frustrating at times but I think we’re beggining to nail it, and it’ll pay large dividends in the future in simplifying and providing structure for further UI development.