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 <[email protected]> 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.
>> 
>> 

Reply via email to