Categories
Technology

Rails vs Django vs Play: Battle of frameworks

rails-vs-django-vs-play

This post is a review of those three frameworks considering four criteria: Ease of learning, Speed of development, Tools/Plugins, and Community.

Right from the start I banished PHP from my possible choices. I know that “sufficiently talented coders can write great applications in terrible languages” (Jeff Atwood), but I just don’t like PHP, probably because of its syntax, and I’m not the only one. You can find a lot of ____ vs PHP comparisons online, and you’ll see that the challenger always win – except for legacy reasons. And the main challengers I’m talking about are JavaScript (Node.JS), Ruby (Rails), Python (Django) and Java (Play).

My objective was to create a platform similar to StackOverflow. Although everyone suggested me to go with Rails, I chose Django. Our relationship lasted four sad months and I broke up before finishing the prototype. So I moved to Play Framework and achieved the same functionality in two months with less frustration. Finally I switched to Rails and implemented all that and much more, finishing the prototype in less than half that time – 22 days. Looks like everyone was right in the first place.

This post is a review of those three frameworks considering four criteria: Ease of learning (programming language, documentation, tutorials), Speed of development (programming productivity), Tools & Plugins, and Community.

Django

Django uses Python, known for its simplicity and indentation rules, which makes it a good language for programming beginners. The Zen of Python advises that “there should be one, and preferably only one, obvious way to do it” and it should be well documented. Since my Q&A website just required the basic functionality of every dynamic website – create user, authenticate, post question, make comment, cast vote – I guessed there would be plenty tutorials explaining how to implement the basics using the one right way. The official documentation exists but it won’t be enough if you’re a beginner at dynamic web development. Sometimes it assumes you know something and skips an explanation that would help you understand the big picture. Doing Codecademy’s python course also helped me get a grasp on Python’s syntax and semantics but that’s like learning the abc. You might want to watch these video tutorials.

I installed Django on Windows: bad move. It was a long and painful process, requiring multiple small tweaks to silence the errors. I sure hope the process is a lot smoother on Linux. After having a hard time installing and configuring Python + Django + WAMP + Aptana Studio (IDE) I was ready to code. I followed Django’s official tutorial (v1.4 at that time), a walkthrough to create a “site that lets people view polls and vote” which suited my initial goal after some customization.

Django uses MTV (Model, Template, View) instead of MVC (Model, View, Controller), so Django's Templates == everyone else's Views and Django's Views == everyone else's Controllers. Your main application is composed of modules; actually your app is also a module. So you create your app, you give it an innovative name Contoso, and then you’re forced to create a module – where the actual code will be placed – but with a different name. Sigh. Instead of ContosoForReal let’s call it ContosoMainModule. After you look at Django’s folder structure you start to get anxious. Your Contoso app folder only stores the url routing file (urls.py) and the global settings (settings.py); Your ContosoMainModule folder contains the models (models.py), the controllers (views.py), yet another url routing file (urls.py), and a folder named templatetags. So where would you put the templates? In the same folder next to the model and the controllers? templatetags is a good candidate for that. Nop, they’ll be placed outside ContosoMainModule, side-by-side with your app folder Contoso at templates\ContosoMainModule, see for yourself. Sigh.

Indentation is a big thing for Python, in fact your code won’t compile if your code isn’t properly formatted. If you didn’t know you’ll find out pretty soon, after you start getting compile errors with cryptic error messages. Time to turn on the whitespace highlighter and search for that naughty tab or space (just don’t mix tabs with spaces!). Sigh. The whole time it looks like you’re fighting a battle with the framework, to see who controls who. You have to specify everything to the last detail; seriously I had to search how to auto-increment an Id primary key, why isn’t that a default?

The only tool I used for Django was an IDE and it didn’t help me much. I used Aptana Studio which is basically an Eclipse distribution optimized for web technologies. Although Aptana is great for HTML/CSS/PHP, its Django support is weak: no syntax highlight for Django-specific files (only Python) and the auto-complete rarely completes anything. When you’re still discovering the framework and its API, an auto-complete would be a precious help. Sigh.

Thankfully, the community exists, both on StackOverflow and Google Plus, and is there to help you. All my questions and doubts were always answered in time. In one year Django went from 1.4 to 1.7, thus the core development team is pretty active. Also there are plenty of modules (plugins) for your applications available online, but some are more plug’n’play than others. There were so many authentication modules I couldn’t choose which one to use. I tried to use a voting plugin. I ended up creating my own. There should be one obvious way to do it. Sigh.

