You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by "Winnebeck, Jason" <Ja...@windstream.com> on 2018/03/21 15:39:06 UTC

Groovy 3 lambda, method reference, default methods

I took a look at the new Groovy 3 changes at http://groovy-lang.org/releasenotes/groovy-3.0.html and noticed there is still a question as to whether or not to implement lambdas, method references, and default methods as closures and traits. Is the Groovy team still taking feedback on these decisions?

If so, my vote would be to by default, emit JDK8+ "native" implementations wherever possible. I would even go as far to say to allow Groovy 3 to emit JDK8+ lambdas for any expression where a closure inline to a method taking a SAM, as a way to improve Groovy 2 code, but I can understand why it might be better to be consistent and have closure blocks always generate closures (as closures have delegate concept that extends Java lambdas).

The reason for my vote is I work on a large Groovy project where performance is a significant consideration. My experience so far is that using closures with streams has poor performance such that any time I want to use streams I either write the class in Java or I make a utility class with the Streams code and call that utility class from Groovy. It is unfortunate that JDK 8's enhancements make Groovy feel a lot less necessary to me, especially since I learned how hard it is to avoid BigDecimal math even when using CompileStatic. We are working with a business rules system and sometimes a single rule can trigger 1k+ times within a single page refresh, so we have to pay attention to which Groovy features we use in certain rules. Avoiding closures, using for in preference to .each, etc., can result in order of magnitude speedup. That's why my vote is to have Groovy compile static generate code as close to Java as possible, whenever a choice is possible.

Jason Winnebeck

This email message and any attachments are for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message and any attachments.

RE: Groovy 3 lambda, method reference, default methods

Posted by "Winnebeck, Jason" <Ja...@windstream.com>.
That's cool that it's basically a separate project. I wonder if IntelliJ itself can use the Parrot parser then to parse Groovy code, in that case it would always be guaranteed to be 100% "compatible", at least from a syntax perspective. I bet same concept could apply to code analysis tools.

Jason

-----Original Message-----
From: Daniel.Sun [mailto:sunlan@apache.org] 
Sent: Wednesday, March 21, 2018 12:11 PM
To: users@groovy.incubator.apache.org
Subject: RE: Groovy 3 lambda, method reference, default methods

You can write Java8 style code(e.g. lambda, method/constructor reference,
etc.) when Parrot parser is enabled :-)
See https://github.com/danielsun1106/groovy-parser


> Is there then a major difference in language between 2.6+Parrot and 3.0?

3.0 enables Parrot parser by default, so no differences.


> I wonder if the IntelliJ support ticket should be updated to say 
> support new language features in Groovy 2.6 as well?

I see the title contains "Groovy 3", so I am not sure if it will support 2.6


Cheers,
Daniel.Sun




--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Users-f329450.html

This email message and any attachments are for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message and any attachments.

RE: Groovy 3 lambda, method reference, default methods

Posted by mg <mg...@arscreat.com>.
I guess the Groovy 3.0/3.0-- (aka 2.6) syntax elements support will be switchable in IntelliJ, anything else would make little sense to me.But we have the expert on this mailing list, who should be able to tell us... :-)mg
-------- Ursprüngliche Nachricht --------Von: "Daniel.Sun" <su...@apache.org> Datum: 21.03.18  17:10  (GMT+01:00) An: users@groovy.incubator.apache.org Betreff: RE: Groovy 3 lambda, method reference, default methods 
You can write Java8 style code(e.g. lambda, method/constructor reference,
etc.) when Parrot parser is enabled :-)
See https://github.com/danielsun1106/groovy-parser


> Is there then a major difference in language between 2.6+Parrot and 3.0?

3.0 enables Parrot parser by default, so no differences.


> I wonder if the IntelliJ support ticket should be updated to say support
> new language features in Groovy 2.6 as well?

I see the title contains "Groovy 3", so I am not sure if it will support 2.6


Cheers,
Daniel.Sun




--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Users-f329450.html

RE: Groovy 3 lambda, method reference, default methods

Posted by "Daniel.Sun" <su...@apache.org>.
You can write Java8 style code(e.g. lambda, method/constructor reference,
etc.) when Parrot parser is enabled :-)
See https://github.com/danielsun1106/groovy-parser


> Is there then a major difference in language between 2.6+Parrot and 3.0?

3.0 enables Parrot parser by default, so no differences.


> I wonder if the IntelliJ support ticket should be updated to say support
> new language features in Groovy 2.6 as well?

I see the title contains "Groovy 3", so I am not sure if it will support 2.6


Cheers,
Daniel.Sun




--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Users-f329450.html

RE: Groovy 3 lambda, method reference, default methods

Posted by "Winnebeck, Jason" <Ja...@windstream.com>.
This is major news, if the performance is comparable to Java. So with 2.6.0-alpha-3, Parrot, and JDK8+ you can use lambda expressions in static groovy and have them compiled to native lambda, or is it using closure syntax?

Is there then a major difference in language between 2.6+Parrot and 3.0?

I wonder if the IntelliJ support ticket should be updated to say support new language features in Groovy 2.6 as well?

Jason

-----Original Message-----
From: Daniel.Sun [mailto:sunlan@apache.org] 
Sent: Wednesday, March 21, 2018 11:50 AM
To: users@groovy.incubator.apache.org
Subject: Re: Groovy 3 lambda, method reference, default methods

Up to now native lambda is available under compile static mode in 3.0.0-alpha-2(will be released soon) and 2.6.0-alpha-3(Parrot parser is required enabled and using Java8+).

Cheers,
Daniel.Sun



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Users-f329450.html

This email message and any attachments are for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message and any attachments.

Re: Groovy 3 lambda, method reference, default methods

Posted by "Daniel.Sun" <su...@apache.org>.
Up to now native lambda is available under compile static mode in
3.0.0-alpha-2(will be released soon) and 2.6.0-alpha-3(Parrot parser is
required enabled and using Java8+).

Cheers,
Daniel.Sun



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Users-f329450.html