Hacker News new | past | comments | ask | show | jobs | submit login
A Django Developer’s Views on Rails (loopj.com)
46 points by foobar2k on May 28, 2009 | hide | past | favorite | 38 comments



"Python vs. Ruby (Perl’s Ugly Sister)...This makes the Ruby syntax look like someone emptied all the symbols from the keyboard into a shotgun and shot them into your face."

It's amazing watching the python web development community develop, nurture and encourage so much mindless trolling. It has turned reddit completely septic and now this garbage is on the front page here? Sigh.


"It's amazing watching the python web development community develop, nurture and encourage so much mindless trolling."

Where are you seeing this? There are a fair number of Django and Python posts on HN and this is the first I've read that I can remember any such trolling.


"on HN"

Indeed, but even here it has been increasing. This made it to #2 within a half hour of posting. Even watching this thread you can see people driving through down modding even mdasen's post. Another recently popular blatant nonsensical anti-rails/pro-django troll that comes to mind was the "Magic Sucks, Django Rocks!" submission: http://news.ycombinator.com/item?id=596833


What the hell are you talking about? This is ONE article written by ONE person and suddenly it's the Python community's fault for allowing it to exist? Spare me.

This victimization technique should added to the list of Logical Fallacies, if it isn't already there.


The article was meant to address transition points from django to rails not start a flamewar. I was never encouraged by anyone to "troll", this is from my personal experiences. There's no conspiracy theory here.


As a pythonista who likes ruby, I think your "Perl's ugly sister" comments were a shot in the foot and detracted from the rest of your argument, which concentrates on rails and has little to do with Ruby itself.


Frankly, I'm quite used to see this kind of trolling spam about Perl.

You could answer by asking after specific problems with "Perl Best Practices" or what can top e.g. Moose, but language wars (+)? I AM able to grow a beard....

This group of scripting languages seems really similar in functionality and usability today (so if I change environment, I'd probably go functional). The large difference seems to be in the cultures around them...

(+) I'm all for editor wars, of course! :-)


Oh come on, it was funny.

You need to lighten up a bit. He gives points on both sides. I do only Ruby and I get what he means.


What does he mean then?

I've looked at quite a bit of Python and Ruby source code and Python uses square brackets, periods, mathematical symbols, parentheses, and colons in similar ways. Indeed, a method definition in Ruby uses fewer symbols (no need for the colon on the end, or even the parentheses, although that's against common Ruby style). Python even makes nonsense like using double underscores in method names obligatory. Or how about Python's obligatory parentheses on all method calls?

How is Ruby really more "line noise" than Python? Seriously. Sure, Ruby allows you to be more lax than Python and write poor, "line noisy" code, but good Ruby is no more "line noise" than good Python.


ruby uses < (less than) for inheritance; also regular expressions start & end with / (slash). you have %W, %w for arrays and %q, %Q for string. things like "class << self ..." looks weird to those new to ruby. also stuff like "a ||= ...". and of course pre-pending '@' for instance variables and '@@' for class variables.

also when i use regexps in ruby i then say "/re(g)ex/ =~ 'string' && $1". in python that would be multiple statements: "m = re.match('re(g)ex', 'string'); m.group(1)"

in python existing syntax (or more familiar syntax) is used to accomplish all the above.


I never use %w for arrays and I never use %Q for strings. After years of schlepping through Python's regular expression support --- support not dissimilar from the regex support C++ has --- /regexes/ are a gift from god.

Also, your Ruby vs. Python regex examples aren't even equivalent.


Sigils on variables are a good point. This is an area where I think Python wins out. Dependence on "self" all over the place is irritating at first but ultimately quite comforting - especially when you wonder whether you're going to screw up your attributes when you use the same name for a local variable in your Ruby method ;-)

But on inheritance - you have to put the class name in round brackets in Python, no? That's 2 characters to Ruby's 1.

Stuff like a ||= shouldn't be considered Ruby-specific noise as Python also has the same idiom as in a += and a -=, just not with ||. || is arguably noise over "or" but it shouldn't seem like cryptic noise with any sort of experience of C, C++, Java, JavaScript, or almost any other mainstream language.

Further, that Ruby code of yours does seem more Perlish than Rubyish, but I suspect this is because Ruby style is gradually shifting away from Perl-like styles to more idiomatic approaches. For example, I'd probably choose 'string'[/re(g)ex/, 1] or if I was trying to be "proper" then something like m = string.match(/re(g)ex/); m[1] (or potentially use Regexp#match, but I far prefer String#match). I see those solutions more typically than those you present - and the latter is quite like your Python example - but.. TMTOWTDI and that's Ruby's greatest asset :)


