Wednesday, July 19, 2006

Django's pretty cool

I've been hearing a lot of buzz about Django lately, so I decided to download it and check it out. Django is a Python-based web application framework for quickly building web applications. And baby, it is hot. I'm really impressed with this product.

Django does out-of-the-box most of the stuff that I spend time building from scratch in PHP. You define what your data model is, and you get intuitive accessor classes and an admin interface for free. And its method for responding to server interactions is downright brilliant, using a Model-Template-View triad that brings all the benefits of Model-View-Controller but none of the cruft.

My only gripe with Django is that, as with most such products, it was a pain in the ass to get installed. I ascribe to the philosophy that you shouldn't have to type esoteric commands into a terminal window to get software installed. I guess I'm just spoiled by the Mac, but if you have to write an installation guide for your software that doesn't start with "Double-click the installer...", then I have to be pretty committed to try out your product or else I'm going to not bother. (Luckily, in the case of Django, the installation pain was worth it.)

I'm also new to Python as a language, but it seems pretty nice so far. It has some language features that I have always missed from other languages, such as being able to just name the arguments when you call a routine, like so:

choice = models.CharField(maxlength=200, core=True)

Objective C has a feature like this, but oddly, you don't name the first argument - only subsequent ones - which always seemed presumptuous. How does the language know that there is only one "natural" object for a method to work on?

Python also leaves off a lot of the extraneous syntax that most languages require, like trailing semicolons and such, but this nicety is counterbalanced by case sensitivity, which I really dislike in programming languages. If I type "post" when I should have typed "Post," the language shouldn't look at me like an idiot and go "huh?" Making a semantic distinction between "post" and "Post" is a bad idea. If the two things are distinct semantically or conceptually, they should have different names.

One curious aspect of the language, to me, was the idea that indentation has literal code meaning. I spent a good fifteen minutes trying to debug some code I typed in from the tutorial before I realized the whole code block was tabbed over one stop too far. Not sure whether I like that or not yet.

5 comments:

Anonymous said...

Although I definitely agree that Django could stand to be easier to install, I'm not sure how it could be as easy as "Double click the installer..." Since most of us have to install it remotely onto a Unix-based server for which we don't have access to a GUI, I think shell commands will always be part of the deal (unless it could be made entirely web-based, but I'm not sure how that would work, either).

I always was put off at first by the indentation rules of Python, but have come to love them. Several things about Python seem to force me to beat as neat and lean as possible, and even if that's annoying at first, it seems like it can only be a good thing in the long run. The funny thing is that I (as someone who is mostly a designer, not a programmer), find myself now being incredibly anal about the indentation in my HTML and CSS, even though it has no meaning there. Python has corrupted me!

CC said...

Holy crap, Jeff Croft posted a comment in my blog!

Thanks for taking the time to post, Jeff. It was mostly your blog that led to me to Django and convinced me to give it a whirl. Keep up the good work - your blog is always an interesting read.

Regarding the installer thing, yeah, remote installation makes having command-line installation a necessary option, but it's still a load of work to go through if you're not even sure you're going to like what you are installing. A .dmg for a local install would have been nice. I guess I was frustrated, because Django wasn't the only thing I had to install to get it working, so I had to slog through a whole stack of "go download this and type these shell commands" sorts of installations, which never seem to work as advertised. For instance, docutils and mysqldb both didn't go nearly as smoothly as advertised in the installation guides, and when something goes wrong, I generally am pretty clueless where to go. It took me hours to get up and running.

But, like I said, Django was certainly worth the trouble. I'm still not sure I'm going to "convert," but I'm certainly going to pick up a book on Python and more closely investigate the language and its capabilities.

Anonymous said...

CC,

Check out the magic mirror they got here:

http://www.shinyshiny.tv/2006/07/magic_message_m.html

Victor

Anonymous said...

Hey CC,

Richie here.
There has been a lot of hype about something
called "Ruby on Rails": Ruby is the language,
Rails is the Web system based on it. Supposedly, it is VERY easy to build web systems with databases from this. One "enabling feature" is continuations (which is basically just a functional goto ... most people means "closures with the continuation", but noone other than language lawyers care about that) that supposedly make it easy to keep state.

My understanding is that Django is a comparable system, except that it is obviously Python based instead of Ruby based. I prefer Python, only because I know it well at this point, so I am curious to hear how your Django work goes.

The O'Rielly "Learning Python" book is pretty good if you are looking for a good text.

As for the indenting to show structure: most programmers do it anyway for non-trivial code , so it's really easy to get use to. I like it.

Python is a great language, it interfaces easy with C (well, it has a well-defined API), and a great user community. The interpreter is what keeps me coming back for more.

CC said...

Yeah, I was actually looking at Ruby on Rails, too. The work I've seen from the 37Signals guys has been pretty impressive, and Mac OS X is a pretty good dev environment for it, apparently. IconFactory just switched over to it for their basis, and several other interesting sites have been singing its praises, too.

After tinkering with Django a bit, although I was mightily impressed by it, I unfortunately came to the conclusion I just don't have the time to learn a new language / development environment at the moment. (Especially when I realized I'd have to figure out how to recompile Apache with mod_python in it without messing up all the standard stuff that Apple handily automates for me through software update.) Moving to Ruby on Rails has the same problem.

I'm pretty quick at PHP development, and I'm getting to the point where I have best practices and handy, reusable codebases in place for rapid, stable development. And the server I'm going to (hopefully) be migrating our web applications over to supports PHP and doesn't (yet) support Django or Ruby on Rails. So I think I'll have to put off exploring these dev frameworks until some later time.