I have been developing on the iPhone with Objective-C for a few months now and I have been applying the best-practices learnt and refined while developing applications with Java. These include: designing classes that have a single responsibility, application of design patterns where appropriate, and writing short methods that do one thing only. To me these practices are both beneficial from a clean-code perspective and are largely domain agnostic.
I have been quite happy with the results. However, a few iPhone developers have independently advised me against this as they say I write too many classes and too many methods. At various times I have been warned:
- The stack will blow
- Too many classes will slow the iPhone down (i.e perceptible by the user)
- Nested method calls will hurt performance (i.e perceptible by the user)
In practice I haven't experienced these issues. Looking superficially at some iPhone performance metrics it seems to me that the extra method calls and object life-cycle overhead required to implement common patterns and short methods is unlikely to create any user perceptible delay. However, the advice from other iPhone developers has me spooked a little.
I would like to continue learning and refining the domain agnostic programming practices that have served me well in the past, but when developing on the iPhone I don't wish to head down a route that will end in pain!
So with regard to this platform - should I forsake some common best-practices and be more conscious of optimizing method call and object life-cycle overheads? Or should I continue following Knuth's advice:
Premature optimization is the root of all evil (or at least most of it) in programming