While working on on open source project, I came across the following C function declaration and implementation:
// FSNData.h
NSString *stringForMimeType(Mime
In short, C (or C++) implementations are very useful:
What benefit exists (other than coding style) for favouring a C function over a class method?
Of course you won't always hurt paying for things you don't need or use -- and remember that ObjC class methods have some benefits over C functions, too. So, just look at C or C++ implementations as another tool in your toolbox. I find them very useful as complexity and project sizes increase, and they can be used to make your programs much faster. Just do what you are least likely to regret in 2015 ;)
You already touched on the marginal performance difference of avoiding an objc_msgSend
call. Objective-C class methods are also subject to overriding in subclasses, so implementing a method in C will prevent it from being overridden in a subclass. Relatedly, because of that runtime inheritance/polymorphism, an Objective-C method can never be inlined, whereas a C function can potentially be inlined by the compiler for added performance.
When it comes to avoiding objc_msgSend
, a wise man once told me, "If the overhead of objc_msgSend
is too great for you, Objective-C is probably the wrong tool for the job."