無分類雜文 03 Sep 2009 12:20 am

推到 Twitter!
推到 Plurk!


Rails 3 的野望 (Rails 合併 Merb 後目前的進展)



這一篇想寫很久了,一直忘記。

大家應該還記得,Merb 在 2008 年底宣布了一個決定,他們決定併入 Rails。而 Merb 的 Team Leader:Yehuda Katz,也將加入 Rails core team 開發。於是未來 Merb2 將直接等於 Rails3。

當時,這件事是非常令人震撼的。原因是 Rails 雖然是一個非常先進的框架,但是還是有非常多開發者,因為它的包山包海(笨重、效能不彰)而卻步。於是,他們選擇了另外一套框架 Merb。Merb 的想法和架構其實是很棒的,它既可以是一個 full stack 的 Framework,又可以讓開發者用 cherry pick library 的方式建構網站。有很多 Merb 派的開發者,甚至就是因為前述原因才跳槽過來的。

因此它們的合併,無異是向社群投了一個大炸彈。很多 Merb 的擁護者當時紛紛表示不能接受,甚至大家都湧上「Merb core team 的人是集體腦袋燒壞掉了嗎」的強烈疑惑,認為 Merb 選擇被 Rails 整併是大錯特錯的愚蠢決定。

我當初也這麼想,但近半年來,追看 Edge Rails 的發展,我才發現所有人(包括 DHH),都被 Yehuda 騙了。

在 DHH 當初的 Announce 提到了 Rails 3 將會有的是:

* Rails core: Yes, Rails is a full-stack framework and will remain so, but there’s no reason we shouldn’t also make it possible to run with less than the full monty. Rails 3 will make it easy to run just a bare minimum and then allow you to opt in just the stuff you want, if that’s necessary for your particular situation. Think “rails myapp—core” (and “rails myapp—flat”).

* Performance optimizations: Merb has a lot of Rails pieces rewritten to be faster. We’ll be bringing all that good stuff over. We’ll also bend the architecture in the places where that’s necessary for a big yield. In short, Rails 3 will get all the performance attention that the Merb guys are known for.

* Framework agnosticism: Rails will always have a default answer to every question within the stack. If you don’t care about testing frameworks, you’ll get test/unit. If you don’t care about which ORM, you’ll get Active Record. But some people do care and want something else. Some people want RSpec for testing, others want to use Sequel or Data Mapper for ORM, others again prefer Haml for templating, and some might prefer jQuery for Ajax. All these people should feel like Rails is welcoming them with open arms. Yes, we’ll have a default, but we shouldn’t have any form of discrimination against alternatives.

* Rigorous API: Too many plugins break when Rails is updated because it’s not clear where they can safely hook into the internals and when they’re monkeypatching and should expect things to break. The Merb guys committed to a public API with tests to ensure that it wouldn’t break. They’ll bring over that line of thinking and give Rails 3 a tested and documented API for extensions that won’t break willy-nilly with upgrades.

大家看到 Rigorous API 這段 一定以為 Yehuda 當初的提議是的改版是,發明一套神奇的 API,讓 plugin 不再爛掉。再加上前三條以上 blahblah 的好處 …不過大家看的半信半疑,感覺上好像都是虎爛,應該完全做不到吧….。

OK。但到目前為止,結果 Yehuda 目前的成果到了什麼地步呢?

Merb 反過來吃掉了 Rails,順便叫 Sinatra 也不用繼續再玩了!

他現在做的事,並不是發明什麼神奇的 API 。而是把整個 Rails refactor,具體的作法就是把整個 Rails 全部拆散成 API 形式再組起來 ……這不僅是空談,而是已經有非常具體的成果了。

1. 現在 Rails 的效能跟 Merb 一樣好!! ( 2008/08/09 )

merb

2. Fully API ( 這在他最近在世界上的各場 ruby / rails conf 演講 影片/ 投影片 都有 demo )

3. 因為現在通通拆開了,所以 Rails3 達成 framework agnosticism 是完全沒問題的…

4. 因為現在通通拆開了,very flat 版 rails 也是沒有問題的…

5. 他最近甚至無聊到火力展示(炫耀)一個東西,如何用 Rails API 拼出一個 Sinatra 。XDDDDDDD

6. 還順便分享了一篇 refactor 技巧(因為公開翻修了 Rails 這個 opensource project ):6 Steps To Refactoring Rails (for Mere Mortals)

完全令人想不到而且偉大的結局啊,完全做的到而且比當初宣告的更屌….。

真期待年底 Rails3 的正式 Release ….

====
Update : 剛剛重回去看
Merb gets merged into Rails 3!,想仔細找找有沒有什麼我寫漏的。結果看到 DHH 在當初的文章裡強調了這次的 merge「This is not a big bang rewrite」。我噗喫一聲,笑出來了…………

Creative Commons License