tl;dr developing on Django is an exhausting symphony of sighs.
– ★★★☆☆ Ease of learning
– ★★☆☆☆ Speed of development
– ★★★☆☆ Tools & plugins
– ★★★★☆ Community

Play

But wait, why should I learn Python+Django from scratch when I could leverage on my Java skills and use them for webdev? So Play Framework came to the rescue. Right away, I removed the effort of learning a new programming language. Besides I always enjoyed programming on Java. The quantity of official documentation was similar to Django’s (ok maybe less) but it was more comprehensive and dummy-proof. “Zentasks” is a tutorial that guides you on the process of creating a website for task management. It’s so much better than Django’s approach: here you start the tutorial with a clear tangible goal; content is presented incrementally and logically; and plenty information and examples are provided on what you need to do and why.

The environment installation was so much easier (on Windows): JDK + Play + Eclipse + Config %JAVA_PATH%. Simple. My typical workflow was opening two command lines (one that automatically compiles the project after each change and another that acts as a local webserver), change the code on Eclipse, refresh the page on the browser. Simple, no more “how do I do ___ on Python…”, just think and code it. The folder structure makes a lot more sense: an app folder with a separate folder for models, controllers and views; a public folder for static content; a conf for configurations and evolutions for database migration files; a test folder for tests. Simple.

Play’s template system to avoid boilerplate is really useful and it looks a lot like inheritance. Each template may receive inputs and define “blocks”; those inputs are used to fill the dynamic parts of the template (like the user’s name); and those blocks can be implemented or overrided by other templates that extend the original template. Simple, powerful, and coherent since you’re using Java/OOP concepts across the framework. The only problem I faced was ManyToOne and OneToMany relationships. I was trying to code a tag system, where I could get from a Tag all tagged questions and from a Question all of its Tags, so One Question has Many Tags and One Tag has Many Questions. I never managed to make it work like I wanted.

Developing Play or Java on Eclipse is great, the syntax highlighting and auto-complete just works. You also have access to all those Eclipse plugins that make your life easier (github integration, checkstyle, findbugs, etc.) Having the possibility to develop JUnit tests is also handy, and coherent once again, but I didn’t really had the time to create them.

I tried once to deploy my Play application on Cloudbees and it wasn’t straightforward. The problem had something to do with a configuration, since my app was using a local database and I had to create another rule for the remote database. Cloudbees’ support helped me a lot but before we could fix the issue I moved to Rails. Have a loom on how you can deploy your app

tl;dr perfect if you know Java and want to develop web applications, it just works.
– ★★★★★ Ease of learning
– ★★★★☆ Speed of development
– ★★★☆☆ Tools & plugins
– ★★★☆☆ Community

Rails

There are so many great places to start learning Ruby and Rails. 99% of what you’ll ever need is documented online by the community; I only visited the official docs to check specific the signature of specific methods. First, you should do the quick course Try Ruby, then get a Ruby/Rails development environment, and finally follow every step of The Ruby on Rails Tutorial by Michael Hartl. You also have screencasts available. Ruby has a very natural and concise syntax, so if you’re a programmer used to highly verbose languages (e.g. Java) you’ll take a while to get used to it.

Rails development is blazing fast. Most of this development speed is achieved through auto-generated code that does make some (fair) assumptions. For instance, if you create a `User` model it assumes you’ll need an auto-incremented `ID` to identify each `User`, and Rails takes care of it for you. Model relationships are as easy as User has_many :questions. Not bad. I pretty much followed Michael’s tutorial from end-to-end, since it covered almost everything I needed for my project, so I never really got stuck. And coding tests is the best, it’s like plain English:

describe "after saving the user" do
  before { click_button submit }
  let(:user) { User.find_by(email: '[email protected]') }

  it { should have_link('Exit') }
  it { should have_title(user.name) }
  it { should have_selector('div.alert.alert-success') }
end

