Thursday, October 1, 2009

So, Why TurboGears, Why Not ___ ?

I've decided to skip out on the "Why Linux?" question. If you have to ask, you won't agree with my answer. If you already agree with my answer, there's no point in preaching to the choir.

Instead, I'd like to address a simpler question, and one that is in some ways more important than the choice of OS, or choice of editor, or even choice of IDE. That question is the choice of which web framework to use.

I'm not sure how many posts this will become since there are so many things that can be considered, and so many comparisons that can be made. Should I choose C, Java, Python, Perl, Ruby, PHP? Struts? HTML::Mason? Django? Ruby on Rails? Smarty? Plone?


I could probably fill several screenfuls with nothing but lists of choices. When it comes to frameworks, we can find one that suits your taste every time. If, by some miracle, we can't, you can always roll your own, too. That's just the nature of the beast.

Since all of that would be boring, I'll instead focus this series of posts on why I chose TurboGears, and why I think you might like it as well. For today, I'm just going to focus on a very high level view of why. Tomorrow I'll start into nuts and bolts comparisons to show why TurboGears works best for me.

It's no secret that I'm a fan of Python. I feel that the syntax is clean and readable. The community promotes the idea of doing documentation and unit testing, both of which are items I strive for in my own code. Using those, the code tends to be more complete and produce fewer bugs.

Since I enjoy working with Python, that meant I should find a web framework that would let me use Python. I went through a couple of them before TurboGears was suggested to me.

I worked through the 20 minute wiki tutorial, and I was hooked. I knew that, even though I didn't know everything there was to know about TurboGears, I could understand the framework. It clicked for me. I can work with this.

As a set of feature highlights, consider this:
  • It uses SQLAlchemy to manage the database. This provides the ability to use (a)raw SQL, (b)SQL constructs (without using raw SQL, but giving nearly  the same flexibility), and (c)an Object Relational Mapper. I'll not dig into the advantages of this, not yet, but I will point you to a blog posting from Chris Perkins on it.
  • It uses Object Dispatch. This lets you register a class instance as handling a segment of your URL space. The exposed methods on the class instance become your URLs. It's delightfully simple to manage what your URLs will map to because of this. Again, Chris Perkins did a great job with more in-depth discussion of Object Dispatch.
  • Flexible choice in templating language. If you prefer validating XHTML, you can use Genshi. If you prefer raw speed, you can use Mako. You can add your own renderer, too.
  • Flexible choices in JavaScript library. If you see one you like, you can arrange to have it available on every page of your application easily.
The list goes on and on, really. You get features on features that you never knew could be useful mainly because you never thought of them. And yet, here they are, making your life as a web developer easier.

Since I found TurboGears, I've become hooked, and have started working on their docs, trying to help them be more complete, and letting the core devs work on the core code even more. We all know how much docs suck, but at least I can do something that will help them not have to focus on them so much.

Now, if only I could somehow talk them into making a Firebug equivalent for Internet Explorer, that would make all the web development so much nicer. And, while I'm dreaming, I'd like tomorrow's winning lottery numbers, please.

1 comment:

joshua said...

Nice article, Michael. TurboGears is really a great framework (and don't forget Elixir for database handling :-).

I don't know if you're aware of this, but there actually is a Firebug equivalent for non-Firefoxes. It's a bookmarklet and works very well inmost situations. You can grab it at http://getfirebug.com/lite.html .

Have a nice day & weekend!