Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting clean, performant code for the iPhone
    text
    copied!<p>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 <a href="http://c2.com/cgi/wiki?ShortMethods" rel="nofollow noreferrer">short methods</a> that do one thing only. To me these practices are both beneficial from a <a href="http://www.informit.com/articles/article.aspx?p=1235624" rel="nofollow noreferrer">clean-code</a> perspective and are largely domain agnostic.</p> <p>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:</p> <ul> <li>The stack will blow</li> <li>Too many classes will slow the iPhone down (i.e perceptible by the user)</li> <li>Nested method calls will hurt performance (i.e perceptible by the user)</li> </ul> <p>In practice I haven't experienced these issues. Looking superficially at some <a href="http://www.mikeash.com/?page=pyblog/performance-comparisons-of-common-operations-iphone-edition.html" rel="nofollow noreferrer">iPhone performance metrics</a> 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.</p> <p>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!</p> <p>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 <a href="http://en.wikiquote.org/wiki/Donald_Knuth#Quotes_about_Donald_Knuth" rel="nofollow noreferrer">Knuth's</a> advice:</p> <blockquote> <p>Premature optimization is the root of all evil (or at least most of it) in programming</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload