Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The Evolution of a Cocoa Programmer
Search
Chris Eidhof | @chriseidhof
January 11, 2014
Technology
790
8
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
The Evolution of a Cocoa Programmer
Chris Eidhof | @chriseidhof
January 11, 2014
More Decks by Chris Eidhof | @chriseidhof
See All by Chris Eidhof | @chriseidhof
Dutch FP Day 2015
chriseidhof
2
400
Tiny Networking in Swift
chriseidhof
2
19k
Functional Swift - Brooklyn
chriseidhof
3
1.3k
Functional Swift - SF
chriseidhof
6
26k
Functional Swift
chriseidhof
6
1.3k
Functional Swift
chriseidhof
1
170
Functional Programming in Swift
chriseidhof
40
19k
Lighter View Controllers
chriseidhof
4
220
Parsing with Blocks
chriseidhof
2
260
Other Decks in Technology
See All in Technology
OPENLOGI Company Profile for engineer
hr01
1
74k
非定型なドキュメントを効率よくリファクタする 〜えぇ!?仕様書27本の移行が1日で終わったって!?〜
subroh0508
2
590
AI時代の開発生産性を捉え直す — 経営と現場をつなぐ「開発組織のオブザーバビリティ」— / AI Dev Ex Conference 2026
tkyowa
0
800
OpenTelemetryにおけるGoのゼロコード・コンパイル時計装について #fukuokago
quiver
0
170
AIとハーネスで育てるトランスコンパイラ / 20260722 Yasushi Katayama
shift_evolve
PRO
1
470
CDKで書くECSのベストプラクティス、 改めて考え直す2026 #cdkconf2026
makies
3
890
[2026-07-15] AI Ready なはずだったアーキテクチャと、見えてきた課題・次に目指す状態
wxyzzz
11
4.1k
AIが当たり前の組織で エンジニアはどう育つか
nishihira
1
560
AI時代におけるエンジニアの新たな役割──FDEとクオリアの探求/登壇資料(戸井田 裕貴)
hacobu
PRO
0
150
第67回コンピュータビジョン勉強会CVPR2026読会前編
tsukamotokenji
0
160
「顧客の声を聞かなければ何も始まらない」 ── 顧客の声から生まれた『AI返信補助機能』の開発プロセス / AICon2026_shikata_imai
rakus_dev
0
230
DatabricksにおけるMCPソリューション
taka_aki
1
310
Featured
See All Featured
Building AI with AI
inesmontani
PRO
1
1.1k
Deep Space Network (abreviated)
tonyrice
0
230
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
610
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
220
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
240
AI: The stuff that nobody shows you
jnunemaker
PRO
9
840
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
My Coaching Mixtape
mlcsv
0
170
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
500
Transcript
The evolution of a Cocoa Programmer Chris Eidhof Mobile Central
Europe 2014
Hashtags #mceconf #mce-evolution
None
None
commit c416c1d259bddaa74833e6df5acd770f85622293 Author: Chris Eidhof <
[email protected]
> Date: Wed Jan 7
11:54:34 2009 +0100 Empty project
I thought I was a pretty good programmer
I knew PHP, Ruby and Haskell
How hard can it be?
Example code @interface HiscoreTableViewCell : UITableViewCell { IBOutlet UIImageView *badge;
IBOutlet UILabel *badgeTitle; IBOutlet UILabel *name1; IBOutlet UILabel *name2; IBOutlet UILabel *name3; IBOutlet UILabel *position1; IBOutlet UILabel *position2; IBOutlet UILabel *position3; IBOutlet UILabel *score1; IBOutlet UILabel *score2; IBOutlet UILabel *score3; }
Example code (continued) @property (nonatomic,readonly) UIImageView* badge; @property (nonatomic,readonly) UILabel
*badgeTitle; @property (nonatomic,readonly) UILabel *name1; @property (nonatomic,readonly) UILabel *name2; @property (nonatomic,readonly) UILabel *name3; @property (nonatomic,readonly) UILabel *position1; @property (nonatomic,readonly) UILabel *position2; @property (nonatomic,readonly) UILabel *position3; @property (nonatomic,readonly) UILabel *score1;
Example code (continued) @synthesize badge; @synthesize badgeTitle; @synthesize name1; @synthesize
name2; @synthesize name3; @synthesize position1; @synthesize position2; @synthesize position3; @synthesize score1; @synthesize score2; @synthesize score3;
There's more
//TODO: as of here, it is completely broken if ([gameView
superview] != nil) { [[SoundBoard sharedSoundBoard] startMenuTune]; [menuViewController viewWillAppear:YES]; [gameViewController viewWillDisappear:YES]; [gameView removeFromSuperview]; [gameViewController viewDidDisappear:YES]; [menuViewController viewDidAppear:YES]; } else {
NSURL *cgiUrl = [NSURL URLWithString:POST_SCORE_URL]; NSMutableURLRequest *p = [NSMutableURLRequest requestWithURL:cgiUrl];
[p setTimeoutInterval:4]; [p setHTTPMethod:@"POST"]; [p setHTTPBody:requestData]; NSURLResponse *response = nil; NSError *error = nil; NSData *responseData = [NSURLConnection sendSynchronousRequest:p returningResponse:&response error:&error];
How did I get better?
If there's only one thing you'll remember Write code for
the person after you
EDD Embarassment-Driven Development
—Write a lot of code —Work with other people —Write
articles —Read books and code
Write a lot of code —Lots of production code —Lots
of throwaway code
None
Collaborate —With people who are better than you —Or who
aren't better than you
Write Forces you to think.
Learn your frameworks —Use Core Data —Use UITableViewController —Use NSURLSession
Absolute Knowledge
2014 1986 1988 1990 1992 1994 1996 1998 2000 2002
2004 2006 2008 2010 2012 1 2 3 4 5 Time How much I know
Perceived Knowledge
2014 1986 1988 1990 1992 1994 1996 1998 2000 2002
2004 2006 2008 2010 2012 1 2 3 4 5 Time How much I know
Strive to become better
Ship
Writing better code —Quick wins —Value Objects —Lighter View Controllers
Quick Wins
I used to do this: if (buttonIndex == 0)
I used to do this: if (buttonIndex == 0) instead,
now I write if (buttonIndex == StartButton)
I used to write this: if ([game state] == running
|| self.trainingMode)
I used to write this: if ([game state] == running
|| self.trainingMode) Now I write this: BOOL shouldPauseGame = game.state == running || self.trainingMode; if (shouldPauseGame)
Write small files I aim for 100-150 lines
Write small files 325 ./THStyleSheet.m 279 THSkillboxView.m 263 THCardsViewController.m 243
THTimeLineView.m 221 THScreeningBarViewController.m 192 THEditPriorityViewController.m 185 User+Extensions.m 183 THScreenInstanceViewController.m 183 THRootViewController.m 179 THUserScreenInstancesController.m 168 THPriorityTimelineCollectionController.m 155 UIView+Extensions.m 155 NSArray+Extensions.m 154 THZoomingNavigationController.m
Write small files find . -name "*.m" -exec wc -l
"{}" \; | sort -n
Use protocols instead of class inheritance They are much more
flexible and make for clearer code.
Deep code paths - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { if (alertState
== submitScore && game.score > 0) { // 20 lines if (result != nil && [resultKeys containsObject:@"position"] && [resultKeys containsObject:@"neededPoints"] && [resultKeys containsObject:@"deviceHighscore"] && [resultKeys
Deep code paths Pull out things into separate, well-named methods
Don't write fast code Optimize for readability
Really learn Interface Builder This makes prototyping much faster
Learn your frameworks
What prevents me from using Core Data at this point
is my concern for scalability and performance. It’s possible I’m just being thick-headed. — Brent Simmons, 27 Sep 2013
So last weekend I switched from SQLite/FMDB to Core Data.
This may come as a surprise. — Brent Simmons, 05 Oct 2013
Core Data —Relationships —Batching —NSFetchedResultsController —Speed of use
Value Objects
I used NSDictionary for everything NSDate* birthDate = [NSDate dateWithTimeIntervalSince1970:131855*3600];
NSDictionary* person = @{ @"name": @"Chris", @"birthdate": birthDate, @"numberOfKids": @0 };
Problems with NSDictionary —It's not typechecked —It might be mutated
A first step @interface Person : NSObject @property (nonatomic,copy) NSString*
name; @property (nonatomic) NSDate* birthDate; @property (nonatomic) NSUInteger numberOfKids; @end
Mutation Sometimes mutation is very handy. Most of the times
it will bite you.
@interface Person : NSObject @property (nonatomic,readonly) NSString* name; @property (nonatomic,readonly)
NSDate* birthDate; @property (nonatomic,readonly) NSUInteger numberOfKids; - (instancetype) initWithName:(NSString*)name birthDate:(NSDate*)birthDate numberOfKids:(NSUInteger)numberOfKids; @end
Value Objects —Use lots of them. —Make them immutable.
Lighter View Controllers
Keep your view controllers light This is the least reusable
code you'll write
What can you do? —Smarter views —Smarter models —Use view
controller transitions —Use categories to populate views —Pull out protocols
Use categories to populate views - (UITableViewCell*)tableView:(UITableView*)tv cellForRowAtIndexPath:(NSIndexPath*)ip { User
*user = [self userAtIndexPath:ip]; MyCell *cell = [tv dequeueReusableCellWithIdentifier:ruI forIndexPath:ip]; cell.textLabel.text = user.name; cell.imageView.image = user.avatar; .... }
Use categories to populate views @interface MyCell (ConfigureForUser) - (void)configureForUser:(User
*)user; @end
Use categories to populate views - (void)configureForUser:(User *)user { cell.textLabel.text
= user.name; cell.imageView.image = user.avatar; ... }
Use categories to populate views —Your view controller is a
bit simpler —Your population code can be reused ... —But now your view knows about your model. Sort of.
Pulling out protocols
Pulling out protocols For example: UITableViewDataSource
Creating a separate data source object @interface FetchedResultsControllerDataSource : NSObject
<UITableViewDataSource, NSFetchedResultsControllerDelegate>
Creating a separate data source object - (NSInteger)numberOfSectionsInTableView: (UITableView*)t {
return self.fetchedResultsController.sections.count; }
Creating a separate data source object - (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)sectionIndex {
id<NSFetchedResultsSectionInfo> section; section = self.frc.sections[sectionIndex]; return section.numberOfObjects; }
Creating a separate data source object Working with the delegate
- (UITableViewCell*)tableView:(UITableView*)tv cellForRowAtIndexPath:(NSIndexPath*)ip { id object = [self objectAtIndexPath:indexPath]; id cell = [tv dequeueReusableCellWithIdentifier:ruI forIndexPath:ip]; [self.delegate configureCell:cell withObject:object]; return cell; }
Advantages of a separate data source —Lighter view controller —Testable
—Reusable And you can do this for other protocols, too
A separate data source —NSArrayDataSource —NSFRCollectionViewController —...
So.... —Write for the person after you —Know your frameworks
—Keep your view controllers light
Commercial Break
None
Questions? @chriseidhof