所有 Groovy 代码都对 Groovy++ 有效吗?

发布于 2024-12-02 21:51:49 字数 264 浏览 0 评论 0原文

看到此链接后,我想尝试 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

紫南 2024-12-09 21:51:49

(我相信)目标是让它支持尽可能多的 Groovy 代码。

我相信目前有一些区域无法正常工作,包括:

  1. 多重赋值 - 无法编译< /a>
  2. 扩展点运算符可能会导致问题在某些情况下
  3. 。使用 {} 不起作用

但是您始终可以解决这些问题,或者不要将需要它们的类标记为@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:

  1. Multiple assignment - doesn't compile
  2. The spread-dot operator can cause problems in some situations
  3. .with {} doesn't work

But you can always work around these issues, or don't mark the class that needs them as @Typed

天涯离梦残月幽梦 2024-12-09 21:51:49

代码示例的差异列表位于 http://groovy.dzone.com/articles/ groovycomparetogroovy-part-1

一些区别:

  • 更严格的编译时检查
  • 没有 ExpandoMetaClass 闭包的动态类​​型修改
  • 不能更改闭包代码之外的变量
  • 没有直接访问私有方法

There's a list of differences with code samples at http://groovy.dzone.com/articles/groovycomparetogroovy-part-1

Some of the differences:

  • stricter compile-time checks
  • no on-the-fly type modifications with ExpandoMetaClass
  • closures can't change variables outside closure code
  • no direct access to private methods
零度℉ 2024-12-09 21:51:49

应该是因为在 Groovy++ 中您可以:

  • 轻松混合静态和动态类型代码

参考:http: //code.google.com/p/groovypptest/wiki/欢迎

It should be since in Groovy++ you can:

  • easy mixing of statically and dynamically typed code

Reference: http://code.google.com/p/groovypptest/wiki/Welcome

神魇的王 2024-12-09 21:51:49

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...

深府石板幽径 2024-12-09 21:51:49

@Typed(TypePolicy.MIXED) 使想要使用 groovy++ 优化代码的开发人员的生活变得更容易。然而它并不完全支持groovy 代码。

即使使用 @Typed(TypePolicy.MIXED) 的 groovy++ 代码兼容性仍然存在问题,

例如 groovy 样式类型转换(使用关键字“as”)

 String foo = myUntypedFoo as String

需要更改为

 String foo = (String)myUntypedFoo

在闭包之外声明的变量也不能直接在这些变量中使用闭包:

  @Typed(TypePolicy.MIXED)
  def countMatches( List<String> bahList, String pattern ){
    int counter = 0
    bahList.each{ String bah ->
      if (bah==pattern) counter++
    }
  }

需要更改为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")

 String foo = myUntypedFoo as String

needs to be changed to

 String foo = (String)myUntypedFoo

Also variables that are declared outside of closures can not be used directly in these closures:

  @Typed(TypePolicy.MIXED)
  def countMatches( List<String> bahList, String pattern ){
    int counter = 0
    bahList.each{ String bah ->
      if (bah==pattern) counter++
    }
  }

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.

め七分饶幸 2024-12-09 21:51:49

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文