55 points · by argonaut · 13y ago · 78 comments
Some factors to consider beyond just the design of the frameworks: productivity, readability, documentation, activity of community, tooling, ease-of-use/learning, etc.
I've purposely left out node.js and its associated frameworks (Meteor, Derby, etc.) because AFAIK the field is still wide open and node.js has different use cases.
But if you were to listen to me, I'd probably be saying something about how they're basically equivalent these days. Both are pretty productive, have clean readable code, are well-documented, have active communities, a wide array of plugins and tools, and are fairly easy to use.
If you were to get even crazier and try to get some advice on which you should use, I'd probably tell you that Rails is best if you already know Ruby; Django if you already know Python. If you don't know either, take a week or two and build a site with both and see what sticks. Either way you'll be pretty happy.
But you shouldn't listen to me because I'm heinously, terribly biased, so you probably didn't hear me say any of that. Just as well.
If only we were all this talented.
This is exactly what I did when I was trying to decide between the two. It really doesn't take long to work your way through the introductory tutorials to get a feel for which framework and language you prefer.
I'm absolutely sure that there are many developers out there that can pick these frameworks up that quickly, but I'm equally sure that there are plenty of developers who "aren't that talented".
I you like Python and it's Zen, use Django. Otherwise, use RoR.
One example is model definitions — in Django, the canonical definition of a model's database schema is in an app's models.py file. I'm still not sure where to look for this in Rails.
Additionally, other tools you decide to use with Django don't require any extra "Django magic" to work — they work the same as they would if you used them alongside any other tool.
One example is using Less with either framework. Using Less's `less.watch()` functionality, which enables live updating in the browser based on changes in your .less file, is much more difficult to use in the Rails asset pipeline, in my experience.
There's pretty much feature-for-feature parity at this point, and where it doesn't exist there's a plugin or other supplemental tool. For Django, pip, south, and django-mediasync cover for bundler, migrations, and the asset pipeline (sort of). And of course there's a rails admin gem.
But these are the same tradeoffs that have always existed, and I don't think any of them have changed in the new versions.
db/schema.rb has that.
> Using Less's `less.watch()` functionality, which enables live updating in the browser based on changes in your .less file, is much more difficult to use in the Rails asset pipeline, in my experience.
I have found that to be difficult too. It think it's because Less has fallen out of favor, and SCSS is the new standard. It's actually super easy if you're willing to use SCSS.
You mentioned Django plugins providing an asset pipeline. Do you feel that it's easier to start supporting a new asset type in Django's pipeline than in Rails'?
I think the schema.rb file CAN be used to build the database though... I'm trying to remember. I feel like I've done that before.
This is good and bad. Good because it saves the developer from describing something that's already described in another area. Bad because it takes away a bit of control.
My Django apps had a bunch of legacy tables that I was forced to sit and document. I had to remember to go back and add another line every time I added another field. But, to be honest, it's pretty much the same way with most other frameworks I use.
You can also run rake db:schema:dump at any time. So it works great with a legacy database. You don't need to run any migrations for this to work.
Eh, I don't know, Twitter bootstrap users don't appear to agree. I know it's fallen out of favor for DHH, but I don't know if that's generally true.
> You mentioned Django plugins providing an asset pipeline. Do you feel that it's easier to start supporting a new asset type in Django's pipeline than in Rails'?
No idea, because I've never tried to do it, but the one I was referring to seems to make it pretty easy: http://sunlightfoundation.com/blog/2011/01/20/django-mediasy...
Yeah, that's all I mean. I agree that it hasn't necessarily gone away in the larger sphere. Just that the Rails community has moved to a different default, so LESS gets harder to use.
I personally am glad, though. I find SCSS more powerful. See, for example, the if statements and loops it gives you:
http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#co...
For another example, around the time when Rails made the switch, I started running into serious problems using media queries with LESS, whereas they've always worked great for me in SCSS.
Rails pluses:
- Has a nice asset pipeline (automatic conversion of CoffeeScript, Sass, Haml, Jbuilder, etc) and concatenation + mignifying.
- Really configurable database migration with a nice DSL. (Django has South which auto generates migration files, but It isn't just as easy to change them)
- Rake tasks (Django also has management commands, but It's easier in using rake)
- multiple environments (development, production, testing), being able to store different configurations (Django does not have this, you can achieve this using some hacks)
- Railscasts.com (great screencasts by Ryan Bates)
- Better release circle, as long as I know in Django didn't appear many features since 1.0 (mostly bug fixes and Python 2.x deprecation warnings)
- more OOP than Django, it really follows MVC pattern, Django is a MVT (Model View Template framework)
- More libraries and more complex and configurable than django libraries. Most Django libraries handling authentication stick on default User class, so it's difficult to subclass it if you require custom fields.
- Model hooks and scopes (I know django has model hooks but they are built using Django signals, not using nice DSL as in Rails)
- Concerns inclusions which guides you to a clean coding style.
- Controller before_filters (very useful when you want to run a filter before multiple actions, eg: check if user is logged in), I know it can also be done using Django middlewares.
Django pluses:
- Django admin (Rails also has a few plugins which try to implement this, but django's is built in and also well documented in their official docs)
- Django built in authentication system (Rails comes with devise library and other alternatives, which is great but not built in)
- Easier to learn (Django follows Python's Zen, "Explicit is better than implicit.", all classes or methods you use must be imported, Rails pollutes global namespace with all classes and namespaces imported from libraries when Gemfile is parsed). It is easier to learn which module each class comes from and it helps you a lot at debugging if you are a begginer.
- Django middleware (you)
- Form based validation (each model can be validated using form class, another minus for Rails is that there was some security vulnerabilities targeting mass assignment on Models)
> Better release circle, as long as I know in Django didn't appear many features since 1.0 (mostly bug fixes and Python 2.x deprecation warnings)
A lot has been added since 1.0, including multi-db support, admin actions, aggregates in the ORM (and other ORM improvements), class-based views, and many other features that I can't think of off the top of my head.
One benefit of Django that you are leaving off your list is general stability, in the sense that the Django team is obsessed with ensuring backwards compatibility between major releases. My understanding is that the Rails team is willing to break backwards compatibility with a frequency that can impact people negatively.
> Most Django libraries handling authentication stick on default User class, so it's difficult to subclass it if you require custom fields.
This is changing in 1.5, the release of which is expected soon.
> More libraries and more complex and configurable than django libraries.
Honest question: how many of these Rails libraries implement things that are implemented in the Python standard library? In other words, are there more Rails libraries because Ruby itself is less complete than Python?
I'm glad to hear they are fixing the annoying bug in 1.5.
About libraries, Python follows the idea that there should be only one way to do something, ruby follows the idea that there should be more ways to do something, this is why there are a lot of alternatives, for example:
Testing: rails built in, rspec, minitest, test-unit, bacon, etc JSON Generation for views: jbuilder, rabl Memcache: memcached, dalli
And many other gems have more than one alternative, which I think it's nice.
I think you're stretching the meaning of this a bit beyond it's intent. It applies to more low level things than testing or JSON generation. The standard library does have a lot of excellent (and almost default) choices but it doesn't stop people from making alternatives.
This has been fixed in the upcoming Django 1.5. I don't want to argue with you, just point out this tiny detail.
Yes, there's SciRuby, but they aren't quite there yet.
Think about the whole language ecosystem. Django is just Python.
SO has 165,076 post tagged for Python. Just 65,706 for Ruby.
P.S. We are hiring Python/Django devs in SF. Email me if you are looking for a gig :) You get to work on a open source this project : https://github.com/iontorrent/TS/tree/master/dbReports
On the flip side, RubyGems is much bigger than PyPI and has a lot of modules that you won't necessarily find equal counterparts to in PyPI.
I think there's a lot of use cases one can come up with where one language's library offerings suit them better. That was how I chose between Ruby and Python. I chose Ruby+Rails but it very, very easily could have been Python+Django.
I want to make some comments on writing APIs in particular, since I've been doing a lot of it lately, as my projects almost always have several interfaces these days, e.g. native mobile apps, angular.js web frontends, and as I mentioned above, fat clients running on kiosk hardware.
Building json apis in rails is a pleasure. My mini stack inside of rails is controller -> request handler -> model layer + external services -> rabl. Very clean, few lines of code, easy to maintain, does exactly what you want.
Doing the same with default django is a little less obvious. Tastypie is cool but when you get much beyond providing CRUD over the web to your models, it gets messy. Forget nesting stuff more than one layer deep. In the end, I build a controller layer that matches the way rails works and it's just about as nice, but I have to know and follow the conventions myself.
In particular, i'm copying rails style validators for models, I've built something similar to my rails request handlers using django forms to handle input, and i've built a simplified controller layer that handles routing, paging, filtering, sorting, etc. Instead of rabl, I just write a to_dict function to package data into a response. not quite as slick, but roughly equivalent.
I had to do more on the django side to get there, but at this point both are equivalent for me in terms of building APIs.
I understand that these days there are compelling arguments for building APIs in neither of these languages. However, for speed of development, ease of also putting up a vanilla web interface, and richness of the ecosystem as a whole, I still like django and rails for building mvps.
thanks for the recommendation, will check it out. I got deep in the guts of tastypie and wasn't happy with the way it handles patching and nested objects in particular.
For my kiosk project, as an example, I need to send a nested object graph over the wire. The wifi card in the kiosks isn't very reliable, so doing it in one call is very helpful (only one thing to retry a couple times, vs 10-ish objects, max depth of 4).
From what I can tell, django-rest-framework is read-only beyond one level of depth (you can return a nested hierarchy, but not post it in one shot)
Also, some of my objects are transient (e.g. credit card data), so I don't have a django model for each object that is an input to the api. (I have a plain old python class with some special magic for parsing track data, validation fields, etc for credit card and drivers license in particular, can't ever save that data to the db).
would you use django-rest-framework for that?
(also, is there a django equivalent of ActiveAttr, which lets you make ruby classes that act like active record objects without the persistence? or would you just make models and never save them? probably wouldn't look so good in an audit though)
1) I find Python code easier to read and 2) Rails seems to evolve a bit too fast for me. I find it easier to keep up with Python frameworks.
Django and Rails are almost the same age. Rails is only a year older, which doesn't mean much after so many years have passed.
The numbers of Google search results for "Python Django" and "Ruby Rails" are on the same order of magnitude, with Rails having around 50% more. Likewise for "Rails site:github.com" and "Django site:github.com"
The differential is bigger on Stack Overflow, with Rails having about twice as many tagged questions. They're still on the same order of magnitude.
One could of course do a feature-by-feature comparison, but I don't find those particularly useful when looking at frameworks. That's because a framework is a long-term investment. You're not just buying into the current or upcoming version, but all future versions. (Unless you make the expensive choice to switch.) If one has a feature that turns out to be really useful, there's a very good chance the other will acquire that same feature soon enough. Especially considering the size of the Django and Rails communities.
Will Django 1.5 or Rails 4 will change the balance significantly? My guess is not. It's like an arms race: One side or the other may claim the advantage from time to time, but with plenty of smart people working on both, cross-pollination should ensure that they stay fairly comparable.
All that being said, I prefer Rails (largely due to Ruby) and am quite happy with it. Though if I were doing scientific computing, I'd take into account what bayesianhorse said.
It's also worth considering that the whole paradigm underlying Django and Rails, wherein you render a bunch of HTML with your choice of backend language, may not last forever. With the client side getting heavier over time, the advantages of sharing code across client and server may push the mainstream away from Ruby and Python. Or not. This isn't a prediction; more like a "what if."
From that perspective, one thing that Django has going for it is the Django REST Framework (http://django-rest-framework.org/), which is pretty great. Of course, it's probably the case that Ruby has something similar.
But even without the HTML templates--even if you're just serving up JSON or XML or whatever--you're still stuck with one language on the client and another on the server. What I'm really curious about is whether the advantages of having a single language on both client and server will ultimately outweigh all other concerns for most web projects. I have no idea what the answer to that question is.
I think this is a product of the speed at which Rails develops - it is more likely that a Rails book will be outdated by the time it is finished than a Django book.
Ruby:
- indeed.com - 507
- monster.com - 66
- dice.com - 96
Django:
- indeed.com - 242
- monster.com - 30
- dice.com - 65
Edit: formattingEdit 2: Though you could argue that Ruby is mostly used as Ruby on Rails, while you could search for "Python" jobs if you have experience with Django.
Edit 3: what is with the downvotes? If you want to learn a new framework whether you can get employment is something to consider.
Consider maybe, but becoming an X developer is usually not a great idea, for just about any value of X. So, if you want to do Webdev, why not be proficient in both to maximize your chances?
It is also very painful to make asset pipelines work in Django (SCSS & CoffeeScript compilation and minification). There are various solutions which require various amounts of tweaking, and which can break in unexpected ways on SCSS syntax errors etc. In Rails, all this just works out-of-the-box.
And lastly, Django's app ecosystem is very tied into the Django ORM data model, which is currently very tied into MySQL/Postgres. If you want to use MongoDB (with MongoEngine), most existing Django apps won't work with it. On the Rails side, Mongoid is an established ODM, and there are existing gems to make most things work with MongoDB without any tweaking. This means you will have the email/password/Facebook authentication (Devise/Omniauth), RailsAdmin, CanCan permissions etc. working right away, and your whole web app can run on MongoDB if you want.
So, even though I'm a long-time Django user and fan, I think it just hasn't kept up with the times. Nowadays Rails works better and is more productive for typical new web projects. (But realtime/single-page-apps are a different story, there I lean towards Derby&Meteor.)
How swappable are the core components of Django?
Flask http://flask.pocoo.org/ is pretty awesome and I've used it for a project that was really light on server-side code (http://palettecomp.com/), but I've never used Sinatra so I don't know how it compares.
Although you can build a product using any, Django is out-of-the-box more useful for building publishing platforms or content-heavy sites, while Rails is more about scaffolding and REST APIs.
There are also the obvious differences between the language stacks, libraries available, etc. This may be more important than frameworks themselves, which are mostly glue logic.
If you already have a preference between Python and Ruby, for whatever reason, then your choice is probably already made. If you don't, more important than attempting to build something in both -- which won't really help unless it's something real-world and in-depth, which is unrealistic -- might be to consider the languages themselves and decide which better suits the way you think/code.
Of course, if you have a specific project or set of projects you're looking to build, reviewing the available libraries for the languages and frameworks as well as their maturity and prevalence would be important.
If you're wondering which suits you better as a long-term time investment, reviewing the community and the doc/misc websites surrounding both frameworks would be a good idea. People are pretty opinionated about those particular communities; trying to decide which you find more helpful or have an easier time gleaning information from and/or interacting with could prove valuable in terms of deciding which language/framework would work best for you.
I guess this is a long-winded way of suggesting this is the wrong question; it just isn't meaningful. You could attempt to compare them on all sorts of metrics, but despite their similarity of purpose, I think you're likely to find your own subjective review vastly more useful than anything else.
[edit: This is also intended as a mild indictment of the question, as specifically disqualifying other mature web language/framework combinations does everyone a disservice, though to include them all would make the question even less meaningful.]
I'm a huge advocate of JRuby. It's Ruby for the JVM. Consider the fun of getting to write Ruby, and the joy of knowing you can deploy to anywhere with a JVM. I'm not a Windows fan by ANY stretch. I do all my development on my Linux laptop... but the powers that sign the checks think Windows is swell. So consider where you'll be deploying.
Substitute 'bundle install' for 'pip install -r requirements.txt' and it's basically the same thing.
I think there are more rails jobs than django jobs, at least the type of job I want, and especially in my geographic area (North Carolina).
I feel like the ruby community is much larger, much vocal, and many of the startups I actually buy stuff from use ruby.
I imagine the tooling is pretty compatible, but I'm not that familiar with the ruby world. At the startup I used to work for we deployed django on heroku much like one would do in the ruby world.
The whole Python 2 / Python 3 incompatibility issue was one of several reasons why I decided to focus on learning Ruby and Rails instead.
Although I understand that mentality and share it on some level, that was a bad way to make that decision. If you write Python 2.7 and avoid things marked deprecated, you are nearly compatible with Python 3 by default.
Besides, this one isn't Django's fault.
Confused. It seems, and I'm happy to be corrected, that many new Rails versions deprecate, often with little notice, even core components. Or am I wrong?
I'm not entitled to talk about Django but that's my perception...
There was a really funny comment in a thread like this back then that impersonated Rails saying "New Ruby version? let's deprecate everything!"
and Django going "On the weekend we're gonna discuss making Django compatible with the 5 year old Python"
And then someone said "What I like about this comment is that it pisses off both sides of the table"
:p
I like Ruby's terseness. Fewer keystrokes is a win for me, especially when you have a shit keyboard (pardon my french).
Django feels very CakePHP-y, if that makes any sense?
QUICK DUMB EXAMPLE:
Django:
from django.db import models
class Person(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
Rails: class Person < ActiveRecord::Base
attr_accessible :first_name, :last_name
validates :first_name, :length => { :maximum => 30 }
validates :last_name, :length => { :maximum => 30 }
end
---Which is simpler to type, ergonomically speaking?
edit: Well when I started replying, you were well into the light grey and with no reply.
Your example, Ruby has 26% more characters (194 vs 154).
"I found that they make heavy usage of symbols such as [, ] in code."
Your example, 3 sets of parentheses, 4 equal signs, 4 underscores, one colon in Python.
In Rails, 2 sets of braces, 4 assignment operators (=>), 10 colons, 4 underscores and a <.
I guess I'm not seeing either the brevity or heavier use of symbols in your example...
class Person < ActiveRecord::Base
attr_accessible :first_name, :last_name
validates :first_name, length: { maximum: 30 }
validates :last_name, length: { maximum: 30 }
endIf you have a shit keyboard, treat yourself to a nice one, I bought a mechanical one for 50€ and it is pretty damn good and I plan to keep it forever.