Naming Functions (original) (raw)
Objective-C allows you to express behavior through functions as well as methods. You should use functions rather than, say, class methods, when the underlying object is always a singleton or when you are dealing with obviously functional subsystems.
Functions have some general naming rules that you should follow:
- Function names are formed like method names, but with a couple exceptions:
- They start with the same prefix that you use for classes and constants.
- The first letter of the word after the prefix is capitalized.
- Most function names start with verbs that describe the effect the function has:
NSHighlightRect |
---|
NSDeallocateObject |
Functions that query properties have a further set of naming rules:
- If the function returns the property of its first argument, omit the verb.
unsigned int NSEventMaskFromType(NSEventType type) float NSHeight(NSRect aRect) - If the value is returned by reference, use “Get”.
const char *NSGetSizeAndAlignment(const char *typePtr, unsigned int *sizep, unsigned int *alignp) - If the value returned is a boolean, the function should begin with an inflected verb.
BOOL NSDecimalIsNotANumber(const NSDecimal *decimal)