Slide 1

Slide 1 text

Ten Commandments for iPhone Software Development

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Adrian Kosmaczewski

Slide 4

Slide 4 text

akosma software

Slide 5

Slide 5 text

all in lowercase!

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

twitter.com/akosma kosmaczewski.net

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Some questions

Slide 11

Slide 11 text

Who’s new to iPhone?

Slide 12

Slide 12 text

Which technologies?

Slide 13

Slide 13 text

J2EE J2ME .NET Ruby / Rails others?

Slide 14

Slide 14 text

Which programming languages?

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

10 Commandments

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

1

Slide 21

Slide 21 text

Thou shalt manage memory properly

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

128 or 256 MB RAM

Slide 24

Slide 24 text

±70 MB for the OS!

Slide 25

Slide 25 text

no swap file

Slide 26

Slide 26 text

(no virtual memory)

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

no garbage collection

Slide 29

Slide 29 text

Objects have a “retain count”

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

basic rule:

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

beware:

Slide 34

Slide 34 text

Objective-C only allows objects on the heap

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

No automatic objects on the stack (C++)

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

iPhone OS memory warnings

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

2

Slide 45

Slide 45 text

Thou shalt remove all compiler warnings

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

GCC_TREAT_WARNINGS_AS_ERRORS -Werror

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Why Warnings?

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

Solutions

Slide 53

Slide 53 text

Make your intentions explicit to the compiler

Slide 54

Slide 54 text

•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

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

3

Slide 58

Slide 58 text

Honor the Human Interface Guidelines

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

Your Objective:

Slide 63

Slide 63 text

avoid rejections

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

http://www.apprejected.com/

Slide 69

Slide 69 text

http://appreview.tumblr.com/

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

Your Objective:

Slide 72

Slide 72 text

avoid this

Slide 73

Slide 73 text

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

Slide 74

Slide 74 text

and this

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

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

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

4

Slide 79

Slide 79 text

Thou shalt optimize for performance

Slide 80

Slide 80 text

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

Slide 81

Slide 81 text

Drawing and scrolling

Slide 82

Slide 82 text

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

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

Application Launch

Slide 85

Slide 85 text

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

Slide 86

Slide 86 text

Files and Data

Slide 87

Slide 87 text

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

Slide 88

Slide 88 text

Power management

Slide 89

Slide 89 text

•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

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

5

Slide 92

Slide 92 text

Thou shalt test in the device

Slide 93

Slide 93 text

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

Slide 94

Slide 94 text

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

Slide 95

Slide 95 text

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

Slide 96

Slide 96 text

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

Slide 97

Slide 97 text

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

Slide 98

Slide 98 text

No content

Slide 99

Slide 99 text

6

Slide 100

Slide 100 text

Remember your developer tools

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

Shark

Slide 104

Slide 104 text

No content

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

Instruments

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

7

Slide 112

Slide 112 text

Thou shalt use PNG files

Slide 113

Slide 113 text

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

Slide 114

Slide 114 text

Advantages

Slide 115

Slide 115 text

Compression on build

Slide 116

Slide 116 text

Low memory footprint

Slide 117

Slide 117 text

Supported by all editors

Slide 118

Slide 118 text

Quality

Slide 119

Slide 119 text

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

Slide 120

Slide 120 text

Transparency

Slide 121

Slide 121 text

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

Slide 122

Slide 122 text

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

Slide 123

Slide 123 text

App Icon

Slide 124

Slide 124 text

Design in maximum quality, then reduce

Slide 125

Slide 125 text

Do not apply effects

Slide 126

Slide 126 text

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

Slide 127

Slide 127 text

512x512 72 DPI TIFF file for App Store

Slide 128

Slide 128 text

No content

Slide 129

Slide 129 text

8

Slide 130

Slide 130 text

Thou shalt use static analysis

Slide 131

Slide 131 text

http://llvm.org/

Slide 132

Slide 132 text

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

Slide 133

Slide 133 text

No content

Slide 134

Slide 134 text

Source: Apple Documentation

Slide 135

Slide 135 text

Source: Apple Documentation

Slide 136

Slide 136 text

Source: Apple Documentation

Slide 137

Slide 137 text

Source: Apple Documentation

Slide 138

Slide 138 text

No content

Slide 139

Slide 139 text

9

Slide 140

Slide 140 text

Thou shalt have project management hygiene

Slide 141

Slide 141 text

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

Slide 142

Slide 142 text

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

Slide 143

Slide 143 text

Your objective:

Slide 144

Slide 144 text

avoid chaos

Slide 145

Slide 145 text

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

Slide 146

Slide 146 text

http://www.geekonomicsbook.com/

Slide 147

Slide 147 text

No content

Slide 148

Slide 148 text

10

Slide 149

Slide 149 text

Thou shalt have fun!

Slide 150

Slide 150 text

and

Slide 151

Slide 151 text

be creative!

Slide 152

Slide 152 text

No content

Slide 153

Slide 153 text

No content

Slide 154

Slide 154 text

No content

Slide 155

Slide 155 text

Recap’

Slide 156

Slide 156 text

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

Slide 157

Slide 157 text

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

Slide 158

Slide 158 text

Thanks!

Slide 159

Slide 159 text

Slides available in slideshare.net/akosma/presentations

Slide 160

Slide 160 text

Questions?