Blog of Jeff A blog about programming and random other things.

28Mar/09link

Rails and Django

Notice: As with all people, I have a bias. Mostly towards python over ruby. Keep that in mind ;)

Ever since the release of Ruby on Rails, shortly to be followed by Django, programmers always compared the two to determine the ultimate question: "What is better?" But this is purely on personal preference. It's like comparing apples to oranges. People like each for different reasons that can't be summed up for everyone.

Rails and Django were both extracted from other projects, but each project weren't identical. Rails was originally part of basecamp, which is a ajax web application where as Django was extracted from lawrence journal world. Both focused on different parts of the development process.

Rails was initially developed by one person (David Hansson), to be an "enjoyable experience" for creating web-based products. These includes reasonable defaults and a more restrictive design for the user of the framework. This improves productivity by reducing the brain power used for making petty choices (such as where to store source code file x). But like any good framework, if you truly wanted to do it differently, you can with a bit of tweaking. Since Rails was part of basecamp, it is particular efficient at rapid development for user-generated content (not by some admin) and simplifying repetitive and tasks. An added benefit of Rails is its integration of the prototype / scriptaculous javascript frameworks. Although if you don't like prototype, there are implementations for other frameworks in the works. However, due to Rails' erb templates uses functions over just plain html when possible, the prototype integration is much stronger. I feel myself viewing source for my own applications to get ids that Rails generates for custom javascript.

Django was created by three people (Adrian Holovaty, Jacob Kaplan-Moss, and Simon Willison) for "perfectionists with deadlines". This is more of a traditional websites framework. Since Django was born in the media world, where sites and content need to be completed in hours, Django tries to assist in automating as much as possible. Backend admin pages are automatically provided and common data fetching practices are simplified as much as possible without compromising restricting the developer to the confines of the framework. Since Django was designed for outputting content, it's not as efficient for generating Rails-styled user generated application (although still possible). Django's templating system tries to minimize the amount of magic which leads to more manual html code. And as you can expect, it lacks integration with a particular javascript framework. Also, since the Django admin is nearly completed automated, it's more difficult to make changes to the interface and definitely not tailored for end-users. But, the templating system is friendlier to designers who never used a programming language before.

