groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MG <mg...@arscreat.com>
Subject Re: [VOTE] Support Java-like array
Date Mon, 07 May 2018 21:04:50 GMT


On 07.05.2018 22:03, Guillaume Laforge wrote:
> I haven't voted as I'm not a big fan of adding this syntax construct.
>
> My feeling is that we shouldn't necessarily try to become a pure 
> Java-superset, and it shouldn't be a goal to try more and more to 
> close that gap.

Being able to write Java constructs in Groovy and incorporating the 
improvements Groovy has to offer one after another was a major factor 
for me, and it continues to be very helpful when introducing new 
colleaugues to Groovy. If they know Java (and who does not, nowadays ?), 
you can tell them: Just use what you know and - oh yea, do a search and 
replace and remove all the semicolons at the end of each line, and you 
can use a multiline String with embedded variables here, you might wanna 
use a list literal there - and just say file.text = list.join('\n') to 
write the result to a file, ...

> There are some confusing cases where (single element) array 
> initializers can be confounded with closures.
>
> Also, I tend to prefer square brackets over curlies, but that's 
> certainly a question of taste.

Agree with both points. I still think the plus outhweighs the minus - 
see above and below.

>
> The other thing that slightly annoys me is that we're adding 
> additional syntax for the same thing: array initializers, but look at 
> how we added lambda notation.
> How will we explain users why we have two syntaxes for the same thing? 
> Or when/why they should use one over the other?

Hence my suggestion to issue a "non-canonical Groovy / Java construct"- 
warning in these cases - which everyone seems to confuse with some sort 
of coding style warning, which to me it is clearly not: One just has to 
ask oneself, whether anyone would have even considered voting for "...a 
brand new alias for def: var !", or "...a way to write array literals, 
so the look like closures: The amazing curly braces array literals 
!".... (spoken with the voice of the boss from "IT Crowd", season 1 ;-) ).

(I understand that we currently don't have warnings in Groovy, but 
seriously, how hard can it be to add errors which do not make the build 
fail ?-)  )

Cheers,
mg






Mime
View raw message