Ask HN: Django or Rails?

10 points by cryptography ↗ HN
For anyone who has experience with both frameworks, when would you prefer one over the other? I am comfortable with Python & Flask, so I gravitate towards Django, but wanted to know if I am missing out on something. Cheers!

28 comments

[ 2.7 ms ] story [ 66.7 ms ] thread
Interestingly, I'm learning Django right now because of enough bad experiences with Rails. This may sound obvious but if you don't do things the Rails way then you'll have a harder time taking advantage of what Rails gives you. Some things which I consider essential to web development are not included with Rails but available via gems which I think are unfortunate: session management, authentication and administration. The model files don't contain any information on the schema like you would expect. You have to dig into the schema file in order to find that. The documentation is bad for Rails and the Ruby ecosystem in general. Lots of magic...
So is RoR something like Flask[0] which provides you with basics and all other bells and whistles (e.g. ORM, Forms, Admin, Auth, etc..) are available via extensions?

[0] http://flask.pocoo.org/

Not at all. The ruby equivalent to Flask is Sinatra: http://sinatrarb.com

Rails and Django are equivalent to each other from the sense of providing an MVC based framework to build a web application.

Sinatra[1] is more like Flask. From your list Rails has an ORM (ActiveRecord) and built in ActionView form helpers, but no default admin interface or authentication. The standard authentication library in the community is usually Devise[2]. What ‘etc’ includes is difficult to comment on :)

[1] http://sinatrarb.com/

[2] https://github.com/plataformatec/devise

No. Sinatra [1] is more like Flask.

Rails has session management, forms, ORM, and simple authentication all built in (as well as asset compilation, schema migrations, websockets, asynchronous processing, file uploads, etc). Models do not contain schema definitions, they're defined elsewhere. Admin functionality needs to be added.

I've got some experience in Python at this point if I were to build a new CRUDy business app I would use Rails because of my familiarity with Ruby and Rails. If I wanted to learn more Python as a main goal I'd pick Django.

[1] http://sinatrarb.com/

Django is not the best solution if your goal is to learn Python -- it simply has too many magic going on underneath, and some of their solutions are convoluted due to its specific architecture and backward compatibility requirements.
> This may sound obvious but if you don't do things the Rails way then you'll have a harder time taking advantage of what Rails gives you

> Lots of magic...

The same is largely true of Django as well.

In fact, it's stronger with Django. Rails (because of Ruby) is more flexible in the right hands.
I'm curious, what makes Ruby more flexible than Python in that context?
> Some things which I consider essential to web development are not included with Rails but available via gems which I think are unfortunate: session management, authentication and administration

You must dislike a lot of web frameworks

> The model files don't contain any information on the schema like you would expect

What schema information were you expecting?

