Upgrade to Pro — share decks privately, control downloads, hide ads and more …

10 Commandments for iOS Software Development

10 Commandments for iOS Software Development

Presentation shown in the Mobile Developer Summit in Bangalore, India, on November 2011

Adrian Kosmaczewski
PRO

December 27, 2011
Tweet

More Decks by Adrian Kosmaczewski

Other Decks in Programming

Transcript

  1. View Slide

  2. Ten Commandments for
    iOS Software Dev
    Adrian Kosmaczewski, akosma software

    View Slide

  3. http://www.flickr.com/photos/gi/164281467/

    View Slide

  4. http://www.flickr.com/photos/jm3/379494322/

    View Slide

  5. http://www.flickr.com/photos/[email protected]/2168398185/

    View Slide

  6. http://www.flickr.com/photos/emiliagarassino/2146648332/

    View Slide

  7. akosma software

    View Slide

  8. akosma.com
    @akosmasoftware
    facebook.com/akosmasoftware

    View Slide

  9. View Slide

  10. View Slide

  11. View Slide

  12. Some questions

    View Slide

  13. Who’s new to iOS?

    View Slide

  14. Which technologies?

    View Slide

  15. J2EE
    J2ME
    .NET
    Ruby / Rails
    others?

    View Slide

  16. Which programming
    languages?

    View Slide

  17. C / C++?
    Java, C#?
    Ruby, Python, Lua?
    JavaScript?
    Fortran, Lisp, COBOL?

    View Slide

  18. View Slide

  19. 10 Commandments

    View Slide

  20. http://www.flickr.com/photos/oseillo/345879263/

    View Slide

  21. http://www.flickr.com/photos/justdrew1985/4348527596/

    View Slide

  22. View Slide

  23. 1

    View Slide

  24. Thou shalt manage
    memory properly

    View Slide

  25. http://www.flickr.com/photos/blakespot/3030107382/

    View Slide

  26. • iPhone and iPhone 3G: 128 MB RAM
    • iPhone 3GS and iPad 1: 256 MB RAM
    • iPhone 4, 4S and iPad 2: 512 MB RAM

    View Slide

  27. > 70 MB for the OS!

    View Slide

  28. no swap file

    View Slide

  29. (no virtual memory)

    View Slide

  30. http://www.flickr.com/photos/cheek/699407283/

    View Slide

  31. no garbage collection

    View Slide

  32. objects have a
    “retain count”

    View Slide

  33. http://cocoadevcentral.com/d/learn_objectivec/

    View Slide

  34. basic rule:

    View Slide

  35. for every
    [alloc], [retain], [copy]
    there must be a
    [release]

    View Slide

  36. beware:

    View Slide

  37. Objective-C only allows
    objects on the heap

    View Slide

  38. http://linguiniontheceiling.blogspot.com/2008/10/thats-madame-trash-heap-to-you.html

    View Slide

  39. No automatic objects
    on the stack (C++)

    View Slide

  40. http://www.futuregov.net/photologue/photo/2008/aug/30/stack-papers/

    View Slide

  41. // C++
    // Memory freed when out of scope
    std::string name(“Adrian”);
    std::string *name = NULL;
    name = new std::string(“Adrian”);
    delete name;

    View Slide

  42. iPhone OS
    memory warnings

    View Slide

  43. View Slide

  44. http://www.flickr.com/photos/tbuser/2763035540/

    View Slide

  45. http://akosma.com/2009/01/28/10-iphone-memory-management-tips/

    View Slide

  46. View Slide

  47. 2

    View Slide

  48. Thou shalt remove all
    compiler warnings

    View Slide

  49. View Slide

  50. View Slide

  51. GCC_TREAT_WARNINGS_AS_ERRORS
    -Werror

    View Slide

  52. View Slide

  53. Why Warnings?

    View Slide

  54. • Using deprecated symbols;
    • Calling method names not declared in included headers;
    • Calling methods belonging to implicit protocols;
    • Forgetting to return a result in methods not returning “void”;
    • Forgetting to #import the header file of a class declared as a forward
    “@class”;
    • Downcasting values and pointers implicitly.

    View Slide

  55. Solutions

    View Slide

  56. Make your intentions
    explicit to the compiler

    View Slide

  57. • Make implicit protocols explicit
    • Create categories for private methods
    • Turn implicit type conversions and casts into
    explicit ones
    • Use @class in the @interface, #import on the
    @implementation

    View Slide

  58. http://akosma.com/2009/07/16/objective-c-compiler-warnings/

    View Slide

  59. View Slide

  60. 3

    View Slide

  61. Honor the Human Interface
    Guidelines

    View Slide

  62. http://developer.apple.com/iphone/
    library/documentation/userexperience/
    conceptual/mobilehig/

    View Slide

  63. View Slide

  64. View Slide

  65. Your Objective:

    View Slide

  66. avoid rejections

    View Slide

  67. View Slide

  68. http://flyosity.com/application-design/iphone-application-design-patterns.php

    View Slide

  69. http://www.smashingmagazine.com/2009/07/21/iphone-apps-design-mistakes-
    overblown-visuals/

    View Slide

  70. http://www.mobileorchard.com/avoiding-iphone-app-rejection-from-apple/

    View Slide

  71. http://www.apprejected.com/

    View Slide

  72. http://appreview.tumblr.com/

    View Slide

  73. http://kosmaczewski.net/2009/08/03/risk-management-in-iphone-projects/

    View Slide

  74. Your Objective:

    View Slide

  75. avoid this

    View Slide

  76. http://www.flickr.com/photos/gruber/2635257578/

    View Slide

  77. and this

    View Slide

  78. http://smokingapples.com/iphone/app-store-iphone/the-worst-twitter-client-ever/

    View Slide


  79. I can’t find one redeeming quality about this app. It’s slow to start [on a 3GS], doesn’t
    respond to taps while it’s trying to load other things, and crashes if you try to change
    modes a lot. It’s limited to only timeline, replies, and messages. It has no other
    functionality. Oh wait… I forgot its killer feature, you can have custom backgrounds and
    choose the color of your tweets. That totally makes up for its lack of useful features
    and sluggish performance. I’m not sure why someone would bother building such an
    inferior app other than that they wanted to find some suckers and score a quick buck. It
    seems even more insane to me that they’d be actively seeking out reviewers to cover
    this. I was given a promo code for ChillTwit, and even for free I didn’t want it on my
    phone. I was sad just from looking at screenshots. Actually seeing it running confirmed
    all of my fears. If it was a free app, I might forgive the developer, but the fact that he’s
    trying to get $0.99 out of people pisses me off to no end. Go buy Tweetie.
    If you somehow weren’t scared away by all my bitching and whinning, you can see
    ChillTwit on the app store here. But seriously, if you buy this, we’re not friends
    anymore.

    View Slide

  80. View Slide

  81. 4

    View Slide

  82. Thou shalt optimize for
    performance

    View Slide

  83. • Drawing and scrolling
    • Application launch
    • Files and data
    • Power and battery life

    View Slide

  84. Drawing and scrolling

    View Slide

  85. • UIView subclasses are already optimized
    • Custom views should use setNeedsDisplayInRect:
    whenever possible
    • Cache static objects

    View Slide

  86. • Use opaque views
    • Avoid allocating while scrolling
    • Reuse table cells
    • Collapse view hierarchies

    View Slide

  87. Application Launch

    View Slide

  88. • Design apps for quick launch and short use
    • Load data lazily
    • Load only images needed

    View Slide

  89. Files and Data

    View Slide

  90. • Use Core Data for large datasets
    • Avoid loading large files in memory
    • Use plist files for structured static data

    View Slide

  91. Power management

    View Slide

  92. • 3G communications are expensive
    • Wi-Fi slightly cheaper
    • Send small chunks of data at low frequency
    • Prefer “chunky” to “chatty” protocols
    • Better performance ==
    longer battery life

    View Slide

  93. View Slide

  94. 5

    View Slide

  95. Thou shalt test in the
    device

    View Slide

  96. http://www.flickr.com/photos/edans/1526393678/

    View Slide

  97. • Camera
    • Accelerometer
    • GPS
    • Compass
    • Battery
    • Network
    • ... Speed!
    http://www.flickr.com/photos/tensafefrogs/728581345/

    View Slide

  98. http://www.flickr.com/photos/schill/969088410/

    View Slide

  99. http://www.flickr.com/photos/jaytamboli/3788327603/

    View Slide

  100. Keep your old iPhone
    3G(S), 4, or iPod
    touches!

    View Slide

  101. http://en.wikipedia.org/wiki/File:3rareiphoneviews.jpg

    View Slide

  102. View Slide

  103. 6

    View Slide

  104. Thou shalt unleash the
    power of Instruments

    View Slide

  105. View Slide

  106. Instruments

    View Slide

  107. View Slide

  108. View Slide

  109. View Slide

  110. View Slide

  111. View Slide

  112. 7

    View Slide

  113. Thou shalt use PNG
    files

    View Slide

  114. Portable Network Graphics (PNG) is a
    bitmapped image format that employs lossless
    data compression. PNG was created to improve
    upon and replace GIF (Graphics Interchange
    Format) as an image-file format not requiring a
    patent license. It is pronounced /ˈpɪŋ/ [1] or spelled
    out as P-N-G. The PNG acronym is optionally
    recursive, unofficially standing for “PNG's Not
    GIF”.[2]
    http://en.wikipedia.org/wiki/Portable_Network_Graphics

    View Slide

  115. Advantages

    View Slide

  116. Compression on build

    View Slide

  117. Low memory footprint

    View Slide

  118. Supported by all editors

    View Slide

  119. Quality

    View Slide

  120. http://en.wikipedia.org/wiki/File:Comparison_of_JPEG_and_PNG.png

    View Slide

  121. Transparency

    View Slide

  122. http://en.wikipedia.org/wiki/Portable_Network_Graphics

    View Slide

  123. • App icon: 57x57
    “Icon.png”
    • Default image: 480x320
    “Default.png”
    • Settings icon: 29x29
    “Icon-Small.png”

    View Slide

  124. View Slide

  125. App Icon

    View Slide

  126. Design in maximum
    quality, then reduce

    View Slide

  127. Do not apply effects

    View Slide

  128. http://developer.apple.com/iphone/library/documentation/userexperience/conceptual/mobilehig/

    View Slide

  129. 512x512 72 DPI TIFF
    file
    for App Store

    View Slide

  130. View Slide

  131. 8

    View Slide

  132. Thou shalt use static
    analysis

    View Slide

  133. http://llvm.org/

    View Slide

  134. http://clang-analyzer.llvm.org/

    View Slide

  135. Source: Apple Documentation

    View Slide

  136. Source: Apple Documentation

    View Slide

  137. Source: Apple Documentation

    View Slide

  138. Source: Apple Documentation

    View Slide

  139. View Slide

  140. View Slide

  141. 9

    View Slide

  142. Thou shalt care about
    accessibility

    View Slide

  143. Setting the accessibility
    properties in Xcode

    View Slide

  144. View Slide

  145. simple

    View Slide

  146. and there’s no reason
    not to do it.

    View Slide

  147. call to action!

    View Slide

  148. Add accessibility
    information to your
    apps now!

    View Slide

  149. View Slide

  150. 10

    View Slide

  151. Thou shalt have project
    management hygiene

    View Slide

  152. • Project management
    • Human resource management
    • Developer working conditions
    • Prototypes
    • Quality management
    • Code organization

    View Slide

  153. http://kosmaczewski.net/2009/07/28/code-organization-in-xcode-projects/

    View Slide

  154. Your objective:

    View Slide

  155. avoid chaos

    View Slide

  156. http://www1.standishgroup.com/newsroom/chaos_2009.php

    View Slide

  157. http://www.geekonomicsbook.com/

    View Slide

  158. View Slide

  159. 11

    View Slide

  160. Thou shalt have fun!

    View Slide

  161. and

    View Slide

  162. be creative!

    View Slide

  163. View Slide

  164. View Slide

  165. View Slide

  166. Recap’

    View Slide

  167. 1. Manage memory properly
    2. Remove compiler warnings
    3. Read the Human Interface Guidelines
    4. Optimize for performance
    5. Test in the device

    View Slide

  168. 6. Know your developer tools
    7. Use PNG files
    8. Use static analysis
    9. Care about accessibility
    10. Have project management hygiene

    View Slide

  169. 11. Have fun and be creative!

    View Slide

  170. Thanks!

    View Slide

  171. Slides available in
    slideshare.net/akosma

    View Slide

  172. Questions?

    View Slide

  173. akosma.com
    @akosmasoftware
    facebook.com/akosmasoftware

    View Slide

  174. View Slide