Back

Grails 吐槽 ( complains about Grails)

发布时间: 2012-10-17 08:40:00

1. 不如Ruby 直观。语言比较拖拽,繁琐,估计是受了java的影响。例如,按照官方文档: ( not as expressive as Ruby.   maybe effected by Java, not as simple as Ruby. e.g. the query below is copied from its official document: )

// Dan brown's first book
Book.find("from Book as b where b.author='Dan Brown'")

// with a positional parameter Book.find("from Book as b where b.author=?", ['Dan Brown'])

// with a named parameter Book.find("from Book as b where b.author=:author", [author: 'Dan Brown'])

// use the query cache Book.find("from Book as b where b.author='Dan Brown'", [cache: true]) Book.find("from Book as b where b.author=:author", [author: 'Dan Brown'], [cache: true])

// query by example def example = new Book(author: "Dan Brown") Book.find(example)

// Using where criteria (since Grails 2.0) Person p = Person.find { firstName == "Bart" }

你可以很容易的写出 Rails这样的代码吗? ( Can you easily implement the Rails code below using Grails ? )

book = Book.where("name = 'Jim'").last()    
book = Book.last(:condition => "name = 'Jim'" )

2. 该约定的时候,允许不约定的情况存在。 例如,今天发现个情况:   ( it allows the not-obey-convention cases which should obey the convention. e.g. I found this code written by others: )

// grails/domain/yourpackage/Book.groovy 
class Book {
  // this is a domain class
}
// still in this file
class Person {
  // this is NOT a domain class, just an POJO
}

按照约定,Person必须是个Domain model, 因为它放在了 domain 目录里。但是实际上,它由于没有自己对应的 Person.groovy文件,(寄居在了Book.groovy 中), Grails 又不会认定它是个Domain.  ( Following the coding convention, Person should be a "Domain model" and thus should exist in a separated file named "Person.groovy". But actually it is written in Book.groovy file, so Grails won't recognize it as a Domain class. )

相比之下, Rails 用显示代码声明的方式更好:  (Comparing to the case above, Rails' specific-declaration approach-- "< ActiveRecord::Base" is better )

# persistent object
class Device < ActiveRecord::Base
end
# regular object
class IAmNotPersistent
end

3. 速度太慢。 比如, Rails console, Rails Unit test:  新机器2秒,06年老机器10秒也启动了。  但是Grails居然要等个1分钟,而且最奇葩的是,出来的居然是 java GUI. >_<   难道 Grails console == Swing/swt GUI ?   ( too slow. when running Rails console, 10 seconds is enough for a 2006 made computer.  but for Grails, I have to wait for 60 seconds!!! and even stranger thing is that finally I got a java "GUI"!!!  Could it be that "grails console" results in a Swing GUI? oh my god...)

4. Bug 多多。例如, 我要在Rails 中显示某个图片,可以这样做   ( too many bugs. e.g. I want to display a <img> element, I have many approaches: )

<%= image_path src='some_file' %>

也可以这样做 (I can also use raw HTML) :  <img src='/images/some_file' />  ( some_file 放在 public/images目录下) ( some_file is put in public/images)

可以是个 soft link  (and the src could be a soft link )

但是 Grails,  <%= g:image %> 既不支持 public 目录的方式,也不支持 soft link的方式,就喜欢报错。 我无语。在Rails 中可以有3+ 种解决问题的方式, Grails中居然都不行。 后来我临时搭建个 apache 服务器才暂时解决问题。( but in Grails, neither public/images nor the soft-link approach is supported.  Grails complains with lots of unreadable/un-debug-able messages. at last I have to setup a apache server to support the soft-link images , the problem was solved. my god... )

Back