How to name a method properly?

101 Views Asked by At

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;
}
2

There are 2 best solutions below

6
Anoop Vaidya On BEST ANSWER

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

2
QuentinUK On

Describe what is being done:-

getNumberOfLines

The other could be ambiguous

getLineNumbers

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