Rails, Cake and Django

I've been having a close look at web frameworks recently. As my programming has matured, I've gone from spaghetti and hacking right through to well-structured, modular programs and I'm now religiously keeping my logic separate from my design. I see web frameworks as the next step in this evolution. Frameworks allow you to take advantage of other people's work (and that has to be a good thing!). If you work within the framework's parameters you can program your application with very little code. You will end up with a well-structured program that is simple, and easy for someone else to work out what you have done.

Here's some more detail on what I've found so far.

Things web frameworks have in common

  • Create a directory structure for you
  • Abstract database access so that you hardly ever have to write sql
  • Use the Model-View-Controller pattern. A well known design pattern for creating applications that separate logic, design and input.
  • Scaffolding - which creates data access methods for you to test your structure (this is a really neat feature - check out any of the frameworks to learn more).
  • AJAX / Web2.0 support

Rails

The framework that's in everyone's face at the moment is Rails (or Ruby on Rails). Its a framework written in the Ruby language. Yes, that's Ruby - not your everyday language for most web programmers. A nice language yes, but the fact that it is not one of the mainstream languages makes me nervous right away. I know at some stage my code is going to be handed over to someone else who probably knows PHP, Java and heck might even know some Python, but they are probably not going to know Ruby. Not a problem (the Ruby people cry) - its easy and can be easily understood. Yes, I'm sure that's true, but it still worries me.

There are some great demos and video tutorial available on the Ruby on Rails website. As much as anything, they are an advertisement for frameworks rather than any particular one. As the supporters of the other frameworks point out, there is nothing inherent in Ruby that makes for a good framework. A framework can be written in Java, PHP, Python, Perl or whatever. If you hunt around, every framework has a tutorial that shows you how to build a (blog|poll|guestbook) in only (40-70) lines of code. Its true that a good framework is built around Object Oriented programming and that's true of Rails as well as the next two frameworks.

CakePHP

CakePHP is a framework written in (you guessed it) PHP. It does many of the things Rails does, but it is written in a language more familiar to the average web programmer. Most people will find this easier to install and get your head around than Rails. I ran through the tutorial and was impressed with how easy it was to get an application running.

CakePHP is not the only PHP web framework. In fact there are over 40 PHP frameworks modelled on the MVC pattern. Its a harsh world out there and it will be interesting to see which ones survive.

Cake seems to me to be one of the more mature implementations of a web framework and its real strength is that it has a strong community with contributed modules and that is is written in PHP. Some people see that as a weakness - PHP has a reputation in some circles for being insecure, but that is more about how the program is written rather than than the language itself. Using a framework goes a long way to helping make a program secure.

I also like the name - it lends itself to lots of references to baking.

Django

I've saved the best until last :) Django is a framework written in Python. For many people, this is just as big a turn-off as using Ruby, but let me tell you, Python is gaining in popularity and is more often than not installed by default on your typical webserver (i.e. a linux server running apache). I can't really tell much of a difference between Python and Ruby. They are both really well thought out languages that are easy to read and make maintenance a breeze.

Django comes from the world of on-line publishing an newspapers where new web apps need to be written very quickly and be able to take sometimes massive loads. Django has been proven to work well in this environment. Django is not entirely simple to install - you'll probably need root access to your server, but once installed it flies. It has its own test server written in python built in, which makes prototyping application very simple.

Another drawcard of Django is that it can create an entire (very nice looking) admin interface with only a couple of lines of code. This is something that would normally take a long time to write and is used by just about every application. Not having to write it yourself makes for rapid development (which is what its all about).

Finally, I like the name Django. Its from Django Reinhardt one the great Jazz guitarists of all time. While the name lends itself to other references, it can get you into trouble - from the Django weblog:

We've changed the default session cookie name. Instead of "hotclub", it's now "sessionid". Intended as a reference to the Hot Club of France (one of Django Reinhardt's bands), "hotclub" had been misinterpreted by some people as having some sort of porn-site meaning.
Oh, well. Wit and obscure references only go so far.

Final Comments

A good review of Django v. Rails can be found here.

All these frameworks are relatively new and will no doubt develop further (at the time of writing all of the above were only just at, or nearly at 1.0 releases). They are getting attention for a good reason, they allow programmers to create quality applications with fewer lines of code and no-one can argue that's not a good thing.

Also worth a look

There's some good info around out there. This article about drupal as an MVC framework is interesting. Also turbogears is another framework for builing web apps in python (have not checked it out, but looks like it is worth a look).

Edit: A lightweight php framework that I have started using in some projects is codeigniter. It has almost no learning curve and excellent documentation (how often do you see that!) Its real strength is that is pragmatic - it is simple but powerful. As a relative newcomer it has a smaller community, but I expect to see this grow. Definitely one to have a look at.

Links: CakePHP | Rails | Django

reply

The (probably) best webframwork ever? Does it exist? Since I tried Google's new webtoolkit I am convinced that GWT is the way to go. That's probably the big winner. Even Ruby on Rails looks outdated if you ask me.

intermedieri imobiliare (not verified) – Tue, 2008 – 04 – 15 22:36

Nice writing.

I really appreciated the contrast between the frameworks, many thanks!

I hope you don't mind a couple of suggestions for easier reading:

s/than than/than
and
s/publishing an/publishing and

Best regards,

Chris

Chris (not verified) – Sat, 2007 – 02 – 10 15:03

Post new comment

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
The content of this field is kept private and will not be shown publicly.