I took him to mean all the built in special variables, like $$ and $! and $?. I don't see them too often in Ruby, but I'm pretty sure the language supports pretty close to Perl's full set. Not a great argument though, unless most of the Ruby I've seen isn't really representative of the whole.


Django vs Rails is like Old Navy vs the GAP.

Lisp web development is haute couture; sure, we might need to travel to the ends of the world to fetch silk, velvet, safron and red dyes, feathers of griffins, and we might need to raise our own albino beavers and translucent-neon chimps to harvest for leather, but the end result is a gallant style fit for a high princely court. (It might also involve a slight invasion of neighboring states to capture their sartorial secrets.)


"Lisp web development is haute couture"

ie, not actually intended for people to use.

Well played!


It's up to you to take the red pill, or take the chill pill ;-)


Old Navy and the Gap are owned by the same company.


Thanks for the info, it only supports my argument for their strong similarity: the vast syntaxful conspiracy is real ..


What does this article say that hasn't been said before? This stuff just isn't interesting anymore.


What this article says to me is:

1) there exists multiple frameworks that are independently excellent

2) some of the best minds in both worlds have nothing better to do other than to take sides in meaningless discussions


some of the best minds in both worlds have nothing better to do other than to take sides in meaningless discussions

That and some unsubtle flirting with language wars and trolly word choice is exploitable for linkbait and HN karma.


Sorry Pythonistas, but whenever you say that having "only one way" to do something is a good point (and many have said this), you sound like religious nutjobs.

There's more than one good and obvious way to do anything worth doing, be it giving birth, building a bridge, adding two numbers together, or developing algorithms in a programming language.

I like Python on many levels - particularly the indentation - but the religious-ness of the philosophy and language design is off-putting in so many other ways.


> I like Python on many levels - particularly the indentation - but the religious-ness of the philosophy and language design is off-putting in so many other ways.

I think you're overgeneralizing from a single misquotation. I've rarely encountered dogmatism from pythonistas, as most of them are too busy getting stuff done.


Well, for me, it is a good point. For some reason it's just much easier for me to remember a particular language's way of doing something when there's only one way.

Also, I'm a little obsessive about my code consistency, so I dislike having to remember that I've been using Array#size instead of Array#length, for instance.

Now, these are obviously not necessarily applicable to anyone else. However, I do feel like I can say that having only one way to do simple things is a plus, without being a "religious nutjob". Which is kind of inflammatory of you to say, by the way.


There's a big difference between a person stating an opinion or a preference, as you have, and a community standard being defined and defended to the hilt. The first is choice; the second is religion.

People who blindly defend Python's wacky standards as some sort of community issue are the religious nutjobs, not people like you who merely have a personal preference.

So, no, you're not necessarily a religious nutjob. But, yes, it was meant to inflammatory; people who blindly defend groupthink deserve to have their cages shaken from time to time.


> having "only one way" to do something is a good point (and many have said this)

I've heard this said often but never actually witnessed it in Python. There seem to be multitudes of ways of doing all sorts of things. The other day I wanted to execute an external process and capture it's output. 5 minutes of research with Google and dozens of alternatives before my eyes and oh my ... how do I choose?


It is fairly easy to avoid symbol soup in ruby.

First, don't use global variables. I'm perfectly OK with global variables sticking out and looking ugly.

Second, use the English module packaged with Ruby if you find yourself using Perl-like special global variables a lot. I very rarely use them and so never need to use the module.

Finally, use accessor methods to work with instance variables instead of accessing them directly. This also makes it easier to add logic to handle your instance variables without having to rewrite or break any code.

If you follow these three steps alone, you will have about the same amount of symbol soup as you would in python, which is almost none.

(By the way, I am also a fan of both python and ruby and think they are both great languages).


> the developer is forced to keep business logic and complex constructs separate from the markup

Nothing I like better than having options taken away without any upside!


In the Rails world, the layer which generates the final markup sent to the browser is called the View layer. In a Rails View, you can chuck as much rails code as you like in amongst your markup.

Some of the early sites I worked on many years ago were written in PHP, which had the same idea.

Um. . . Sure, you can put any logic you want in a Rails template, but people don't. Rails applications tend to have a nice separation of layout and application logic. Django really likes to constrain users here - not even letting them use a full "if" statement. It's really unfair to just say Rails == Unmaintainable PHP. PHP often becomes that way because there is no immediate way of separating the code. Smarty and others can force you, but both Rails and Django put a really obvious place to put your app logic and developers tend to respect that. Part of this is just how much rope do you give a developer and it's fair to say that one shouldn't give developers that much leeway. However, it's wrong to just equate the two.

Multiple Apps in a Project

