-1

It's more a question about English grammar, but nevertheless, can you tell me which one is a correct method name? This ambiguity drives me crazy.

Method linesNumber returns number of "rows" in some sort of table. I personally like "numberOfLines" variant, but linesNumber is shorter...

#pragma mark - RCGroupDataSource methods

- (NSUInteger)linesNumber { // ???: or numberOfLines or lineNumbers
    return 2;
}
yaru
  • 1,260
  • 1
  • 13
  • 29
  • For what it's worth, as a native English speaker I find "linesNumber" awkward and nonobvious. I'd go with "numberOfRowsInTable" as Anoop Vaidya suggests. – bdesham Feb 26 '13 at 14:48
  • `numberOfLines` would be correct the others wouldn't make sense for the purpose of why you are using it. When naming methods try to have them make sense for the purpose of the method. So if you had a method returning the number of rows in section have `numberOfRowsInSection` or if it was a calculation have have a method called `calculation` and so on it would be good naming convention. Also Anoop Vaidya is correct why not use `numberOfRowsInTable` – Popeye Feb 26 '13 at 14:50

2 Answers2

2

Always give full name as you can.

Method linesNumber returns number of "rows" in some sort of table.

why not use numberOfRowsInTable

You can refer AppleDocumentation and CocoaDevCentral

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • I'd also like to add that methods are typically actions so it's also good practice to put a verb in the name (GetNumberOfRowsInTable). You beat me to this by just a few seconds – brenton Feb 26 '13 at 14:48
  • 2
    @brenton I don't think "get" methods in Objective-C often, if ever, actually have "get" in their names. – bdesham Feb 26 '13 at 14:49
  • 1
    if the class is a table i would go only for numberOfRows, as in table would be implicit by calling the method on a Table object. otherwise up for the Anoop suggestion – Ultrakorne Feb 26 '13 at 14:49
  • **NO** dont put Get and Put in cocoa, Have you seen anywhere in cocoa framework as GetString or getString? – Anoop Vaidya Feb 26 '13 at 14:50
  • brenton, it's a method from a datasource - should it still has verbal form? – yaru Feb 26 '13 at 14:50
  • @brenton NO do not use get or GET this is bad naming convention in cocoa. You can have set but they don't have get on there getters. it is generally just something like `- (NSString*)name;` as the getter and `- (void)setName:(NSString*)aName;` as the setter. – Popeye Feb 26 '13 at 14:53
0

Describe what is being done:-

getNumberOfLines

The other could be ambiguous

getLineNumbers

Sound more like a plural, ie an array of numbers.

QuentinUK
  • 2,997
  • 21
  • 20