문제

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++?

도움이 되었습니까?

해결책

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

다른 팁

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

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

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

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top