Is all Groovy code valid with Groovy++?
Asked Answered
H

6

7

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

Hospodar answered 6/9, 2011 at 9:52 Comment(0)
A
8

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

Abstention answered 6/9, 2011 at 12:32 Comment(1)
If you mark the entire package as @Typed, you can opt out by marking an individual class or method as @Typed(TypePolicy.DYNAMIC)Con
C
4

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
Con answered 6/9, 2011 at 12:40 Comment(0)
W
2

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

Woolridge answered 6/9, 2011 at 11:56 Comment(0)
F
1

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

Fishgig answered 6/9, 2011 at 14:51 Comment(3)
Yes. Maybe it's because I use it for the right things. I wouldn't want to code a raytracer in groovy, but I could imagine to write the prototype for it in groovy or some part of it. But when I write a grails app (that's what I use groovy mostly for), performance really is no problem.Fishgig
@ralf. Still there are talks that Grails is very slow , and we couldn't control each and every thing in Grails. Means Grails do stuffs faster, but we can't go in depth? Is it true!Hospodar
There are those talks, but I didn't have those problems yet :-) Buy a truck and complain about it that it isn't as fast as a porsche. You can always fallback to java if your really need speed. Depth: I did 10+ years of web development with php and other technologies and switched to grails some years ago. I had not one single moment where I couldn't control something or couldn't go into depth. That's the best about grails: it makes the everyday task really easy and still allows you to go into depth.Fishgig
K
1

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

Kayak answered 19/1, 2012 at 19:14 Comment(0)
N
0

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.

Noiseless answered 1/11, 2011 at 8:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.