You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by Noel Grandin <no...@gmail.com> on 2009/11/27 11:46:44 UTC

nitpicking: Sequence.getLength()

Hi

I realise that I'm nitpicking, but why does Sequence have a
getLength() method instead of a size() method?

My brain is habituated to the normal JDK collections, and I keep
typing size() and wondering why it isn't working.

Thanks, Noel.

Re: nitpicking: Sequence.getLength()

Posted by Niclas Hedhman <ni...@hedhman.org>.
An interesting observation of what IMHO constitutes the biggest flaw in the
so called Glasgow spec, aka JavaBeans and POJOs;
It is said that a method in the verb form is a property (which in turn is a
noun).

>From that stems a lot of nastiness that we now take for granted and some
even call 'goodness'. And I think a proper 'Property' spec would have
emerged if it wasn't for this "JavaBean spec" making a naming convention
(which people not even follow slavishly, since you can get away with it, for
instance array access.

I kind of agree with both Noel and Greg in their argumentation. Is
consistency more important than habbit? I don't know, but IF now consistency
(Glasgow spec) is chosen, be prepared to be called out on it whereever else.
The worst situation IMHO is saying you are consistent, but not being so...

-- Cheers
Niclas

On 27 Nov 2009 23:41, "Greg Brown" <gk...@mac.com> wrote:

I actually think the array length property makes sense - it is simply a
public final field and doesn't need a "get" prefix. However, I think this
raises an interesting point. I imagine that the designers of the JDK
collections were attempting to maintain parity with "length" when they
created the "size()" method. I would further guess that they chose "size()"
instead of "length()" because "length()" doesn't make as much sense for a
map or set as it does for a list. I'd suggest that "getLength()" is actually
more consistent with array "length" than "size()", since "getLength()" is
simply the bean equivalent of a public "length" field.

Of course, this is neither here nor there.  :-)  I personally prefer
getLength(), but to each his/her own.

On Nov 27, 2009, at 10:07 AM, Noel Grandin wrote: > I see the rationale, but
in API design, there...

Re: nitpicking: Sequence.getLength()

Posted by Greg Brown <gk...@mac.com>.
I actually think the array length property makes sense - it is simply a public final field and doesn't need a "get" prefix. However, I think this raises an interesting point. I imagine that the designers of the JDK collections were attempting to maintain parity with "length" when they created the "size()" method. I would further guess that they chose "size()" instead of "length()" because "length()" doesn't make as much sense for a map or set as it does for a list. I'd suggest that "getLength()" is actually more consistent with array "length" than "size()", since "getLength()" is simply the bean equivalent of a public "length" field.

Of course, this is neither here nor there.  :-)  I personally prefer getLength(), but to each his/her own.


On Nov 27, 2009, at 10:07 AM, Noel Grandin wrote:

> I see the rationale, but in API design, there comes a point where
> adherence to stylistic rules has to give way to human processes and
> usage patterns.
> The existing "length" field on arrays and size() method on collections
> API is simply too widespread and too ingrained into the collective
> Java-programmer consciousness to be fought against.
> 
> Anyhow, not serious, just my 2c.
> 
> -- Noel.
> 
> On Fri, Nov 27, 2009 at 16:25, Greg Brown <gk...@mac.com> wrote:
>> We chose to go with bean-style getters and setters across the board, thinking that Sun might have done the same were they to revisit the collections today. Also, wherever possible, we prefer to name methods using an imperative form. "getLength()" is consistent with that approach, and its intent is clear: it gets the length of the sequence. Based on this convention, naming the method "size()" would imply that we want to use the verb form of "size", and that the result of the method might somehow alter the size of the collection, which is not correct.
>> 
>> G
>> 
>> On Nov 27, 2009, at 5:46 AM, Noel Grandin wrote:
>> 
>>> Hi
>>> 
>>> I realise that I'm nitpicking, but why does Sequence have a
>>> getLength() method instead of a size() method?
>>> 
>>> My brain is habituated to the normal JDK collections, and I keep
>>> typing size() and wondering why it isn't working.
>>> 
>>> Thanks, Noel.
>> 
>> 


Re: nitpicking: Sequence.getLength()

Posted by Noel Grandin <no...@gmail.com>.
I see the rationale, but in API design, there comes a point where
adherence to stylistic rules has to give way to human processes and
usage patterns.
The existing "length" field on arrays and size() method on collections
API is simply too widespread and too ingrained into the collective
Java-programmer consciousness to be fought against.

Anyhow, not serious, just my 2c.

-- Noel.

On Fri, Nov 27, 2009 at 16:25, Greg Brown <gk...@mac.com> wrote:
> We chose to go with bean-style getters and setters across the board, thinking that Sun might have done the same were they to revisit the collections today. Also, wherever possible, we prefer to name methods using an imperative form. "getLength()" is consistent with that approach, and its intent is clear: it gets the length of the sequence. Based on this convention, naming the method "size()" would imply that we want to use the verb form of "size", and that the result of the method might somehow alter the size of the collection, which is not correct.
>
> G
>
> On Nov 27, 2009, at 5:46 AM, Noel Grandin wrote:
>
>> Hi
>>
>> I realise that I'm nitpicking, but why does Sequence have a
>> getLength() method instead of a size() method?
>>
>> My brain is habituated to the normal JDK collections, and I keep
>> typing size() and wondering why it isn't working.
>>
>> Thanks, Noel.
>
>

Re: nitpicking: Sequence.getLength()

Posted by Greg Brown <gk...@mac.com>.
We chose to go with bean-style getters and setters across the board, thinking that Sun might have done the same were they to revisit the collections today. Also, wherever possible, we prefer to name methods using an imperative form. "getLength()" is consistent with that approach, and its intent is clear: it gets the length of the sequence. Based on this convention, naming the method "size()" would imply that we want to use the verb form of "size", and that the result of the method might somehow alter the size of the collection, which is not correct.

G

On Nov 27, 2009, at 5:46 AM, Noel Grandin wrote:

> Hi
> 
> I realise that I'm nitpicking, but why does Sequence have a
> getLength() method instead of a size() method?
> 
> My brain is habituated to the normal JDK collections, and I keep
> typing size() and wondering why it isn't working.
> 
> Thanks, Noel.