Board index » delphi » Re: Singulars

Re: Singulars


2004-11-05 05:12:28 AM
delphi74
Jens Gruschel writes:
Quote
Especially since English is not my native language ...
Your English is excellent.
Quote
Now what about this?

type
TMyCollection = class
private
FItems: TList;
function GetItems(Index: Integer): TMyItem;
public
property Items[Index: Integer]: TMyItem read GetItems;
end;

I'm using the plural "Items" here. But "GetItems" is a bit confusing,
because it only returns one item, so I would probably better use
"GetItem" instead. On the other hand most naming conventions say that
the getter method should equals "Get" plus the name property.
That convention is for un-indexed properties. The convention is
slightly different for indexed properties.
The name of an indexed property should be pluralised (as you've done),
but the getter and setter should be singular (GetItem, not GetItems).
- Peter Gummer
 
 

Re: Singulars

Especially since English is not my native language (but of course it's
the same problem with other languages as well), I sometimes don't know
whether to use singular or plural for my array variables and properties.
To know what I mean, take a look at:
var
Person: TPerson;
Persons: array of TPerson;
That looks quite logical to me, althoug using Persons[3] is a bit
confusing, because it actually is only one person. But at least you see
that you are dealing with a collection, so I think it is alright.
Now what about this?
type
TMyCollection = class
private
FItems: TList;
function GetItems(Index: Integer): TMyItem;
public
property Items[Index: Integer]: TMyItem read GetItems;
end;
I'm using the plural "Items" here. But "GetItems" is a bit confusing,
because it only returns one item, so I would probably better use "GetItem"
instead. On the other hand most naming conventions say that the getter
method should equals "Get" plus the name property. Maybe it is better to
name the property "Item" and the getter method "GetItem", but than...
should I name the private field "FItem", which doesn't sound much like a
list? And what about using the property? The same problem as above:
MyItem := MyCollection.Items[3] or MyItem := MyCollection.Item[3]?
Am I just bored? Maybe. But what do you think about it?
Jens