Method name is shorter than 3 or longer than 40 characters
ID |
objectivec.maintainability.identifier_length |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Naming |
Language |
Objective-C |
Description
Reports the declaration of an instance or class method whose name falls outside a readable length band - shorter than 3 characters, or longer than 40. The name checked is the first keyword of the selector, or the whole name for a method that takes no arguments. The thresholds are fixed at 3 and 40, the defaults of the OCLint ShortMethodName and LongMethodName rules. Variable names are checked by their own rules and are not reported here.
Rationale
A method name is the part of a class that other code reads most and changes least, so its length is what the callers pay. Under three characters it carries no meaning at the call site - [shape x:3] says nothing about what happens - and it cannot be searched for, so the callers of the method cannot be found mechanically when it has to change. Over forty characters the name has usually absorbed the class and the caller’s context as well as its own job, which both pushes every call site past the column limit and hides the fact that the method is doing more than one thing.
The following code illustrates the pattern detected by this rule:
@implementation Geometry
// FLAGGED: Method name is shorter than 3 or longer than 40 characters
- (void)go {
NSLog(@"go");
}
@end