Really, neither framework (or any code) is as pluggable into random situations as we programmers would like. The author suggests that you can use models from different applications in Django. That sounds cooler than it is. They're all running off the same database and in the same project. Really, what Rails creates are projects in Django-speak. And the "apps" convention in Django doesn't help you in development. It helps in organization sometimes - especially the admin interface - but it isn't some spectacular thing where you can just reuse random code in a way that you can't with Rails. Well, I take that back, there is one way that is really nice: namespacing. You can have a blog app that has an Entry and Category model without having to name it BlogEntry and BlogCategory because it would conflict with your Category model for, say, a real estate part of your app. And that is helpful in a way that Rails doesn't solve nicely. However, for the most part Rails and Django provide decently equal utility in this area, they just name the things differently.

URL Routing

Django's routing is really verbose. You have to specify each route you want. Rails has a bunch of shortcuts for common cases (REST as well as :controller/:action/:id). In a way, this is just the explicit vs. implicit thing. Django makes you explicitly state your URLs while Rails will let you state them, but you don't have to should you like the defaults. The Django folk say that it takes very little time to write routes (true) and that one should be thoughtful when making URLs (also true). But sometimes it just feels tedious. Really, it's just a matter of preference.

Ruby (Perl’s Ugly Sister)

This is kinda low at some points (why I went to it last - I don't like dwelling on such poor arguments). Ruby doesn't actually use that many symbols ala Perl. All variables are done without symbols; I think strings built as "#{var} is cool" are easier to understand than "%(var)s is cool" % {'var': var}. And it isn't like Python doesn't have weird things like "/".join(list).

Really, my beef with Ruby would be how easy (and common) it is to add methods to ancestors without really making it clear. As you start adding methods to Object, you can get yourself into a position where Python's explicitness is really nice. However, when you want to get something done, Ruby can be nice in that respect. It's like having a circular saw: really good for both cutting wood and cutting your hand off. Likewise, Python's mixins are put onto attributes of the model - so that you have things like house.photo.url rather than house.photo_url (although Django did create the second for a long time). That makes it very clear what you're adding while if you say "acts_as_nested_set" in Rails, you don't immediately see which methods are being added.

Ruby's problems aren't really syntactic, but it can have things that one could define as problems.

--

I've put out two sites in Django and one in Rails and at this point I'm developing two projects in Rails. The Django community is really smart and understated and I still read a lot (smart information translates well to anything), but Django just doesn't see the same pace of development that Rails does. Even something simple such as following reverse foreign keys isn't implemented in Django. Yep, if you try Entry.objects.all(select_related="comments") it will just silently fail (how's that for letting errors pass silently that shouldn't!). And it is difficult and Malcom has way more on his plate than any normal person could even conceive of, but. . . it's still missing.

And the Rails community has calmed down a bit, the Merb camp seems to be adding nicely to Rails 3, the Rails framework covers so many more edge cases than it used to as well as just seeming more reliable, and deployment has really stepped up with Passenger.

Django is a wonderful piece of software with great features and really smart, considerate people using it. It just isn't seeing as great a push toward little simplifications for more edge cases in the way that Rails has been. Frankly, they're so much alike in all the meaningful ways - I think that's why I have such an easy time wrapping my head around both.

Eh, I have to get dinner.


"Django really likes to constrain users here - not even letting them use a full "if" statement."

Yes, but as you've noted it's for a good reason. This is really one of the few places where Django gets opinionated by default, and personally I'm OK with that; keeping people off the slippery slope of "well, I should write this in a cleaner way, but for now I'll just stuff some application logic in the template and fix it later" is a goal I can get behind.

"The author suggests that you can use models from different applications in Django. That sounds cooler than it is. They're all running off the same database and in the same project."

Not really. I can have multiple different Django "projects", each running its own settings, its own database, its own URL configuration, its own templates, etc., but all using the same single copy of an application module somewhere on the server. Last I checked this was non-trivial to do in Rails, while in Django it's made very easy since it's a common use case, and encourages neatly abstracting/encapsulating common pieces of functionality for reuse.

"The Django folk say that it takes very little time to write routes (true) and that one should be thoughtful when making URLs (also true). But sometimes it just feels tedious. Really, it's just a matter of preference."

Personally, I tend to view this more as a security concern than a programmer-convenience concern; if my framework is auto-mapping URLs to any code it can find, it may auto-map some things that I didn't want to expose (this was the source of an exploitable vulnerability in Rails a while back, as you may remember). If the framework only handles the URLs I tell it to handle, I don't get that situation.

Mostly, though, I like Django because it (and Python) fits my brain.


If people don't agree on the IF statement, they just don't agree on it. I find that I can discipline myself enough to use a full IF - having always used the pyif (http://www.djangosnippets.org/snippets/130/) template tag in Django. I don't think this is such a big deal since one can swap out the templating layer in both Django and Rails for something they'd rather. If anyone reading this sees this as a big point, Liquid in Rails offers a more Django-like experience and Cheetah will give you things like full IFs in Python.

You make a good point about not having to copy the code into the project directory and have multiple pieces of code sitting on the server. Someone pointed out that Rails Engines (included in 2.3) allow for this, but I haven't personally used them to know how nicely they work.

For the security concern of auto-routes, this is actually a bigger concern in Python than in Ruby just because of the different ways that they handle OO stuff. In Python, everything is a public method. So, if Django just mapped URLs to methods, there would be no way of hiding a method you didn't want called. Ruby has the ability to make private and protected methods and Rails only makes public methods available as actions (the private and protected ones still being able to be called in their scope).

So, it isn't a great security concern in Rails since it's trivial to define what is public and what isn't. Likewise, if one chooses, you can decide to map all of the URLs explicitly like Django and turn off the default :controller/:action/:id route. So, Rails offers both ways.

Just as a note about Python: Django could just auto-map URLs to any method not starting with an underscore (the convention used in Python to say, this is kinda private even though Python will let you use it). Or there could be a kwarg (keyword argument) in the method signature that Django looked at. Anyway, there are ways around the fact that the Python language doesn't have explicitly private methods. Django's convention (like Python's) is just that explicit is better.


"If people don't agree on the IF statement, they just don't agree on it."

Pretty much. And while individual cases can be argued, I think the general goal of keeping program logic out of templates is a good one.

"For the security concern of auto-routes, this is actually a bigger concern in Python than in Ruby just because of the different ways that they handle OO stuff. In Python, everything is a public method. So, if Django just mapped URLs to methods, there would be no way of hiding a method you didn't want called."

Actually, what I'm thinking of is a case where you might have a single application running on multiple sites, and -- for security reasons -- there'd be some views that you wouldn't want exposed on one or more of those sites. Forgetting to "un-map" even a single URL could lead to major problems (and, since an auto-mapping system can, in theory, locate anything that's on the import path, the risk seems to me to be a bit too much to accept just for the convenience of occasional automatic URLs).


"Yes, but as you've noted it's for a good reason. This is really one of the few places where Django gets opinionated by default, and personally I'm OK with that; keeping people off the slippery slope of "well, I should write this in a cleaner way, but for now I'll just stuff some application logic in the template and fix it later" is a goal I can get behind."

Pretty sure Rails, via some plugin, lets you easily use Liquid templating in place of erb. Likewise for Ramaze and Merb.

If you want constraints, they're easy to add.


>Django's routing is really verbose. You have to specify each route you want. Rails has a bunch of shortcuts for common cases (REST as well as :controller/:action/:id). In a way, this is just the explicit vs. implicit thing. Django makes you explicitly state your URLs while Rails will let you state them, but you don't have to should you like the defaults. The Django folk say that it takes very little time to write routes (true) and that one should be thoughtful when making URLs (also true). But sometimes it just feels tedious. Really, it's just a matter of preference.

Don't forget globs. They're freaking awesome.


>Multiple Apps in a Project

Also, don't forget that this is solved problem in Rails 2.3 with the use of engines. So, really this claim is plainly false.


Skimming through before bed, but:

"Even something simple such as following reverse foreign keys isn't implemented in Django"

Yes it is, it's very clearly documented here:

http://docs.djangoproject.com/en/dev/ref/models/querysets/#i...

Not much you say about Django is very accurate, actually. Maybe someone else can point out the specifics, but I'm going to bed..


You've linked to the documentation about following foreign keys, not reverse foreign keys.

So, you have a blog with entries and comments on those entries. A Comment has a ForeignKey to an Entry. That's a normal setup. In Django, you can say Comment.objects.select_related("entry").get(id=5) and that will get you the comment with id 5 and its associated entry. However, you cannot say Entry.objects.select_related("comment_set").get(id=12) to get the blog entry id 12 with its associated comments.

Don't believe me? Well, believe core Django core contributer Malcolm Tredinnick - the lead of the database refactor effort. http://groups.google.com/group/django-users/browse_thread/th...

There are a lot of people who use Django that don't realize this limitation exists because they haven't gotten that deep in their usage of the framework.

On a personal note, in the future I would appreciate it if you didn't attack my truthfulness with statements like "Not much you say about Django is very accurate, actually."


There are many ways of doing the same thing in Ruby? I guess that's true to some extent but I'm not really sure why it's a problem?

['cat', 'dog'] %w[ cat dog ]

Although these are not technically the same ... lambda { } proc { } Proc.new { }

string.match(/regex/) string =~ /regex/

object.is_a?(Thing) Thing === object

hash.merge!(hash) hash.update(hash)

Anyways, I'm not a Python programmer, but I can say (with regards to Ruby) when you are used to the language it feels right.

Why can't we just all get along and not troll the shit out of each-other?




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: