Slide 1

Slide 1 text

Tips & Tricks of Effective iOS Developers

Slide 2

Slide 2 text

BEN SCHEIRMAN @subdigital

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Weekly Screencasts on iOS DEVELOPMENT $9/month

Slide 5

Slide 5 text

Tips & Tricks of Effective iOS Developers

Slide 6

Slide 6 text

? Effective

Slide 7

Slide 7 text

effective |iˈfektiv| adjective ! successful in producing a desired or intended result

Slide 8

Slide 8 text

! DEVELOPERS Effective

Slide 9

Slide 9 text

! DEVELOPERS FIX PROBLEMS Effective

Slide 10

Slide 10 text

! DEVELOPERS WRITE CODE FASTER Effective

Slide 11

Slide 11 text

! DEVELOPERS CONFIDENTLY REFACTOR Effective

Slide 12

Slide 12 text

! DEVELOPERS WRITE BETTER CODE Effective

Slide 13

Slide 13 text

! DEVELOPERS WRITE FEWER BUGS Effective

Slide 14

Slide 14 text

! DEVELOPERS GET THINGS DONE Effective

Slide 15

Slide 15 text

! DEVELOPERS SHIP BETTER SOFTWARE Effective

Slide 16

Slide 16 text

SHIP BETTER SOFTWARE

Slide 17

Slide 17 text

ME?

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

I aspire to be Effective

Slide 20

Slide 20 text

Objective-C Tips

Slide 21

Slide 21 text

Always use braces for conditionals if ([self isHungry]) { [self eatBurger]; } if ([self isHungry]) [self eatBurger]; if ([self isHungry]) [self eatBurger]; [self takeNap]; if ([self isHungry]) { [self eatBurger]; [self takeNap]; }

Slide 22

Slide 22 text

if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0) goto fail; if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0) goto fail; goto fail; if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0) goto fail; ... ! fail: SSLFreeBuffer(&signedHashes); SSLFreeBuffer(&hashCtx); return err; Always use braces for conditionals

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

@interface Player ! - (void)moveLeft; - (void)moveRight; - (void)jump; - (void)hit; ! @end Use Class Continuations for Private Properties @interface Player () @property CGFloat health; @property Texture *texture; @end ! @implementation Player … @end Player.h Player.m

Slide 25

Slide 25 text

Use Class Continuations for Private Properties @interface ViewController () @property IBOutlet UILabel *label; @end ! @implementation ViewController … @end

Slide 26

Slide 26 text

Use intention revealing method names - (NSDate *)nextDate:(NSDate *); - (NSDate *)nextBillingDateAfterDate:(NSDate *);

Slide 27

Slide 27 text

Name single parameter BOOL arguments -(void)showPanel:(BOOL)animated; [self showPanel:NO];

Slide 28

Slide 28 text

Name single parameter BOOL arguments -(void)showPanelAnimated:(BOOL)animated; [self showPanelAnimated:NO];

Slide 29

Slide 29 text

Add Comment Documentation to Public Methods

Slide 30

Slide 30 text

- (void)viewDidLoad { [self.fetchedResultsController performFetch:nil]; } Lazily Initialize Properties - (NSFetchedResultsController *)fetchedResultsController { if (_frc == nil) { _frc = [[NSFetchedResultsController alloc] initWithFetchRequest: self.fetchRequest ... ] } ! return _frc; }

Slide 31

Slide 31 text

Lazily Initialize Properties - (NSFetchRequest *)fetchRequest { if (_fetchRequest == nil) { _fetchRequest = … } return _fetchRequest; }

Slide 32

Slide 32 text

Lazily Initialize Properties - (void)didReceiveMemoryWarning { self.fetchResultsController = nil; self.fetchRequest = nil; … }

Slide 33

Slide 33 text

Use Refactor Method judiciously - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *) indexPath { UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@“cell”]; NSArray *peopleInSection = self.sections[indexPath.section]; Person *person = peopleInSection[indexPath.row]; cell.textLabel.text = [NSString stringWithFormat:@“%@ %@“, person.firstName, person.lastName]; cell.detailTextLabel.text = person.email; return cell; }

Slide 34

Slide 34 text

Use Refactor Method judiciously - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *) indexPath { UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@“cell”]; Person *person = [self personAtIndexPath:indexPath]; cell.textLabel.text = [NSString stringWithFormat:@“%@ %@“, person.firstName, person.lastName]; cell.detailTextLabel.text = person.email; return cell; }

Slide 35

Slide 35 text

Use Refactor Method judiciously - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *) indexPath { UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@“cell”]; Person *person = [self personAtIndexPath:indexPath]; cell.textLabel.text = person.fullName; cell.detailTextLabel.text = person.email; return cell; }

Slide 36

Slide 36 text

Use Refactor Method judiciously - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *) indexPath { UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@“cell”]; Person *person = [self personAtIndexPath:indexPath]; [self updateCell:cell forPerson:person]; return cell; }

Slide 37

Slide 37 text

Understand Dependencies method1 method2

Slide 38

Slide 38 text

Understand Dependencies

Slide 39

Slide 39 text

