>
> I have the feeling that your confusion comes from the fact that you think
> Groovy = Python in the Java world, and Python def = Java var, therefore
> Groovy var should be def.
>

Well, my confusion comes from the documentation (
https://groovy-lang.org/semantics.html#_variable_definition) that states:

> If you think of def and var as an alias of Object, you will understand in
an instant.

So I understood the wrong thing instantly :)

There are tons of constructs Groovy supports for the sole reason to be as
> copy & paste compatible with Java as possible (Java-style curly-braces
> literal arrays, Java for-each loops, etc, etc), and none of these are first
> class citizens / idiomatic Groovy.
> The var reserved word, that as a technicality is currently mapped to def
> with some restrictions, is just a small blip in a large sea here.
>

Okay then I guess that this should be clear from the documentation. Because
they can be seen as new features of the language we should use to stay
updated. I mean we should not even talk about `var` in the same place we
are documenting `def`, there should be a separate chapter "Compatibility
with Java".

I use `def` everywhere when writing the higher/final layer of my software
(Eg, not the internal API layers where I prefer to use types to self
document the code) this `var` topic I am discussing here was triggered by a
talk I've heard about starting to use 'var' in Groovy code.

Cheers,
Gianluca

Reply via email to