Why I moved from Ruby on Rails to Python/Django and back
Python, Ruby on Rails, Software development, Startup and business, Technology Add commentsAround March of 2006, I decided to proceed with a complete rewrite of Ajaxwhois.com. I had been studying Ruby on Rails for long enough and knew it would be the ideal platform to develop with. And I was right. While Ruby and Rails might be a little awkward at first for the Java or .NET coder in you, it all really makes sense after a little while.
The behind the scene code generation (aka: magic), the lack of a decent IDE, and worse, of a good debugger made my transition to Ruby somewhat difficult and sometimes confusing frustrating. I used to live in Visual Studio .NET and breath Intellisense. In fact, I still miss that to this day.
Any newcomer to Rails will quickly discover why it is so talked about. First of all, even though I don’t consider myself anywhere near a decent Rails programmer, I am now at least twice as productive with Ruby on Rails than with ASP.NET and C#. Thanks to the MVC (Model, View, Controller), DRY (Don’t Repeat Yourself) and Convention Over Configuration mindset of Rails. All the data access code is automagically generated for you (without running a code generator), templating is built in and creating AJAX’ed applications is a snap.
Life was good with Rails and the more I used it, the more I liked it. That was until early August of 2006. I was ready to launch version 2.0 of Ajaxwhois. Knowing so many professional Rails hackers, I thought deploying my application to my production server was going to be a breeze. I was wrong. Even though the installation of Linux (Ubuntu Dapper Drake 64 bit), Lighttpd, MySql and Mongrel went well, I experienced weird problems, mainly related to Mongrel. Sometimes, my Mongrel instances would simply die and disappear from the process list for no apparent reason. I didn’t have ANY traffic at this point because I hadn’t done DNS transfers yet. On other occasions, Mongrel went crazy and started peaking the CPU at 99%. I had to manually kill and restart it.
After extensive research and countless “from scratch” reinstalls, I found out that Mongrel was known to not play well with 64 bit Ubuntu (I lost the links to this evidence, unfortunately). Mongrel was patched accordingly, but it didn’t solve my problem. It still crashed many times a day and I just couldn’t figure out what was wrong. I asked my good friends Rich Collins and Adam Thorsen (of Guruza.com) who are both experienced Rails developers and they had no idea either. I was stuck.
I wanted to launch. Badly. I didn’t want to waste anymore time with this so I picked up a Python book and rewrote the whole site one more time, in Python using the Django framework this time. I had never programmed in Python before and much less used Django. However, the switch was easy enough since Ruby and Python are somewhat similar.
My experience with Python and Django was great; it is a combination every web developer should consider. However, I soon missed Ruby and Rails. Ruby supports “real” private/public/protected methods (Python just fakes that with its naming convention) and it’s syntax is more forgiving (the need for () at the end of each method call in Python was killing me). Django is not as straightforward as Rails, and requires more code to get things done. There are also many little things that don’t “feel right” in Django, like the need to manually pass variables to a view. Data access is confusing at best while Rails’ ActiveRecord is god-sent. These little things really add up.
On the flip side, Python is faster than Ruby and less memory hungry. I was also surprised to actually love Python’s significant indentation (see example). But more importantly, Python and Django just worked! I never experienced weird crashes like I did with my Rails stack.
So, why am I back to Rails for my next project? 3 letters: FUN. I find Ruby and Rails to be pleasant to use. The community large, active and very helpful. The number of freely available Rails plugins and the fast evolution of the core code are also welcomed additions. Rails requires less code, less self.__awkward_method_calls(), has built-in AJAX and REST support, and has much more flexible data access and templating engines.
But what about those crashes? What about the speed issue? Well, I don’t have the crashes anymore. Don’t ask me why, I don’t know, but it’s fine now, I swear! Something somewhere got fixed and it seems to have solved the problem. However, speed is still one of the low points of Rails. Using caching and proper code optimization should take you a long way, though. Matz, the author of Ruby, is working hard on a new virtual machine that should make Ruby just as fast, if not faster than Python.
My recommendation is, try both for long enough to figure out what works and what doesn’t for you. If you are a long-time Python user, Django might be more compelling for you, but if you are coming from a Java, Perl or Smalltalk background, Ruby and Rails will most likely be what you’ll end up using. Either way, I don’t think you can go wrong.
PS: I don’t want to blame Mongrel for my Rails problems because I am still not sure who was the guilty party. Mongrel is a wonderful piece of software and I heartily recommend it. Just make sure you watch it closely if you use Ubuntu on a 64 bit machine.
January 30th, 2007 at 3:06 pm
I already weighed in on this
http://guruza.com/question/431/reward-65.00/754
January 30th, 2007 at 4:39 pm
Ok, not a bad writeup of his personal experience, but as an avid Pythonista/Djanger, I’d like to point out:
1. Python functions need () at the end: Ok, fair enough.
2. self._awkvardmethod_calls(). I assume he’s unhappy about the first two underscores, as long method names are Good(tm) if you got an autocomplete editor. However: (1) most of Python’s “private” stuff that isn’t part of built-in scope should have one, not two underscores, and (2) if he’s accessing private methods a lot, my guess is that he’s doing something very, very wrong in his code. Or maybe more likely he’s been exposed to too much Java or C#: Python is NOT Java and you don’t program the two in the same style! Hint: The property function would most probably be this guy’s new best friend. Check it out. Also check out iPython, an interactive Python command line. Among other things it’s very good for interactive inspection.
Anyway, an ok write-up, as everyone’s taste is different. Personally I love Python and Django, so I’ll stick to it.
January 30th, 2007 at 4:44 pm
Being one of those that fell in love with Python at first sight, I do take notice of the fact that your problems with Django isn’t something generally true.
Being forced to use parenthesizes with methods and functions isn’t something people normally would be troubled with, it’s probably just because you were used to rails.
The fact that you need to be slightly more explicit in Django is actually considered a feature, since that increases readability and ease of maintenance.
I do agree though that while Python is a pleasant language to develop and maintain code in, Ruby seems to be more focused at being fun. It feels like it lets you be “clever” with your code in a way that Python won’t allow. For better and for worse, I’d guess that part is quite much just a matter of taste.
January 30th, 2007 at 4:53 pm
>Matz, the author of Ruby, is working hard on a new virtual machine that should make Ruby just as fast, if not faster than Python.
… and Perl 6 is coming out next week too.
January 30th, 2007 at 5:26 pm
It’s agood piece of writing. After isn’t the FUN factor that it matters most
January 30th, 2007 at 5:41 pm
I’d like to hear more about your gripes with Django. I use it at work, and I love it. I was using Rails before it reached 1.0 (my todo list tutorial was pretty popular in fact.) However, I had a much easier time wrapping my head around Django, because there is no magic involved. Data access is very easy in my opinion:
city = City.objects.get(name=”Montreal”)
montreal_restaurants = Restaurant.objects.filter(city=city)
Since it’s been a while since I did any Rails, I don’t recall what that would look like with ActiveRecord. The syntax of Python doesn’t really bother me, you eventually just grow used to typing self everywhere and parentheses. As for public/private/protected methods, although I can see why some people like them, I’m not a big fan (must be the Smalltalk background). In Ruby on Rails they are used to separate the views that users can access (those public) from those they can’t. Since in Django you must explicitly associate a URL regular expression to a specific method, you don’t get that problem.
I think you’re right about Ruby being more fun than Python however; Python is great language, and much more fun than PHP or Java, however the hackability of Ruby and the blocks make it really, really fun to use.
I hope to hear back from you,
Vincent.
January 30th, 2007 at 6:20 pm
Vincent,
ActiveRecord looks like:
City.find_by_city(’Montreal’)
or
City.find_by_city_and_state(’Montreal’,'QC’)
January 30th, 2007 at 6:52 pm
I’ve had very similar experiences… really loved rails until I had to start worrying about deployment.
Rumors like this also make me really wonder where the ruby ship is headed. Taking out continuations (one of the more elegant ruby code constructs) because its TOO HARD to implement? Give me a break, Matz.
I’m holding out for either 1) A properly done Rite that doesn’t strip features from 1.8.2, or 2) The JRuby guys to tweak their project to the point where its comparable in speed with CRuby (which isn’t very fast for a C implementation). In the meantime, I’m checking out Django because of its speed, stability, and all of the other cool stuff going on in python right now (like PyPy).
January 30th, 2007 at 7:19 pm
Or if you want to keep continuations, there’s always Common Lisp!
January 30th, 2007 at 7:37 pm
“… and Perl 6 is coming out next week too.”
Unlike Perl 6, Ruby 1.9 and the new VM are in the public SVN and can be checked out and used /today/.
January 30th, 2007 at 8:17 pm
@TomP: Pugs is a Perl 6 implementation which you can already play with. Check out http://run.pugscode.org for something similar to TryRuby
January 30th, 2007 at 11:08 pm
Good read Carl. I think Rails deployment gets better every month or so, literally. More tricks, more articles, more support. While I prefer Rails, in the end it’s likely just a matter of personal taste and style. Ultimately however, a happy coder is a productive coder. So you chose the right answer (for you!). Glad to help power ajaxwhois.com!
January 31st, 2007 at 2:05 am
Perhaps you should have used lighty or apache instead of Mongrel for production deployment.
Personally speaking, Rails fits my mental model like a glove.
Regarding Rails performance, here’s a few tips:
- 3rd normal form DB schema
- use DB column indexes
- leave performance to production
- you’ll need a minimum 2GB of RAM in prod
- start on one box THEN distribute (you may find one big fat box is the way to go)
January 31st, 2007 at 4:06 am
It’s not Common Lisp that has continuations, it’s Scheme. Though, all you need is some sort of closure to emulate them in any language.
January 31st, 2007 at 9:39 am
>Unlike Perl 6, Ruby 1.9 and the new VM are in the public SVN and can be checked out and used /today/.
OK, so what’s the performance improvement?
January 31st, 2007 at 11:53 am
Wow. Love you Ajax app - especially the idea behind it! if you can promote it, you can pull in some $$$
January 31st, 2007 at 11:18 pm
I think Grails is the best choice for Java developers.
February 1st, 2007 at 1:12 am
“”"
here are also many little things that don’t “feel right” in Django, like the need to manually pass variables to a view.
“”"
You mean pass variables to templates ? you can use locals() if you like.
February 1st, 2007 at 1:12 am
and context processor is very useful.
February 1st, 2007 at 11:46 am
I have had the same problem with Mongrel just up and dying. On the Mongrel FAQ (http://mongrel.rubyforge.org/faq.html) though you can find the following. After I did as Zed suggested I no longer have mongrels dropping off the map.
Q: Mongrel stops working if it’s left alone for a long time.
If you find that Mongrel stops working after a long idle time and you’re using MySQL then you’re hitting a bug in the MySQL driver that doesn’t properly timeout connections. What happens is the MySQL server side of the connection times out and closes, but the MySQL client doesn’t detect this and just sits there.
What you have to do is set:
ActiveRecord::Base.verification_timeout = 14400
Or to any value that is lower than the MySQL server’s interactive_timeout setting. This will make sure that ActiveRecord checks the connection often enough to reset the connection.
February 1st, 2007 at 1:36 pm
Justin: Wow! This might be it. I was using MySQL at the time (now postgres)… I wish you told me that a few months ago
Thanks for that!
February 16th, 2007 at 7:28 am
[...] 交流的启迪 今天和limodou的一段对话,有些意思,征得limodou同意,公开出来,希望能有所启迪: [08:35] myhat123: 看到一篇blog,http://blog.carlmercier.com/2007/01/30/why-i-moved-from-ruby-on-rails-to-pythondjango-and-back/ [...]
March 2nd, 2007 at 5:13 pm
Just to correct one small point. You don’t have to give up Visual Studio and IntelliSense to develop Ruby or Rails. We’ve recently released a Ruby/Rails IDE, ‘Ruby In Steel’, which is integrated into Visual Studio. Our commercial edition has IntelliSense. We also have a free version though that one hasn’t got IntelliSense.
Try it out: http://www.sapphiresteel.com
best wishes
Huw
March 2nd, 2007 at 6:05 pm
Huw,
If I was still under Windows, I’d fork out the $200 and buy this thing right away. I think what you have achieved is simply amazing.
I am now on Mac. Visual Studio is the only thing I miss sometimes. Bring Ruby in Steel to TextMate or even Eclipse and you’ll become rich!
March 6th, 2007 at 8:26 am
Thanks for the comments. I’m afraid Ruby In Steel is a Visual Studio-only project. There are many things I like about the Mac (it looks nicer, for one thing). But I couldn’t learn to live without VS
and, to be honest, I don’t think we would have been able to accomplish half as much as we have done if we’d been using any other platform (by ‘platform’, I mean Visual Studio itself which, once you dig inside it, seems to be more like a whole operating system than just an IDE).
best wishes
Huw
March 18th, 2007 at 2:29 pm
[...] Why I moved from Ruby on Rails to Python/Django and back - Carl Mercier: “I am now at least twice as productive with Ruby on Rails than with ASP.NET”. This guy jumps into RoR world from ASP.NET, after that he tries python/django and at the end he is again happy with Ruby on Rails. It’s interesting to read his story. [...]
March 24th, 2007 at 12:02 pm
I used Java and learned struts framework.And found those xml based configurations were frustrating.Then I learned PHP framework like Cakephp but it does not seem well supported.I didn’t try rails because i didn’t want to learn another language.But now I shift to rails,and find ruby is a such powerful language that just I need.
April 5th, 2007 at 2:43 pm
> > Unlike Perl 6, Ruby 1.9 and the new VM are in the public
> > SVN and can be checked out and used /today/.
> OK, so what’s the performance improvement?
About 3.5x:
http://www.antoniocangiano.com/articles/2007/02/19/ruby-implementations-shootout-ruby-vs-yarv-vs-jruby-vs-gardens-point-ruby-net-vs-rubinius-vs-cardinal
July 20th, 2007 at 10:08 pm
[...] conforms to Carl Mercier’s entry on Why he moved from Ruby on Rails to Python/Django and back to RoR. It is afterall a framework that Carl understood best and felt most comfortable with. [...]
December 10th, 2007 at 11:28 pm
“Well, I don’t have the crashes anymore. Don’t ask me why, I don’t know, but it’s fine now, I swear! Something somewhere got fixed and it seems to have solved the problem.”
This “I don’t know why, but la la la.” is what I hate about Rails developers. Their sites are going to break and not have the foggiest about how to fix them (if they’re like this fellow).
December 11th, 2007 at 12:42 am
spaceman: Rails has gone a LONG way since this incident happened. That was almost 1.5 year ago.
Rails doesn’t break, developers break things. As with any framework/language, good testing is a must.
Rails errors are often hard to understand and/or completely irrelevant. It takes some time to get used to this, but once you’ve seen them a few times, it’s almost a no brainer.
I’d still recommend Rails over Django. If you must absolutely go Python, web.py is an awesome little framework to look at. MERB for Ruby is also excellent for smaller apps.
December 13th, 2007 at 6:59 pm
You really should have tried Pylons (http://pylonshq.com/) instead of Django. Yeah, Django has all the press; it was invented by journalists. Pylons is still better.