Understand Dependencies

Slide 40

Slide 40 text

Understand Dependencies

Slide 41

Slide 41 text

Keep your dependencies in check OO is your friend

Slide 42

Slide 42 text

objc-dependency-visualizer http://paultaykalo.github.io/objc-dependency-visualizer

Slide 43

Slide 43 text

http://jomnius.blogspot.com/2012/01/dependency-graph-tool-for-ios-projects.html

Slide 44

Slide 44 text

http://jomnius.blogspot.com/2012/01/dependency-graph-tool-for-ios-projects.html

Slide 45

Slide 45 text

Reduce Dependencies by… Loose Coupling Programming to interfaces Dependency Inversion Reduce God Objects Reduce Singletons

Slide 46

Slide 46 text

With Less Dependencies you can… Refactor Change your mind Change your implementation Add features

Slide 47

Slide 47 text

“Ruthlessly modularize functionality. Design, implement, and package everything as if it were to be distributed as 3rd-party code”

Slide 48

Slide 48 text

“Ruthlessly modularize functionality. Design, implement, and package everything as if it were to be distributed as 3rd-party code”

Slide 49

Slide 49 text

Mattt Thompson

Slide 50

Slide 50 text

Slim down your classes

Slide 51

Slide 51 text

Slim down your classes

Slide 52

Slide 52 text

Try to impose limits

Slide 53

Slide 53 text

Challenge Yourself Photograph by Mikey Schaefer

Slide 54

Slide 54 text

Max LOC for .m: ~150 Max LOC for method: 4-5 Cesare Rocchi

Slide 55

Slide 55 text

Automate it

Slide 56

Slide 56 text

awk

Slide 57

Slide 57 text

find "${SRCROOT}" \(-name "*.h" -or -name "*.m"\) -and \( -path "${SRCROOT}/Pods/*" -prune -o -print0 \) | xargs -0 wc -l | awk '$1 > 400 && $2 != "total" { for(i=2;i

Slide 58

Slide 58 text

Xcode Tips

Slide 59

Slide 59 text

Completing Methods

Slide 60

Slide 60 text

“- ta”

Slide 61

Slide 61 text

Label your views in Interface Builder

Slide 62

Slide 62 text

Learn Keyboard Shortcuts Photo credit: Wikipedia

Slide 63

Slide 63 text

⌘0

Slide 64

Slide 64 text

⌘⌥0

Slide 65

Slide 65 text

⌘⇧J

Slide 66

Slide 66 text

⌘⇧Y

Slide 67

Slide 67 text

⌘⇧C

Slide 68

Slide 68 text

⌘⌃J ⌘⌃←

Slide 69

Slide 69 text

Jump in Assistant, back

Slide 70

Slide 70 text

⌘⌃E (Edit all in Scope)

Slide 71

Slide 71 text

⌃I (Re-indent selection)

Slide 72

Slide 72 text

So many to learn

Slide 73

Slide 73 text

Pick 2 you don’t know

Slide 74

Slide 74 text

Deliberately Practice them

Slide 75

Slide 75 text

Repeat.

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

Snippets

Slide 78

Slide 78 text

Xcode / TextExpander

Slide 79

Slide 79 text

“pns” @property (nonatomic, strong)

Slide 80

Slide 80 text

“propint” @property (nonatomic, assign) NSInteger

Slide 81

Slide 81 text

“propstr” @property (nonatomic, copy) NSString *

Slide 82

Slide 82 text

“mark” #pragma mark -

Slide 83

Slide 83 text

#pragma mark

Slide 84

Slide 84 text

#pragma mark

Slide 85

Slide 85 text

“tvds”

Slide 86

Slide 86 text

“swf”

Slide 87

Slide 87 text

“tvdel”

Slide 88

Slide 88 text

