The venerable Groovy style guide <https://groovy-lang.org/style-guide.html> (which could be updated a bit) recommends using def inside the body of methods and closures, and to use proper types for method signatures. In terms of updates, it could mention def or var. I'm used to use def, and am not using var all that much, unless I'm copy pasting some Java code that uses var. For me, def == var, in my mental model. Which means == Object. I don't think we should impose too much extra constraints on def or var, as it could break some code in the community at large.
Guillaume On Tue, Nov 26, 2024 at 5:08 PM MG <mg...@arscreat.com> wrote: > Hi Rémi, > > 1. yes, I saw that, thank you. > 1. Most of the examples seemed obvious to me, and the bugs that > could be introduced feel like they are a little bit on the artficial > side. > 2. But, having said that: Inferring an interface type or a less > specific parent type in some cases could imho be a very Groovy thing: > 1. e.g. inferring List<T> instead of ArrayList<T> > 2. Potentially through some explicit construct, such as "var>" to > indicate that a more loose / interface type shall be used. > 3. Not that I see any of that becoming a reality anywhere in the near > future... ;-) > > Cheers, mg > > PS: I googled a bit, and I could not find in general that ppl think var > in Java is something you should avoid. Instead, as with any language > feature, one can over-/abuse it, thereby making code less readable than > when using explicit types. > It is funny thinking about this in the context of Groovy, where > typically ppl who use it as a scripting language do not even use final > instead of def when defining variables, even though they will never > reassign said variable 99% of the time... ;-) > > There is an official guide that explains some of the gotchas > https://openjdk.org/projects/amber/guides/lvti-style-guide > > regards, > Rémi > > > -- *Guillaume Laforge* Apache Groovy committer Developer Advocate @ Google Cloud <https://cloud.google.com/> - Blog: glaforge.dev - Twitter: @glaforge <http://twitter.com/glaforge> - Mastodon: @glafo...@uwyn.net <http://%40glafo...@uwyn.net/>