I typically use Groovy in its static mode, and the single biggest value to
me is the AST-transformation system. However, there are cases where I find
dynamic mode very useful.

1. Methods that handle processing for particular subtypes of a base type. I
could do something like a class-based map with, and I do in cases where I
need pluggability, but for the case of "I have these 4 types of incoming
message and need to convert them to a target format", using dynamic
dispatch on a top-level method results in much clearer code than a giant
switch or hand-written reflection.

2. Quick-and-dirty processing of data structures. REST calls usually return
JSON these days, and if I know that I just to pull some simple data out of
a nested structure, it's much easier to use dynamic mode against a Map than
to try to write a bunch of mapping classes.

3. Spock and Geb. I have managed to convince consulting clients that stick
to plain Java only for the business code to adopt Spock for testing because
it's so powerful and clear. Spock is the Groovy equivalent of an IOCCC
winner, and it showcases the dramatic lengths you can (and nearly all of us
shouldn't) go to.

On Sat, Dec 30, 2023 at 12:17 PM Agile Developer <fithis2...@gmail.com>
wrote:

> Hi,
>
> I was a  4 years user of Grails/Groovy (last year mostly Python). With the
> general trend of people moving to static languages, is there any reason
> that Groovy needs to stay dynamic?
>
> I see Python having the mypy approach, I see gradle moving to Kotlin and
> FE mostly on Typescript.
>
> I understand that the @CompileStatic is the supported method, but having
> true static typing (with the Script-Like enhancements other Languages
> added, would be beneficial).
>
> Is there still a reason to keep it dynamic? What is the benefit?
>
> --
> Dr. Vasileios Anagnostopoulos (MSc,PhD)
> Researcher/Developer
>

Reply via email to