On 8/1/20 14:41, MG wrote:
> Hmmm, I am for consistency, but at least I use very few maps as compared to 
> lists, and rarely ever output the size of a map, but constantly for
> lists, so having getSize() on List would still be beneficial.

You're free to add whatever you want to your metaClass :-)
>
> This has of course been discussed many times before - maybe a "size" operator:
>
> #list // list.size()
> #map // map.size()
> #string // string.length

Now, this is not a completely bad idea.
I spent a few years programming in Lua, and that's what the # operator does for 
strings and tables (arrays)

i think the # symbol is not being used in Groovy anywhere but I may be mistaken.
They would need to change the language's grammar, though.

I'm all for using symbols for syntactic sugar.
And why limit ourselves to ASCII-7 when we have the whole Unicode set to choose 
from!! :-)


BBB

>
> which people could override (e.g. sizeOf() method) and which unifies all 
> kinds of "how many elements do I hold / how big am I" concepts (if its not
> a collection holding items) ?-)
>
> Cheers,
> mg
>
>
> On 01/08/2020 18:08, OCsite wrote:
>> MG,
>>
>>> On 1 Aug 2020, at 14:59, MG <mg...@arscreat.com 
>>> <mailto:mg...@arscreat.com>> wrote:
>>> What was the reason again Groovy does not add getSize() here... ?-)
>>
>> Consistency I guess. Having a List.size would lead to a request to add 
>> Map.size, which alas would clash with Map['size'].
>>
>> All the best,
>> OC
>>
>>> On 01/08/2020 04:06, Paul King wrote:
>>>> What Daniel said is correct. Also if there was an accessible getSize() 
>>>> method, you could use just ".size".
>>>>
>>>> Cheers, Paul.
>>>>
>>>> On Sat, Aug 1, 2020 at 11:19 AM Daniel Sun <sun...@apache.org 
>>>> <mailto:sun...@apache.org>> wrote:
>>>>
>>>>
>>>>     The parentheses of methods without parameters could not be ommitted.
>>>>
>>>>     `[1, 2, 3].size` is accessing the private field `size` of `ArrayList`, 
>>>> so illegal reflective access warning will be thrown.
>>>>
>>>>     Cheers,
>>>>     Daniel Sun
>>>>     On 2020/08/01 00:49:54, paul <pl.grue...@gmail.com 
>>>> <mailto:pl.grue...@gmail.com>> wrote:
>>>>     > Hi all,
>>>>     >
>>>>     > (on latest groovy 3.0.5 and OpenJDK 14) omitting the empty 
>>>> parentheses to the .size() call works, but throws an illegal reflective 
>>>> access
>>>>     warning:
>>>>     >
>>>>     > ```
>>>>     > groovy:000> [1,2,3].size
>>>>     > WARNING: An illegal reflective access operation has occurred
>>>>     > WARNING: Illegal reflective access by 
>>>> org.codehaus.groovy.reflection.ReflectionUtils
>>>>     (file:/home/paul/.sdkman/candidates/groovy/3.0.5/lib/groovy-3.0.5.jar) 
>>>> to field java.util.ArrayList.size
>>>>     > WARNING: Please consider reporting this to the maintainers of 
>>>> org.codehaus.groovy.reflection.ReflectionUtils
>>>>     > WARNING: Use --illegal-access=warn to enable warnings of further 
>>>> illegal reflective access operations
>>>>     > WARNING: All illegal access operations will be denied in a future 
>>>> release
>>>>     > ===> 3
>>>>     > ```
>>>>     >
>>>>     > Curiously, the size() method seems to be the only parameter-less 
>>>> method where I can
>>>>     > omit the empty parentheses – all others throw a 
>>>> MissingPropertyException (as expected).
>>>>     >
>>>>     > What is the desired behaviour, and why is it even working (albeit 
>>>> with warnings) with .size ?
>>>>     >
>>>>     >
>>>>     > best
>>>>     > paul
>>>>     > --
>>>>     > typed with Neo 2 -- an ergonomically optimized keyboard layout
>>>>     > for German, English, programming, and science
>>>>     > ❤ http://neo-layout.org <http://neo-layout.org/>
>>>>     > ❤ https://useplaintext.email <https://useplaintext.email/>
>>>>     > ❤ YY-MM-DD dates (ISO 8601/RFC 3339)
>>>>     > � UTF-8 encoding
>>>>     >
>>>>
>>>
>>
>


Reply via email to