groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MG <>
Subject Re: Possible New Groovy Features... - Auto final-ize
Date Sun, 27 Aug 2017 02:19:57 GMT
Hi Jochen,

On 25.08.2017 10:01, Jochen Theodorou wrote:
> On 23.08.2017 00:32, MG wrote:
> [...]
>> Apart from making the code easier to
>> read & safer, it also allows compiler optimizations (and in the absence
>> of a true const-keyword, at least for fundamental data types it has the
>> same effect).
> Something I want to mention here: The Groovy compiler currently 
> contains no optimizations for final local variables. The JIT has 
> optimizations for final fields, but for local variables the final 
> modifier is just removed even in Java. There are of course 
> optimizations that can be done if something is final, which is to use 
> a change-only-referenced logic instead of a change-variable-itself 
> logic for inner classes, lambdas and closures. But right now we do not 
> have this kind of optimization in the compiler.

Thank you for the information. When the Groovy compiler gets theses 
optimizations, me and my final-ized code will be already be waiting... ;-)

> That of course still means there is the read&safer part. Just not sure 
> what you mean by safer actually.

Safer in the sense that final parameters cannot be changed by accident 
in the code.

> [...]
>>> Also, it would be an easy task to create an @AutoFinal local transform
>>> which could then be automatically applied using a compiler customizer.
>>> I think going further with a dedicated compiler flag would be a later
>>> step if such a local transform became extremely popular.
>> Never found the need to do my own AST transforms in Groovy - do you
>> maybe have a pointer to a current tutorial on how to get started for me
>> ? Since you mentioned macros in your reply, I first went "Do we have
>> these in Groovy ?", then I found I checked out the 2.5 macro description
>> - do you think it would be worth waiting for 2.5 to become stable to be
>> able to use macros for this functionality ?
> you can use it already. The macros will most likely not change a lot 
> anymore, unless we find problems, which then you could for example 
> help us finding then ;)

That would be good, but a) Paul advised against macros for this task b) 
Not sure if it would be wise to write my first Groovy AST transform 
while beta testing a new language feature at the same time ;-)


View raw message