$30 off During Our Annual Pro Sale. View Details »

Ten Commandments for iPhone Software Development

Ten Commandments for iPhone Software Development

Presentation shown at the JAOO iPhone Dev Days in Zürich, Switzerland.

Adrian Kosmaczewski

October 03, 2009
Tweet

More Decks by Adrian Kosmaczewski

Other Decks in Technology

Transcript

  1. Ten Commandments
    for iPhone Software Development

    View Slide

  2. View Slide

  3. Adrian
    Kosmaczewski

    View Slide

  4. akosma software

    View Slide

  5. all in lowercase!

    View Slide

  6. akosma.com
    akosma.tumblr.com
    github.com/akosma
    linkedin.com/in/akosma
    facebook.com/akosma

    View Slide

  7. twitter.com/akosma
    kosmaczewski.net

    View Slide

  8. View Slide

  9. View Slide

  10. Some questions

    View Slide

  11. Who’s new to
    iPhone?

    View Slide

  12. Which technologies?

    View Slide

  13. J2EE
    J2ME
    .NET
    Ruby / Rails
    others?

    View Slide

  14. Which programming
    languages?

    View Slide

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

    View Slide

  16. View Slide

  17. 10 Commandments

    View Slide

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

    View Slide

  19. View Slide

  20. 1

    View Slide

  21. Thou shalt manage
    memory properly

    View Slide

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

    View Slide

  23. 128 or 256 MB RAM

    View Slide

  24. ±70 MB for the OS!

    View Slide

  25. no swap file

    View Slide

  26. (no virtual memory)

    View Slide

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

    View Slide

  28. no garbage
    collection

    View Slide

  29. Objects have a
    “retain count”

    View Slide

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

    View Slide

  31. basic rule:

    View Slide

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

    View Slide

  33. beware:

    View Slide

  34. Objective-C only allows
    objects on the heap

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  39. iPhone OS
    memory warnings

    View Slide

  40. View Slide

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

    View Slide

  42. http://kosmaczewski.net/2009/01/28/10-iphone-memory-management-tips/

    View Slide

  43. View Slide

  44. 2

    View Slide

  45. Thou shalt remove all
    compiler warnings

    View Slide

  46. View Slide

  47. View Slide

  48. GCC_TREAT_WARNINGS_AS_ERRORS
    -Werror

    View Slide

  49. View Slide

  50. Why Warnings?

    View Slide

  51. •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

  52. Solutions

    View Slide

  53. Make your intentions
    explicit to the compiler

    View Slide

  54. •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

  55. http://kosmaczewski.net/2009/07/16/objective-c-compiler-warnings/

    View Slide

  56. View Slide

  57. 3

    View Slide

  58. Honor the Human
    Interface Guidelines

    View Slide

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

    View Slide

  60. View Slide

  61. View Slide

  62. Your Objective:

    View Slide

  63. avoid rejections

    View Slide

  64. View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  68. http://www.apprejected.com/

    View Slide

  69. http://appreview.tumblr.com/

    View Slide

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

    View Slide

  71. Your Objective:

    View Slide

  72. avoid this

    View Slide

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

    View Slide

  74. and this

    View Slide

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

    View Slide


  76. 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

  77. View Slide

  78. 4

    View Slide

  79. Thou shalt optimize
    for performance

    View Slide

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

    View Slide

  81. Drawing and
    scrolling

    View Slide

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

    View Slide

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

    View Slide

  84. Application Launch

    View Slide

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

    View Slide

  86. Files and Data

    View Slide

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

    View Slide

  88. Power management

    View Slide

  89. •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

  90. View Slide

  91. 5

    View Slide

  92. Thou shalt test in
    the device

    View Slide

  93. http://blogs.tech-recipes.com/itouchmyiphone/2008/03/26/
    from-iphone-sdk-to-simple-app-in-less-than-452-seconds/

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  98. View Slide

  99. 6

    View Slide

  100. Remember your
    developer tools

    View Slide

  101. View Slide

  102. View Slide

  103. Shark

    View Slide

  104. View Slide

  105. View Slide

  106. Instruments

    View Slide

  107. View Slide

  108. View Slide

  109. View Slide

  110. View Slide

  111. 7

    View Slide

  112. Thou shalt use PNG
    files

    View Slide

  113. 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

  114. Advantages

    View Slide

  115. Compression on
    build

    View Slide

  116. Low memory
    footprint

    View Slide

  117. Supported by all
    editors

    View Slide

  118. Quality

    View Slide

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

    View Slide

  120. Transparency

    View Slide

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

    View Slide

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

    View Slide

  123. App Icon

    View Slide

  124. Design in maximum
    quality, then reduce

    View Slide

  125. Do not apply effects

    View Slide

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

    View Slide

  127. 512x512 72 DPI
    TIFF file
    for App Store

    View Slide

  128. View Slide

  129. 8

    View Slide

  130. Thou shalt use
    static analysis

    View Slide

  131. http://llvm.org/

    View Slide

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

    View Slide

  133. View Slide

  134. Source: Apple Documentation

    View Slide

  135. Source: Apple Documentation

    View Slide

  136. Source: Apple Documentation

    View Slide

  137. Source: Apple Documentation

    View Slide

  138. View Slide

  139. 9

    View Slide

  140. Thou shalt have
    project management
    hygiene

    View Slide

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

    View Slide

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

    View Slide

  143. Your objective:

    View Slide

  144. avoid chaos

    View Slide

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

    View Slide

  146. http://www.geekonomicsbook.com/

    View Slide

  147. View Slide

  148. 10

    View Slide

  149. Thou shalt have
    fun!

    View Slide

  150. and

    View Slide

  151. be creative!

    View Slide

  152. View Slide

  153. View Slide

  154. View Slide

  155. Recap’

    View Slide

  156. 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

  157. 6. Know your developer tools
    7. Use PNG files
    8. Use static analysis
    9. Have project management hygiene
    10. Have fun and be creative!

    View Slide

  158. Thanks!

    View Slide

  159. Slides available in
    slideshare.net/akosma/presentations

    View Slide

  160. Questions?

    View Slide