Re: [EXT] Re: Using `var` as method return type placeholder

2024-11-21 Thread most m
@Steve Etchelecu Java's var is a purely local type placeholder to elide the well-known verbosity when declaring and initializing variables on the same line, e.g. so that instead of writing "VeryLongTypename variable = new VeryLongType name(...);", you could omit the variable's type declaration and

Re: [EXT] Re: Using `var` as method return type placeholder

2024-11-21 Thread MG
Hi guys, yup, the current choice of support for var in Groovy is def a problem in my lexicon, ah, book... ;-) var was always intended for the case of "type inference from an assignment", the way it is used in Java, and imho that is also what people coming fom other languages would expect. Ho

Re: [EXT] Re: Using `var` as method return type placeholder

2024-11-21 Thread Gianluca Sartori
We may have ‘var’ just to make Java happy in the few occasion of a cut and paste from Java in a Groovy file or we can catch the opportunity to be more “Java like” but staying Groovy with ‘var’ == ‘def’. I understand both ways, I realise it’s not a decision to be taken easily, but we have the oppor

Re: [EXT] Re: Using `var` as method return type placeholder

2024-11-21 Thread Milles, Eric (TR Technology) via dev
When support for var was installed, the path taken was to make it work more or less like def. That is not to say it is identical to def, since we did make sure to support the name "var" — reserved type name and not keyword. This was a fitting choice given our close-to-Java semantics. We don't

Re: [EXT] Re: Using `var` as method return type placeholder

2024-11-21 Thread Gianluca Sartori
If we want Groovy to just accept `var` as it is used in Java we should also reject an un-initialized variable definition or a "var v = null' since the type cannot be inferred and it would not be accepted by Java. My take on this argument is that "Groovy digests Java but Groovy is not Java" and ins

Re: [EXT] Re: Using `var` as method return type placeholder

2024-11-21 Thread Gianluca Sartori
If `var` is a "type placeholder" when we don't care about typing (or for `Object`, let's say) then it makes sense. It may be a bit forced but in the end a method is an address in memory that contains instructions instead of a value. I prefer to see it semantically as "define a variable with `var`

Re: [EXT] Re: Using `var` as method return type placeholder

2024-11-21 Thread Gianluca Sartori
Using `var` for fields or properties is less meaningful than using `var` as a type placeholder for methods. I can understand that the word "(var)iable" is semantically more specific than the word "(def)ine" but it is not that ugly or alien in method definitions if we think of `var` as a placeholder

Re: [EXT] Re: Using `var` as method return type placeholder

2024-11-21 Thread Gianluca Sartori
Java supports `var` only for local variable declarations when it can infer the type from the expression on the right side of '=' Gianluca Sartori -- Cell. +39 388 1026822 On Thu, 21 Nov 2024 at 19:17, Steve Etchelecu wrote: > I thought Gianluca made an excellent argument and helps modernize th

Re: [EXT] Re: Using `var` as method return type placeholder

2024-11-21 Thread Jonathan Carter
The Oracle docs on var are helpful, here. Specifically, this part: var can be used for the following types of variables: - Local variable declarations with initializers: - Enhanced for-loop ind

Re: [EXT] Re: Using `var` as method return type placeholder

2024-11-21 Thread Steve Etchelecu
I thought Gianluca made an excellent argument and helps modernize the language.  Given Groovy’s symbiotic relationship with Java, it seems like the guidance here should probably be to follow Java’s usage as that likely keeps friction/confusion to a minimum.  Not being a Java developer, it isn’t cle

Re: [EXT] Re: Using `var` as method return type placeholder

2024-11-21 Thread Milles, Eric (TR Technology) via dev
I don't think semantically that "var name() { ... }" makes sense. One might argue that var for field and property do not make sense either. We could explore removing support for var on class members. From: Gianluca Sartori Sent: Thursday, November 21, 2024 10:57

Re: Using `var` as method return type placeholder

2024-11-21 Thread Gianluca Sartori
Well, actually that's not true, Groovy supports creating fields and properties as well with `var`, so basically everything `def` does except return types. Gianluca Sartori -- Cell. +39 388 1026822 On Thu, 21 Nov 2024 at 17:41, Daniel Sun wrote: > Hi Gianluca, > > `var` was introduced to

Re: Using `var` as method return type placeholder

2024-11-21 Thread Daniel Sun
Hi Gianluca, `var` was introduced to Groovy just for the better compatibility of Java. Java just supports declaring variables with `var`, so does Groovy. Cheers, Daniel Sun On 2024/11/21 10:37:23 Gianluca Sartori wrote: > Hello everybody, > > My name is Gianluca Sartori, from Italy, I am

Using `var` as method return type placeholder

2024-11-21 Thread Gianluca Sartori
Hello everybody, My name is Gianluca Sartori, from Italy, I am the author of the open source project Dueuno Elements (https://github.com/dueuno-projects/dueuno-elements) and I am new to this list. I would like to start using the more Java-ish `var` instead of the Python-ish `def` lexicon but I ca