Rails不是入门的好东西(gateway drug)

这是Dzone这几天推荐排行榜的文章,有可能是作者的一面之词,但可能也反映了某些问题,来自Rails is not a gateway drug - Yo Briefcase!

作者开头说:他知道对Rails下一个死定义会面临如何恐怖的地步,但是他还是想武断地说:Ruby是一个顽固的重量级Web框架,不是人们宣称那种大麻之类诱导性毒品(让你感觉良好但不伤害你),很多人当试验一下Rails以后,就会立即爱上Ruby和Rails,并且写很长博客来谈自己如何把.NET或Java抛在脑后了,但是作者并不这么认为,只有感觉是Rails让自己落后了,已经使用它一个月,一直在愤怒中度过,充满挫折,作者解释了其中原因:

作者之前是.NET程序员,试验了Ruby,并且开始进行.NET到Ruby移植,作者当时长舒了口气,去他妈的.NET,比Java还差,我讨厌你和你的味道。作者走上了Rails之旅程。

但是等到了作者写这篇文章的时候,他感觉无比沮丧:
1.在命令行接口方面,CLI有太多特性,如果不深入研究几乎无法使用,当他看到一些Railscasts.com文章后他总是问自己,这个家伙是怎么做到的?可选择当然是好,但是Rails本来定位给初学者容易上手(约定大于配置),现在发现默认的选项并不是我的最佳选择。

2.有太多魔术Magic,Rails是非常依赖约定的,但是有太多约定,以致于作者有几次百思不得其解,一些约定有很好文档,但是其他没有,这样就感觉Rails有很多让人搞不懂的魔术。


class HomeController < ApplicationController
def index
end
end

它等同于ASP.NET的MVC:

public class HomeController: Controller
{
public ActionResult Index()
{
return View();
}
}

.NET代码中return view()(Rails没有)可以告诉我返回一个View试图,这样我能够知道访问home/index.cshtml,当我们增加更多类似方法时,一点点这样的代码可以告诉我们区别,约定如果不清楚标注就不具有扩展性。

3.消肿,在一个Rails应用中,你会使用很多类似脚手架的复制工具,你将会看到很多文件:


rails generate scaffold MyEntity name:String age:Int !6580
invoke active_record
create db/migrate/20120403130542_create_my_entities.rb
create app/models/my_entity.rb
invoke test_unit
create test/unit/my_entity_test.rb
create test/fixtures/my_entities.yml
route resources :my_entities
invoke scaffold_controller
create app/controllers/my_entities_controller.rb
invoke slim
create app/views/my_entities
create app/views/my_entities/index.html.slim
create app/views/my_entities/edit.html.slim
create app/views/my_entities/show.html.slim
create app/views/my_entities/new.html.slim
create app/views/my_entities/_form.html.slim
invoke test_unit
create test/functional/my_entities_controller_test.rb
invoke helper
create app/helpers/my_entities_helper.rb
invoke test_unit
create test/unit/helpers/my_entities_helper_test.rb
invoke assets
invoke coffee
create app/assets/javascripts/my_entities.js.coffee
invoke scss
create app/assets/stylesheets/my_entities.css.scss
invoke scss
create app/assets/stylesheets/scaffolds.css.scss

...
其他见篇首作者文章和讨论。
[该贴被banq于2012-04-05 10:10修改过]
[该贴被banq于2012-04-05 10:13修改过]

方便简约与严谨精确有时是一对矛盾,Rails这种因为简单而导致的一些不可捉摸甚至象魔术一样特点,有时也出现在Javascript上,其根本原因来自逻辑上一段故事:

罗素悖论 类型系统与编程语言


[该贴被banq于2012-04-07 08:33修改过]