Not bad at all! And the template system is even better than Play’s. They have the notion of partials which is just a block of reusable code. So on Play I had to inherit a base template and implement every empty block – hence, the “baggage” of the base template always came attached. Rails uses composition: for example you define a partial that receives a Question ID and displays the voting buttons for that specific Question. Anytime you need to display voting buttons for a question, just <%= render vote_buttons_question, :id => 123 anywhere your code. And partials than call other partials. Do you want to change the buttons’ color? Just change the partial! Nice!

At that time I had given up on IDEs. Michael advised to use Sublime Text and I wanted to learn more about Sublime, so I sticked with it. I lost auto-completion but I gained coding performance, like Sublime’s quick find (Ctrl+P) that saves you from navigating through the folders to open a file just by typing the file’s name. And you can’t place breakpoints to debug your code, I really miss that feature. So sometimes I had to paste my Ruby code online and run it, debugging it via command line. A really handy tool.

And gems just work the way a plugin should work. I needed a voting system: gem 'thumbs_up' + Question acts_as_voteable + User acts_as_voter = done. I needed to encode emails to prevent spam: gem 'actionview-encoded_mail_to'. App monitoring? gem 'newrelic_rpm' Font Awesome? gem 'font-awesome-rails'. Deploy? After the initial configuration it’s as easy as git push heroku master; heroku run rake db:migrate.

This is the power that comes from an active open-source community: somewhere in time, someone had your problem, solved it, and provided a solution for everyone else. Again, find them at Google+, StackOverflow, and on local meetups.

tl;dr Rails enables fast development great for prototyping. The more you use it the more you love it.
– ★★★★☆ Ease of learning
– ★★★★★ Speed of development
– ★★★★☆ Tools & plugins
– ★★★★☆ Community

And the winner is…

home-by-now

Any questions?

34 replies on “Rails vs Django vs Play: Battle of frameworks”

I notice you didnt test against ‘groovy’ which is VERY similar to Ruby, is a layer on top of Java and compiles to Java bytecode. Is this because it kicks Ruby’s ass???

Try JetBrains RubyMine IDE and I can tell you for sure that you won’t even look behind at Sublime Text or anything else.

I hate python. Sigh! Django uses Python so I didn’t like it. Sigh! How many times is the word “sigh” used in this article. SIGH!

Interesting post, but your Django assessment is rather weak. You fell in two basic mistakes: Windows and Aptana. The former is not an OS for development (or any kind of serious work); the later is a Ruby on Rails IDE, not Django. There are then things that do not make much sense, like storing templates outside the app folder or the issue with auto-increment primary keys. I never experienced such issues with Django (but then again, I do not develop on Windows).

These past few years I have used Django, Rails, Vaadin and CakePHP. I would chose Django over the others in most circumstances. Among the four, Django is considerably faster in the model design phase, with the added plus of generating a structurally strong database.

Long term, maintenance becomes the most time consuming task in any software engineering project. By enforcing structural integrity, Django greatly facilitates maintenance and evolution. It is not uncommon for a database managed by a Rails application to reach an invalid state – and that is when problems really start.

Just an addendum: it has proved far more difficult to integrate new team members into on-going Rails projects than with Django. Programmers maintaining Rails code for a first time often complain of code opacity, to them many things seem to happen magically.

It is not entirely clear why it is so. On the one hand Ruby can be rather alien to some folk; on the other some of the “elegance” in Ruby on Rails can easily be the victim of developer idiosyncrasies, often there is more than one way of doing the same thing.

Nice article! But, developer fun is not a deciding factor for developing scalable systems. The most critical metric for comparison of frameworks “performance” didn’t seem to have gotten much attention in this article.

I was curious to know, between Play vs Django vs Rails, what is the QPS we can achieve in each for some typical use cases.

I believe your struggle with django was somewhat self inflicted. I have developed both in rails and django and find them to be about equal in speed, power and ease. I wouldn’t consider myself an elite programmer so if you struggled in django it sounds more like you just have problems picking up that specific framework. This doesn’t invalidate your article or opinion but I think it deserves relegating it to exactly that, just an opinion rather than a thorough scientific study of the two frameworks. I’ve never been developing in one framework or the other and had to throw my hands up in frustration and wish I was in the other one, I can get what ever the project needs done in either. They are both great frameworks and I would chock them up as about equal except that rails has more jobs right now and is the popular kid on the block at the moment, howver node.js is working on stealing that thunder.

It got a mention in your preamble – why did you not consider a node/express implementation? I have found application development can be reduced to days with client-server code sharing and client frameworks like Angular.