That sums both frameworks up. Which should you choose? If you rather not deal with javascript code that much but intend on using bits and pieces here and there, use Rails. If you have a lot of content to manage (maybe not by you), give Django a whirl. If you have a language preference, go with the corresponding framework, although I strongly recommend to investigate the other language if you haven't already (See "The Blub Paradox" section of "Beating the Averages").

  • Share/Bookmark
  • Coming from ASP.NET, using Rails was bliss. However, I quickly started to notice things about Rails that bothered me, starting with Rails' conventions. Rails is also very monolithic. It's very difficult to encapsulate an application module such as a blog. There's so much "magic" in Rails that it's hard to understand what's happening behind the scenes, and the documentation, for lack of a better word, effing sucks.

    Rails has come a long way in the past couple of years, but it's JUST NOW starting to work the way Django has worked since the beginning. Encapsulating app modules, including routing, views, etc, nested forms - all baked into Django since 0.96

    Add Django's admin module and you just solved probably 95% of your use cases for editing content. It will save you an unbelievable amount of time.

    When you compare the amount of code, workflow and results, I simply don't understand why anyone would choose Rails over Django, unless you just enjoy writing admin screens, logins, file uploads, form validators and everything else Django does out-of-the-box.

    Don't let a lack of knowledge of Python stop you from getting started with Django, it's very English-like, with very minimal syntax and tons of built-in goodness. Django has the lowest learning curve of any framework I've used in the past 13 years as a professional web developer. Python is every bit as elegant and clean as Ruby, and is a hell of a lot faster to boot.

    Happy coding!
  • My response was too long -- see the post http://blog.jeffhui.net/2010/02/djangos-flaws/
  • Hello,

    Would you happen to have some examples of how Rails is faster than Django for developing a user-generated-content-heavy website? This is the type of app I'm looking to build, but have already invested some time in learning Django. I'm trying to decide if it's worth it to explore Rails before continuing on with heavy development.

    (FWIW, I'm currently brand new to both Python and Ruby. I've been picking up Python and would need to pick up Ruby if I were to switch to Rails.)
  • Unfortunately, I can't provide examples myself, but most real world applications of these frameworks are similar to their original purpose.
    - Django is used by everyblock, washingpost, torontolife (and was extracted out of one)
    - Rails is used by twitter, tumblr, github, lighthouse (and was extracted out of basecamp)

    From these examples and where the frameworks originated from, Django is usually used to aggregate or publish information while rails apps are usually from user-generated content.

    Rails is slightly faster because of its scaffolding feature which generates some html as well as the model-interaction code when you can then tweak to your own liking. The one downside is rails doesn't provide its own user auth system, but there are plenty of plugins that implement that.

    Django uses generic views to help automate CRUD operates that rails scaffold provides, minus the html generation. But if you need more customization that the generic views provide, you kind of have to hack around the blackbox or implement it yourself, although the generic views are pretty customizable. Also, Django does provide user auth built-in.

    It's not impossible for Django to work with user-generated content (pownce) or Rails to work on publishing-styled sites (yellow pages), it just wasn't originally designed that way.

    Personally, I'd recommend checking out Rails a bit to see if you like developing in it (create a simple blog app or something). I always prefer something I enjoy programming in since the productivity boost will outweigh any minor benefit of productivity the other framework provides.
  • Thanks. I wish this had come out a few weeks ago! From the research I found up to that point, everything was fifty-fifty. I ended up going with Django because I have a built-in support group for it (i.e. family and friends who work in Python). If I had realized the benefits that Rails provides for user-generated content, I would have swung that way instead.

    As it is, I guess I'll take a look at Rails, as you suggest. I'm hoping to get a first cut application up and running by this summer though, so I'm not sure what it would take for me to make the switch.

    At the very least, it will be good to get a deeper perspective of the tradeoffs.

    Thanks for writing this up!
  • I'm curious to know what benefits Rails provides for user-generated content? Especially when Rails doesn't even know how to validate a form field unless you tell it.
  • No problem and good luck with your project :)
    - Jeff
  • Name's spelled wrongly for Simon Willison.
  • Dunno how I misspelled that. It's fixed now. Thanks :)
    - Jeff
  • My thoughts :) Nice summary
  • Thanks :D
  • Alen Ribic
    The thing that stands out for me in Django is it's strong non-monolithic approach to application development, following the Unix philosophy that reads: "Write programs that do one thing and do it well."
    I have many small, very specific, applications in my my Django site that can be very simply plugged in to any other site that may need those features. (Django sites are somewhat like unix shell pipes in a sense that they are used to solve complex tasks using different combinations of tiny programs.)

    On the note of lack of javascript framework integration in Django is true, however, how difficult is it really to integrate a javascript framework such as JQuery? From my experience, really strait-forward. If one refers to actual client-side components that get generated in form of javascript and html, Django has some nice open projects that already today provide custom tags to do things such as filed autocompletion, client side form validation, etc. Also, for instance, I have a custom tag for flash notes. I plug that custom tag in to all my sites that need flash notes.
  • Alen Ribic
    Oh and one more thing regarding the javascript framework integration in Django, or lack-of it, has been discussed many times on Django dev group. Answer pretty much is: Django marks it's territory as the server side. Core developers have consistently rejected any attempt to bind Django to any specific javascript framework such as JQuery, prototype, etc. Hence admin site uses plain javascript for clients-side works.

    So its left to the developer to either integrate her/his own javascript framework of choice by writing his own code or making use of open django projects that provide these solutions.
  • I personally prefer to write my own javascript, but I'm presuming there are people that wouldn't want to bother learning javascript for simple javascript behaviors (which rails provides).

    I never bothered looking into apps that provided a js-framework functionality for Django. I'll have to look into that. Thanks :)
blog comments powered by Disqus

Recent Posts

Topics

Archives

Following

Links