2/28/2007

一個在 Rails 跟 Django 徘徊設計師的真情告白



AjaxWhoIs 這個網站的作者最近發表一篇文章 Why I moved from Ruby on Rails to Python/Django and back,講解他開發 AjaxWhoIs 2.0 的時候為何先用 Rails 開發,後來採用 Django 開發,最後還是轉回 Rails 的紀錄。

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.

他一開始是一個 ASP.NEt 跟 C# 的程式設計師,所以他是第一次使用 Rails ,但是當他使用 Rails 開發的時候,他發現 Rails 的三大法則 MVC ,DRY ,Convention Over Configuration 至少讓他生產力比原本很熟悉的 ASP.NET 快了兩倍以上。

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.

但是當他寫完AJAXWhoIs 2.0的時候,他發現到 Mongrel 跑 64bit Ubuntu 的時候有詭異的問題,導致 Mongrel 常常當機,屢試不爽。

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.

相當令人覺得很了不起,也相當令人覺得不可思議的事情發生了。他已經寫完了整個 Project ,只是遇到了這個 Hardware 問題,他居然跑去用 Django 重新寫了一次 AjaxWhoIs 2.0,而且這還是他第一次寫 Python。一般人應該都會換台機器跑就好了不是嗎 @@!

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.

但是當他寫完的同時,他開始相當懷念 Rails 了,有許許多多小地方他認為 Rails 做的比 Django 來的好,Rails 作法也比 Django 來的更 straightforward 。要完成同樣一件事情,Django 也需要比 Rails 更多 code 。 Django 有太多東西讓他覺得 don't feel right了。

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.

的確,Python 比 Ruby 快,需要 memory 也比較少。而且最重要的是,Django 可以動,Mongrel 在 64 bit CPU 不能動。

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.

而為何他又要跑回 Rails 了呢?Just for FUN。他發現到 Ruby on Rails 會讓人非常愉快,社群很大,活動力強,而且都會互相幫忙。免費的 Rails Plugin 跟 code 快速的進展都很棒。Rails 需要較少的 code ,較少的可怕的 method call,而且還內建 AJAX 跟 REST。而且 Data Access 跟 template engine 都更有彈性。

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.

最神奇的是,當他回去 Rails 時,Mongrel 不再 crash 了@@!不知道Mongrel 哪裡修正了,反正問題解決了。但是效率依舊是一個問題所在。

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.

他的建議是如果你是 Python 長期的使用者,用 Django 吧,如果你是 JAVA,Perl,Smalltalk背景的人,來用 Ruby on Rails 吧。

我的小結論:

從他的字裡行間可以看出幾件事情

  1. Rails 跟 Django 開發時間都很快速
  2. 他真的很不會利用時間,居然用 Rails 跟 Python 各開發了一次,只是因為 Mongrel 對 Hareware 有點 bug

4 則留言:

emomo 提到...

"而為何他又要跑回 Rails 了呢?Just for FUN。他發現到 Ruby on Rails 會讓人非常愉快,社群很大,活動力強,而且都會互相幫忙.免費的 Rails Plugin 跟 code 快速的進展都很棒。Rails 需要較少的 code ,較少的可怕的 method call,而且還內建 AJAX 跟 REST。而且 Data Access 跟 template engine 都更有彈性"
"
???
這一段完全不同意.
我是 Django 的使用者,也認真讀了一些 Ruby on Rails 的書籍, 但最後還是決定使用 Djando, 原因無它,程式風格和所進行專案的適用性而已.兩個都是很好的 Framework, 各有所長. 不同在那,去 Google 一下就會有很多人的評論的.如果下一個專案 RoR 比較適用, 那我也會用 RoR
但是依照你這一段這樣寫下來,可能會讓人有所誤解.
Django 和 Python 同樣讓人愉快,社群是比RoR小,互相幫忙是一定會的. 而且即將出版的書籍,全部內容完全開放免費 Djangobook.com, 不像那本 Agile Web Development with Rails 還在 Rough Cut 階段就要收費,幫忙挑錯給建議還要付錢???有沒有搞錯阿? Rails 是需要較少的code沒錯 ,但和Python 的設計理念有關:Explicit is better than implicit.Readability counts.
也就是說有時Code少是要付出代價的.對習慣 Python 的使用者來說, Rails 有太多的 implicit magic,喜不喜歡, 看個人風格了...
關於內建 AJAX, Django 的作者在這次的 Pycon 說了:We don’t ship with a JS framework. Having Python produce JavaScript is like using a motorized wheelchair because you’re too lazy to walk...

來源:
http://www.b-list.org/weblog/2007/02/23/pycon-2007-web-frameworks-panel
這是Django 作者的理念問題, 看你同不同意了. Python 的其他 web framework 如 Pylons 和 Turbogears(?) 是有整合 AJAX 的.
至於 Template Engine 也是設計理念的問題, Django 作者認為, 如果你開始在 template 上開始作一些Django 既有template engine很不容易達到的事情,那很可能表示你可能要重新回去看看你的
MVC架構是否應該重新規劃,因為 template engine 本來就是要給 designer 用的,不需要也不應該讓 designer 去作超過他的工作範圍, 對 Programmer 來說也是一樣的.我是贊同這樣的理念的.要真的比template彈性,去跟 PHP 比如何?
...不寫了,這永遠也寫不完的.
我是你 blog 的讀者,每篇我都會看一下的.你提到
Django 兩次, 但可能是消息來源的原因,我想大部份的 Django 使用者都不會同意你的說法的.我不確定你有沒用 Django 試作一些小 Project, 或到
Python, Django 的討論區,社群網站, blog, irc...看看,或許你會有不同的看法.

thegiive 提到...

喂喂,老兄

這只是翻譯,不同意這段文章的看法可以至原作者去 complain 。我這邊只負責翻譯正不正確而已 :p

lukhnos 提到...

從這件事情我們還知道,狗(Mongrel)吠火車有時是會把 Rails developer 嚇跑的。:p

匿名 提到...

Hello people! I have been looking for [url=http://www.streaamy.com]Free Spyware Removal Software[/url] online and used the following search terms [url=http://www.streaamy.com/spyware-removal-tool]Spyware Removal Tool[/url] [url=http://www.streaamy.com/best-spyware-removal]Best Spyware Removal[/url] [url=http://www.streaamy.com/free-spyware-removal-tool]Free Spyware Removal Tool[/url] [url=http://www.streaamy.com/best-free-spyware-removal]Best Free Spyware Removal[/url] [url=http://www.streaamy.com/spyware-removal-free]Spyware Removal Free[/url] , but did not find anything free. Can you help me?