Is there a reason why you are considering only those two?
These are the most popular ones: which means more tutorials, more StackOverflow questions & answers, more people involved (i.e. won't vanish in 1 or 2 years). However, I am open to other suggestions.
Ive been very intrigued by Kotlin. As a language it's nicer than either Ruby or Python. Don't be turned away by the fact that it runs on JVM, there will be a native, LLVM based backend. The killer feature is that you can transpile Kotlin to JS so you can write your backend and front end in one language. You can also integrate with all the front end frameworks. Here's an official sample app based on React https://github.com/JetBrains/create-react-kotlin-app

Another nice thing is that you have a good IDE for Kotlin. Kotlin is by JetBrains, the same people that built PyCharm and IntelliJ.

It honestly depends on what you're trying to achieve with your work.

If you're trying to build something, then use Django. It'll save you time from having to learn about Ruby's community of tools and how Rails works.

If your goal is to learn Ruby, then using Rails will be fine.

Neither is better than the other and I've used both. It comes down to what you personally enjoy using better as they are both built to be generic tools to create a web application using a specific language.

Don't get lost in the marketing hype of which is better - use the tool that allows you to solve your problem more efficiently (creating something vs. learning a new language and framework).

I've used both professionally on large and small projects. Both work fine, but the have a pretty big philosophical difference.

Rails emphasizes writing as little code as possible by having a lot of "magic" that you are supposed to know about by convention. For example, almost every object is available globally with no require statements. Also, model objects automatically have methods on them for every column present in the matching database table - you don't list out the model fields in code. There is also a code scaffolding system that generates what little boiler plate code is needed to add new pages.

Django takes a more explicit approach. You have to import controllers or helpers you are using. Models have actual code that define the schema. There is no codd generator system.

In general, I think Rails is faster to get something running from zero. You can build a functional site in like 30 minutes. They really nail single developer productivity.

On the other hand, Rails sites tend to turn into a big ball of unmaintainable memory-sucking spaghetti if you have a big team working on them. There's just too much "magic" and hidden interactions going on.

Django gives you the tools to avoid that, but it also prescribes less about the "right" way to do things so there is still plenty of opportunity for your app to get bloated or terrible if you do it wrong.

IMO, Rails is much "nicer" in terms of quick productivity and sanded down edges and working solutions out of the box. Just look at how much easier basic stuff like compressing css/js is in Rails than Django. Django is more an assemblage of disparate parts that work together, more or less.

But while both work fine, I'd choose Django because Python is a much more popular language to find a team for and I much prefer explicit over magic in the long run. But that's just me.

tl;dr - Rails is the artsy kid and Django is the engineer.

Neither. Use Python and a solid Web framework -- I would recommend Tornado, but Flask is quite OK. You don't need a full solution that will keep you locked in to its specifics, like Django -- and all its components are available as separate libraries, arguably even better: SQLAlchemy for ORM, Flask-Admin for admin, Jinja2 for templates.
What year is this?
I note in the comments that you are open to alternatives.

I'm familiar with both Django and Rails. I leaned on Rails for years – starting at the pre v1.0 day. Today, I prefer Phoenix (the Elixir framework).

You also mention in the comments the use of StackOverflow. Elixir Q&As live elsewhere on https://elixirforum.com/, which is very active. All the "senior" members of the community hang out there and routinely answer questions. Even Joe Armstrong, who designed and implemented Erlang is active. There is also an active Elixir Slack.

I still have personal projects in ruby, but none in Rails; all the survivors use Sinatra and Sequel (a far better alternative to ActiveRecord).

For small projects, any of these frameworks will suffice. However, once you need additional services, such as: messaging; background processing; server-side state (e.g. redis); crons; monitoring and self-healing; etc. then Elixir and Phoenix shine brightly.

Phoenix and Elixir are great. The negatives I have are: not a comparatively large community, not many companies using it, and it doesn’t have the breath of options via package management that frameworks like rails have.
I remember the rails' community on usenet when it was like that :-) However, both community and packages are growing quickly. Package and installation management is very flexible via mix and asdf.

Anecdotally, I'm seeing an increasing number of ruby shops becoming ruby + elixir shops.

There’s a long way to go
I'm in it for the long run. It deliver today and can only get better.
I'm on the django side, but why is there more rails jobs than django jobs?
It depends what you want to do in the future.

If it’s to be a full stack dev or backend in a startup then Rails is good. They are slightly more startups that start with RoR and after +3 years of Rails I can tell you you have everything you need to do any website or web app with it.

If you want to do other things like machine learning or go in a big company then Django is a good option. Python is used a lot in ML with flask for Restful API and Python is often used as a scripting language in complement of a more low level language like Java in a big co.

Laravel is also similar and catching up and php version 7 isn't that bad.

I prefer rails because:

1) I love the community and the gems (I always find everything I need)

2) I feel that the decisions of the core team are the right ones and they are still innovating in the small details

3) Finally and most important, because of ruby. Ruby in my eyes is much more expressive.

When I do something in rails I feel like that's the right way to do it (I am a rails developer for about 8 years now). Maybe my brain has been wired too much with rails but everytime I tried to do something in laravel, django, or even phoenix, it just couldn't cut it.

I think it is a matter of preference than anything else.

> but everytime I tried to do something in laravel, django, or even phoenix, it just couldn't cut it.

Why?

If I were you I'd still stick with Python ecosystem, just because you say you're comfortable with Python & Flask. When you come to Ruby right from Python 'it feels the same, but different'.

You won't lose anything if you stay with Python/Django stack without touching Ruby/Rails. I believe the number of jobs available for Django and Rails developers is more or less equal if we talk about that point specifically.

But if your goal is just self-education, then why not give Ruby a try?