“networkact” [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

Slide 89

Slide 89 text

Repetitive code? Boilerplate code? ! Make a snippet.

Slide 90

Slide 90 text

Source Control Tips

Slide 91

Slide 91 text

(git)

Slide 92

Slide 92 text

Use the command line

Slide 93

Slide 93 text

Leverage GUIs for specific tasks

Slide 94

Slide 94 text

http://rowanj.github.io/gitx/ GitX

Slide 95

Slide 95 text

Commits aren’t just ⌘S

Slide 96

Slide 96 text

Commit in logical chunks.

Slide 97

Slide 97 text

Write a good commit message

Slide 98

Slide 98 text

http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html Capitalized, short (50 chars or less) summary ! More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together. ! Write your commit message in the imperative: "Fix bug" and not "Fixed bug" or "Fixes bug." This convention matches up with commit messages generated by commands like git merge and git revert. ! Further paragraphs come after blank lines. ! - Bullet points are okay, too ! - Typically a hyphen or asterisk is used for the bullet, followed by a single space, with blank lines in between, but conventions vary here ! - Use a hanging indent

Slide 99

Slide 99 text

$ git log --oneline ! 9511f6c Add mixpanel gem 47a3e6d Add a sleep to not get throttled by facebook ce30dcb Kick Jenkins build 2e6802f Merge pull request #981 from DeliRadio/venue-favorites-rabls 99eb628 stub master account to avoid fail when run in test suite. b4e0435 before(:all) -> before(:each) to avoid certain test to fail when execute e4b10b6 Update schema 7b1e053 Fix banner check for venues in autocomplete 83ca7cb Update ci reporter 6eae32f Fix admin manages events spec. 7c8902b Add new line at the end of file so Github likes it. a153a48 Call Rails.application.eager_load! right before it is needed so that its 4a4d050 Refactoring test so it finishes faster. 4155ac6 fix crash when correcting country code from geolocated params 08c5bdb Proper auth token generation for facebook login: 4efaf1e Venue needs to have shareable_id and shareable_type implementation. Defa a9cdd7a Implemented a test to check shareable_id and shareable_type. Since Favor 9e1e6c2 fix after_party task syntax dde3ae9 add after_party task to fill in fb birthdays where we can 6e99a74 Implemented tests to check renderability of all ActiveRecord instance th b174af9 Added four templates that are required for favoritable items. 07218a0 year_of_birth, not birth_year be562bf update attribs from fb even for existing users 29041f0 Add logging to facebook oauth responses

Slide 100

Slide 100 text

No content

Slide 101

Slide 101 text

Branches are basically free

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

REBASE Learn to

Slide 104

Slide 104 text

master origin/master

Slide 105

Slide 105 text

master origin/master

Slide 106

Slide 106 text

master origin/master MERGE METHOD “git pull” by default

Slide 107

Slide 107 text

master origin/master

Slide 108

Slide 108 text

master origin/master REBASE METHOD

Slide 109

Slide 109 text

99% of the time you want ! git pull --rebase

Slide 110

Slide 110 text

Make this the default git config branch.autosetuprebase always

Slide 111

Slide 111 text

Never rebase public branches

Slide 112

Slide 112 text

git bisect

Slide 113

Slide 113 text

No content

Slide 114

Slide 114 text

git bisect start

Slide 115

Slide 115 text

git bisect bad

Slide 116

Slide 116 text

git checkout HEAD~15

Slide 117

Slide 117 text

git bisect good

Slide 118

Slide 118 text

?

Slide 119

Slide 119 text

git bisect bad

Slide 120

Slide 120 text

git bisect bad

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

git bisect good

Slide 123

Slide 123 text

No content

Slide 124

Slide 124 text

git bisect good

Slide 125

Slide 125 text

No content

Slide 126

Slide 126 text

git bisect good

Slide 127

Slide 127 text

No content

Slide 128

Slide 128 text

git bisect run

Slide 129

Slide 129 text

Oops, I made a git mistake!

Slide 130

Slide 130 text

git reflog

Slide 131

Slide 131 text

No content

Slide 132

Slide 132 text

Branch Per Feature

Slide 133

Slide 133 text

Keep Master Releasable

Slide 134

Slide 134 text

Don’t veer too far from working software

Slide 135

Slide 135 text

“I attempt to keep the app in a working state as much as possible. That means test driving small changes, committing often, and only hooking things up to the UI when I think they're ready…”

Slide 136

Slide 136 text

“… If I'm not in a position to push my code at least every hour or so, I feel like I haven't broken my work down properly”

Slide 137

Slide 137 text

Stew Gleadow

Slide 138

Slide 138 text

http://collectorcare.blogspot.com/

Slide 139

Slide 139 text

http://cobcottagegifts.com/

Slide 140

Slide 140 text

Effective Habits

Slide 141

Slide 141 text

“I'm not a great programmer; I'm just a good programmer with great habits.” ! - Kent Beck

Slide 142

Slide 142 text

Keep an improvement list ! !

Slide 143

Slide 143 text

Have a side project ! !

Slide 144

Slide 144 text

Read Other People’s Code

Slide 145

Slide 145 text

“I form opinions about the code I study. Not all of it is good. I want to reflect on why I feel that way.”

Slide 146

Slide 146 text

Jonathan Penn

Slide 147

Slide 147 text

Learn how to ask for help

Slide 148

Slide 148 text

No content

Slide 149

Slide 149 text

No content

Slide 150

Slide 150 text

Don’t ask ! Questions. 5

Slide 151

Slide 151 text

Ask ! Question. 1

Slide 152

Slide 152 text

Distill The Problem

Slide 153

Slide 153 text

Reduce Variables

Slide 154

Slide 154 text

Also works for:

Slide 155

Slide 155 text

“Before asking for advice, take a careful look at what you know and what you are looking to have answered. Often that will put you in a spot where you answer your own question.” ! !

Slide 156

Slide 156 text

Daniel Steinberg

Slide 157

Slide 157 text

No content

Slide 158

Slide 158 text

Program in other Languages

Slide 159

Slide 159 text

“Don't just program in Objective C, make sure you regularly use another language. There is a lot we can learn from other technologies and communities” ! - Stew Gleadow ! !

Slide 160

Slide 160 text

Write Tests.

Slide 161

Slide 161 text

Go Forth, and be Effective

Slide 162

Slide 162 text

Thank you BEN SCHEIRMAN @subdigital chaione.com