所有 Groovy 代码都对 Groovy++ 有效吗?
看到此链接后,我想尝试 Groovy++,但我有一个担心;
Groovy 的所有语法在 Groovy++ 中都有效吗?
例如,我可以在 Groovy 中执行此操作:
def list = [1,2]
上述代码在 Groovy++ 中有效吗?
After seeing this link, I want to try Groovy++, but I have a worry;
Is all of Groovy's syntax valid in Groovy++?
For example I can do this in Groovy:
def list = [1,2]
Is the above code valid in Groovy++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
(我相信)目标是让它支持尽可能多的 Groovy 代码。
我相信目前有一些区域无法正常工作,包括:
但是您始终可以解决这些问题,或者不要将需要它们的类标记为
@Typed
The aim (I believe) is to get it to to support as much Groovy code as is possible.
I believe there are currently a few areas that are not working including:
But you can always work around these issues, or don't mark the class that needs them as
@Typed
代码示例的差异列表位于 http://groovy.dzone.com/articles/ groovycomparetogroovy-part-1
一些区别:
There's a list of differences with code samples at http://groovy.dzone.com/articles/groovycomparetogroovy-part-1
Some of the differences:
应该是因为在 Groovy++ 中您可以:
参考:http: //code.google.com/p/groovypptest/wiki/欢迎
It should be since in Groovy++ you can:
Reference: http://code.google.com/p/groovypptest/wiki/Welcome
a) 别担心。性能对于 groovy 和 groovy++ 都不是问题。使用这两种语言,您主要编写胶合逻辑。连接各种java库的代码。这些库是用 java 编写的 - 所以它们全速运行。
有时您会注意到您已经用 groovy 编写了一大段代码,并且您希望增加一些额外的速度。没问题。 Groovy 非常适合构建算法原型。由于 Groovy 具有类似 java 的语法并利用所有这些 java 库,因此将原型转换为全速运行的 java 库是没有问题的(是的,您必须手动编码,但这意味着,您'只是'必须从你的groovy代码中删除所有这些快捷方式才能将其转换为java)。
b) 据我了解 groovy++,它是通过注释来工作的。只有当你对代码进行注释时,它才会被识别为groovy++代码。所以它应该有效。但正如您从所有这些答案中看到的那样,目前没有太多人使用 groovy++,因为性能不是问题(请参阅:-)。
顺便说一句:我猜 groovy++ fork 很快就会合并到标准的 groovy trunk 中......
a) don't worry. performance isn't an issue with neither groovy nor groovy++ . With both languages, you mainly write glue-logic. The code which connects the various java libraries. And those libraries are written in java - so they run at full speed.
Sometimes you notice that you've written a big pice of code in groovy and you would like to add some extra speed. No problem. Groovy is great for prototyping your algorithm. Since Groovy has a java-like syntax and makes use of all those java libraries, it is no problem to convert your prototype into a java library which runs at full speed (yes, you have to code it manually, but this means, you 'only' have to remove all those shortcurts from your groovy code to turn it into java).
b) as far as I understand groovy++, it works through annotations. Only if you annotate code, it will be recognized as groovy++ code. So it should work. But as you can see from all these answers, not too many people use groovy++ at the moment, since performance isn't an issue (see a :-) .
BTW: I guess that the groovy++ fork will soon be merged into the standard groovy trunk...
@Typed(TypePolicy.MIXED) 使想要使用 groovy++ 优化代码的开发人员的生活变得更容易。然而它并不完全支持groovy 代码。
即使使用 @Typed(TypePolicy.MIXED) 的 groovy++ 代码兼容性仍然存在问题,
例如 groovy 样式类型转换(使用关键字“as”)
需要更改为
在闭包之外声明的变量也不能直接在这些变量中使用闭包:
需要更改为java风格(违背了groovy++的目的)或者你必须使用Reference对象。
groovy++ 对于提高 groovy/grails 性能非常有用,但这肯定不是一个简单的方法,我不确定是否应该使用 java。
@Typed(TypePolicy.MIXED) makes the live of a developer that wants optimize code using groovy++ certainly easier. However it is not fully supporting groovy code.
There are still issues even with groovy++ code compatibility using @Typed(TypePolicy.MIXED)
e.g. groovy style type casting (using the keyword "as")
needs to be changed to
Also variables that are declared outside of closures can not be used directly in these closures:
needs to be changed to java style (defeats the purpose of groovy++) or you have to use Reference objects.
groovy++ is very useful to improve groovy/grails performance but it is certainly not an easy way and I am not sure, if I should should use java instead.
Groovy++引入了@Typed(TypePolicy.MIXED)注解,与Groovy完全兼容。
通过使用 @Typed(TypePolicy.DYNAMIC) 或根本不使用 @Typed,您将失去所有 Groovy++ 优势。
如果可能的话,MIXED TypePolicy 优化静态位置。
Groovy++ introduced @Typed(TypePolicy.MIXED) annotation, what is fully compatible with Groovy.
By using @Typed(TypePolicy.DYNAMIC) or not using @Typed at all, you will lose all Groovy++ advantages.
MIXED TypePolicy optimize static places if it is possible.