Daily Archives:September 28th, 2005

Another nice quote from Paul Graham

“As a rule of thumb, the more qualifiers there are before the name of a
country, the more corrupt the rulers. A country called The Socialist
People’s Democratic Republic of X is probably the last place in the
world you’d want to live.” – Paul Graham

(Thanks to James Miller for that one)

Django and Rails

No conference which discusses the Web can consider itself cutting-edge these days unless at least a couple of the speakers make reference to Ruby on Rails. For those who haven’t come across it, Ruby is a very dynamic programming language which has been around for a long time, but because it originated in Japan, it’s taken a while to gain popularity in non-Japanese-speaking parts of the world. Rails is a framework which takes advantage of the dynamic nature of the language to map SQL databases neatly onto Ruby objects. It has scripts which create a lot of standard stub code for you, and so in general it makes it very easy to create web applications based around a SQL database back-end, which an awful lot of web apps are, nowadays.

I wrote briefly about Ruby on Rails three months ago, and since then I’ve been sipping at the kool-aid – watched the intro videos, bought a Ruby book, and played a bit with the software – but I never quite got a taste for it. Ruby is so named because it was meant to be a better PERL, and it certainly is that, but I think there’s a few too many Perl-isms still lingering in the background. Ruby enthusiasts claim that it’s a ‘pure’ object-oriented language, more like Smalltalk than most of its competitors, because everything is an object, so you can do things like calling a method on an integer:

5.upto(10) { |i| print i }

but somehow this just doesn’t feel very natural to me. You can do some lovely things in Ruby, but I don’t think a language can lay much claim to purity when it still has things like the global $_ variable from PERL.

And so I’ve been very pleased to discover Django, which is a very similar framework that slightly pre-dates Ruby on Rails, and which is based on Python rather than Ruby. Python has been one of my favourite languages for a long time – I first used it in 1991 – and to my mind it’s rather nicer than Ruby for most things. It’s much more widely known, and all the benchmarks I’ve seen also show Python as rather faster than Ruby, and Django as higher-performance than Rails.

Django works the opposite way to Rails; you create particular kinds of objects in Python and run a script which produces the SQL tables which store them for you. In practice this doesn’t make a huge difference. The Rails approach can be more flexible, but with Django’s you get all your canonical source code in the same language. They both have their merits. But the default framework that Django produces is much more useful than anything you get for free with Rails; it provides quite a nice ‘admin’ interface which you can start using immediately for entering data without grimacing too much about the user interface.

My wife Rose needed to store some data in several related tables and access them from home and from the University. In one day I was able to take her data, which was mostly in tables in Word documents and get it via Excel, text files, and some Python scripts into a MySQL database. Django provided the web front end and by the end of the day she was entering her data via her browser into a set of inter-related tables with various conditions attached. I was working in the next room and from time to time I’d come in and say – “Look – there’s a search box now!”.

Remember that this was my first attempt at using the platform. Now, of course, I’ll be tinkering with it for ages, but the ability to get something up and running and useful so quickly is a great tribute to Django’s design. I also have a feeling, though I haven’t tested this yet, that much of Django might be more useful than Rails for any web apps which are not based on a SQL database.

Anyway – highly recommended.

© Copyright Quentin Stafford-Fraser