Monday, 25 August 2008

1. Welcome to Django

This is part 1 of a series of posts on James Bennett's excellent Practical Django Projects. The main post can be found here. This is not a critique of James's book, but rather a collection of notes and code revisions to accompany it, both updating it for Django 1.x and things beginners may want to consider. The headings follow the subheadings in the book.

Say Hello to Python

If you haven't already bought a book on python and want some other recommendations to the ones given then I highly recommend Learning Python 3rd edition by Mark Lutz. Both the 1st and 2nd very thumbed editions took a long time for me to grow out of. The only thing I wish had been in Learning Python was a few modern software engineering principles such as test driven development. In fact I almost wish the first program was a doctest
>>> print 'Hello World'
Hello World
It took me a while to realise that learning to program without testing is like learning to drive without learning how to use the brake.

Looking Ahead

For learning Django, sqlite is the easiest entry point, but if you do decide to move your applications into the real world chances are you're going to want to install either Mysql or Postgresql. Just don't try to make a decision based on transaction speed, it's a futile exercise. Personally I think Mysql is easier to use and quicker to learn sql on than Postgresql if you're accessing your data outside Django, but once you're more experienced I think the balance tips to Postgresql as the more mature database, but for specific requirements each one has it's own advantages and disadvantages. I have happily used both in production but here's my take on the broader differences between them:

Mysql
 + The documentation has always been excellent and I think better than Postgresql
 + In some ways Mysql feels like Django in that they have made pragmatic choices to make things easier for rapid development. The prime example is the REPLACE statement which has no equivalent in Postgresql and statements like INSERT IGNORE.
 + Replication is easy to setup.
 + Works better with external odbc destinations such as Excel and Crystal Reports (the latest Crystal includes official support for Mysql).
 + The freely available tools are easier to use than those that are available for Postgres
 + A wide range of pluggable storage engines for different purposes

Postgresql
 + Stored procedures are much more mature than Mysql and you can use Python
 + If you ever have to slice and dice your data for reports with views then Postgresql is by far the best choice. Try writing a view of a view and you will quickly fall into a blackhole with Mysql.
 + For large data sets you can have partial indexes to speed up queries on massive tables.
 + In general Postgresql seems less forgiving when you try to do things you shouldn't with SQL, which is painful when learning but less likely to lockup your server.

For further reference a good up to date comparision is on wikivs

0 comments:

Hedged Down