user.p0d.org

bits release in progress

Django, not necessarily the best solution

Tags rant

A feedback about my experience with Django and others.

I recently had to build a blog (http://pariscotedazur.fr/) using what seemed the best Python framework at this time, Django. Truth to be told, this was an rewarding experience, but in the end i finished disappointed by this framework.

Django

It's 148k source lines of code as ohloh as of today.

It include a template engine, declarative ORM, auto-generated administrative backend, common views, form handlers, authentication module, caching system, comment system, a good documentation, a huge community, et cetera, et cetera.

On the paper, Django seems to answer to all your needs, especially those of a mere blog.

However it took me over 3600 sloc to obtain the basic features i wanted. Maybe it's me, but i think this makes a lot for a framework batteries included.

As a result, i got a blog using too much memory in my opinion, and i spent a lot of time reading pages of Django's code trying to figure out how to do stuff.

ORM

I had a particularly hard time to reach my goals with the ORM. I understand, and even approve, it's more elegant to not mix the languages (SQL / Python) in a single source file; but the SQL logic remains sometimes easier to express in SQL.

I gradually realised I was spending a disproportionate amount of time trying to coax the ORM into doing my bidding - and when I succeeded, the results were often ugly, slow and needlessly opaque.

Cortesi - A Farewell to ORMs

Aldo said it better than i could, and as him i felt the frustration of forcing my way through the ORM.

For my blog i decided it was more efficient to use SQLAlchemy only for the database abstraction, providing a comfortable independence to the database engine, and doing my requests in raw SQL (i have yet to try the SQLAlchemy SQL Expressions Cortesi was talking about).

Framework

After a long hesitation to use CherryPy (19k sloc as ohloh) i finally fell for Flask (7k sloc as ohloh), an elegant micro-framework with only the strict minimum while providing modules for most of your needs.

It's really in the Unix philosophy:

Write programs that do one thing and do it well.
Write programs to work together.
Write programs to handle text streams, because that is a universal interface.

Honestly, there are a load of Python framework these days, but i really like the work of the pocoo's team (jinja, pygments, sphinx, ...) so another of their product must be good.

Using Flask i could implement what i needed for this micro-blog in a couple of hours and a handful of code lines.

Why do i care about sloc (source lines of code)? Well, more code means more to read if you have to hack it, usually a larger memory footprint, etc.

The central enemy of reliability is complexity.
— Geer et al

I'm wondering if the ever increasing size of Django is not begining to make it the new Zope (393k sloc by the way), plenty of brillant ideas but too much bundled together, getting complex while trying to do and simplify too much.