13 Responses to “Rails 3 的野望 (Rails 合併 Merb 後目前的進展)”


  1. on 03 Sep 2009 at 1:09 am 1.guest said …

    我比較好奇的是那些基於 rails 2 的 project 可以無痛的 porting 到 rails 3 嗎?如果不行,那是不是意味著得全部砍掉重練?

    我覺得 rails 最大的問題在於開發團隊對於向後相容這件事的重視程度… 不重視的話等 rails 4 出來大概又得通通砍掉重練一次…

  2. on 03 Sep 2009 at 1:35 am 2.xdite said …

    DHH 本人建議,寫新 project 才用新版 Rails。而不是每出一版 Rails 就不計代價升上去。

    我自己也是會做相同建議。當然如果你執意要升,我的建議是在做這件事之前,你的網站要寫 fully test,然後用 git 另外一個 branch,邊修邊跑 test,跑到都沒問題再 merge 回去。

    沒有做 test,就玩追新版無異是*自己找死*。事實上其實也不只有 Rails 不理舊版相容性,其他 Web Framework (如 Zend Framework),一升級上去也是噴光光。

    只是這世界上用 Rails 的網站太多了,所以那麼多人在幹角就讓你覺得 Rails 太嚴重…

    (同樣道理也可以套在 performance 不彰,事實上 Rails 比一大堆 PHP framework 效能還要好超多)

    另外改成 API 的好處是,以後寫 plugin 就直接引 API 寫,而不是像以前用 override funtion 的方式硬幹…這樣才不會說一升級就噴光光….

    Rails 3 做完這件事。Rails 3.1 / 3.2 …一直到 4 應該就不會出現類似噴光光這種情形了…(吧)

  3. on 03 Sep 2009 at 1:52 am 3.s said …

    嗯.. Zend 有升級上去就爛光光嗎?
    你是說 Zend Framework 嗎
    雖然主要功能也有在加新 feature (例如 Zend_Layout, Zend_Application)

    不過維持舊的寫法,大部分功能還好耶, 小地方可能看 Release Note 要注意一下.

    不過 ZF 現在也才 v1.9 而已還遇不到升級就要大改版的情況吧

  4. on 03 Sep 2009 at 1:52 am 4.guest said …

    DHH 的建議基本上有講等於沒講,所以像 Redmine 之類的 project 都不用管升級嗎?

    軟體都會進化,而我個人覺得選 framework 本來就是要選穩定 API / 3rd party libraries 的,不然除非 project 就打算綁死在特定的版本,否則有完整的 test suit 也沒用,光是升級就搞死人了,哪來的時間寫新功能…

  5. on 03 Sep 2009 at 2:14 am 5.xdite said …

    Redmine 是 freeze 在 2.1 沒有錯啊 …

    「framework 本來就是要選穩定 API / 3rd party libraries 的」。請問你可以建議一個嗎(最好還有開發迅速)?我也想找這種 framework …

    ====

    寫完整的 test case 可以避免程式在遭到許多人大量 commit 變更的情況下(框架升級,上新功能動到舊功能,同時間多數人 maintain 同一份 code ),程式設計師不被搞死….

  6. on 03 Sep 2009 at 9:55 am 6.ryudo said …

    嗯..這樣的話可以先不用搓sinatra了

  7. on 05 Sep 2009 at 8:27 pm 7.訪客 said …

    RoR進步的好多 orz.
    我當初怎麼會選擇用 catalyst..
    (只是當時比較熟 perl 就跳到這裡來了.)

  8. on 11 Sep 2009 at 10:39 pm 8.wangaguo said …

    真是棒丫, 我也很期待Rails愈來愈好.
    可不可以問個題外話.
    用actionmailer大量寄信,for loop 7000 user,deliver寄信,
    然後是用god跑mongrel,cpu及memory會慢慢的持續上升,
    約寄出2000~3000人,然後mongrel就掛掉了。
    有什麼原因在loop的過程中讓cpu及memory慢慢的持續上升呢?
    如果解決不了的話,我就要把user都一起塞到to去寄了。

  9. on 14 Sep 2009 at 11:50 pm 9.xdite said …

    因為記憶體沒有釋放。

    ActiveRecord 的 model 是很昂貴的……

    你可以看 Engineyard 最近的這篇文章

    That’s Not a Memory Leak, It’s Bloat

    http://www.engineyard.com/blog/2009/thats-not-a-memory-leak-its-bloat/

    建議你寄信塞 delayed_job 或跑 daemon / 塞 queue 慢慢寄。不要用 for loop 塞 actionmailer

  10. on 26 Sep 2009 at 2:47 pm 10.超級帝國 said …

    我也想找這種 framework …

  11. on 29 Sep 2009 at 4:13 pm 11.拆組達人 said …

    世事難料!

  12. on 08 Dec 2009 at 11:50 pm 12.Benson said …

    砍掉重練 只會讓想入門的人感覺更難上手吧!

  13. on 03 Feb 2010 at 1:27 am 13.Blog.XDite.net » Rails3 架構與進展 Part.1 said …

    [...] 還記得去年九月這篇文章嗎?Rails 3 的野望 (Rails 合併 Merb 後目前的進展) [...]

Trackback This Post | Subscribe to the comments through RSS Feed

Leave a Reply