That’s a good question but I don’t have a good answer. Node.JS’s benefits of sharing code between client and server makes sense to me – however JS frightens me, that’s it :P

What ? no love for RubyMine IDE? Not free but it’s so much better than sublime I wouldn’t know where to begin

Don’t know about yoel but what I like about an IDE is that is thinks for me and intelligently understands most of the code. After it sees the code structure it is easy to navigate within it, also it is less easier to write jerky code, leaving trash here and there for example. The only price I have to pay is the horse power to make it move, which in my case is not a problem as I need VMs running too.

wow so biast against django, actually I would argue its the best choice due to python and its clean syntax. For Java, I hear Spring framework is a good choice.

Just because you don’t agree with me, you can’t say my review is biased. I gave a sincere opportunity to each framework, using and evaluating which one best satisfied my needs. Finally I provided objective examples of what I liked and dislike about each one. I can’t be more transparent than this.

Hi! U mention that RoR works good on prototypes, I want to know in the case that the app is rlly robust, does RoR still works good, is it the robustest”? I’ve read that Play is the robuster one.. what do you think? Nice blog btw ;)

Diego, do you speak spanish?

Hi,
I want to make an ecommerce website . I want to choose between django,php(raw),asp.net. Assuming that the pages would contain calls to database,jquery,ajax,css which will render fastest web page to client.

help please
.

If you are looking for fast rendering (what I will translate to fast feedback to the client) maybe you should thing about to use a js framework like angular or ember to make an SPA. It makes also easier to communicate with the server through rest. About the speed it is difficult to say without to know the logic but I don’t really think that you will notice the performance difference. About the test mentioned by Diogo (http://www.ubuntu.com/content/matthew-nuzum-quick-speed-test-between-php-and-django), it is just useless since the code is not shown and compare a whole framework (like django) against a raw solution with just a print of hello world is completely unfair not to say sessionless (stateless) against with session (statefull) that requires access to files or dbs

If django is a problem (Documentations, Performance, etc. than Rails ) for Develop Web App, Why a lot of companies uses Django ?

Thanks

Companies have more people and more resources available for projects than an individual. My evaluation was based on someone that wants to start developing Web Apps and has little to no experience (and needs a prototype fast!)

Hi Diogo,

Good article,
I’m curious about if the development speed also was a result of a iterative process of your Q&A prototype, I meant, if you try again the same thing starting with Django, how long do you think it will take to complete the prototype?

That’s a good point Ernesto. I can almost guarantee you that if I was to do the whole project again using Django I would take approximately the same time. I find it less intuitive and more cumbersome to develop in Django. When I have a problem with Rails I just google it and most of the times I find the code I need right away or a nice tutorial explaining it. I just didn’t had that experience with Django

I love RoR is the best one, I don´t like Play because is too verbose (java) it looks like a mess.
And what about all those commands like netbeansify to can load the project on netbeans. :( I dont like it

Well,
Even though the title of the article is about comparing frameworks, I think you ended up comparing the programming languages in which they are based, by using the framework.
Most of the sighs mentioned in Django, are due to Python instead.

I think you gave Django a Ease of learning of 2 stars and Play a Ease of learning of 5 starts because you didn’t know Python and already knew Java.

A machine is as good as the worst part of it, and the programming language is a part of the framework. If I choose Django I’m forced to use Python, therefore Django is as good as Python will be, and probably in that case Python is the bottleneck. I had to review both the framework and its programming language together because the two are inseparable. Play is the only that let’s use Java or Scala.

Every model in Django has an auto increment field called pk for primary_key. Implementing own auto incremental id field is trying to force open door thas are already wide open. IIRC It’s all in tutorial on django site. Messing tabs with spaces is no no for every language. You’re simply biased :) but hey it’s your blog. And I enjoyed the article anyway.

Just as I don’t like PHP, probably Python/Django is not for my mindset. That’s why I tried to detail every problem I faced, so that reader can judge if that’s a generic issue or if it was a caused by my lack of experience and persistence.
Thank you for your comment Bartosz ;)

I don’t know python that well, but I had a wonderful experience using Flask.

From what I gather, Django is an amazing framework, I guess if you don’t know python and how Django works, than I can see the sighs

Now I’m going to have to give Django a go

Thanks for the write up