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
Working With Legacy Code - iOS TDD Workshop
Search
Maciej Oczko
July 05, 2014
Programming
170
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Working With Legacy Code - iOS TDD Workshop
Talk given on iOS TDD Workshop in Berlin.
Maciej Oczko
July 05, 2014
More Decks by Maciej Oczko
See All by Maciej Oczko
Dependency Injection on iOS
maciejoczko
1
130
Working with Legacy Code (Łódź)
maciejoczko
0
59
iOS TDD Workshop (Gdańsk)
maciejoczko
1
85
UICollectionView Basics and Flow Layout
maciejoczko
0
240
UICollectionView Introduction
maciejoczko
0
63
Depenedency Injection in iOS
maciejoczko
0
73
Other Decks in Programming
See All in Programming
DynamoDBの基礎を振り返りながらベクトル検索機能を理解する
musan
3
250
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
370
Deep dive into the select statement (GopherCon UK)
jespino
0
160
Claude Code全社展開のためにやったことn選~プラグイン302個・コミッター271人を支えるために~
kenchan
5
1.8k
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
400
AI時代に学ぶ 好きなルール 嫌いなルール Linter編
shorty5121
0
220
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
170
Oxlintはいいぞ(続)
yug1224
1
490
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
550
Cloudflare is Agents
chimame
0
180
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.4k
プロポーザルを書いてもらう
pvcresin
0
590
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.5k
The Invisible Side of Design
smashingmag
301
52k
Ethics towards AI in product and experience design
skipperchong
2
350
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.9k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
400
HDC tutorial
michielstock
2
830
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Optimising Largest Contentful Paint
csswizardry
37
3.9k
The browser strikes back
jonoalderson
0
1.6k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
390
Everyday Curiosity
cassininazir
0
300
Transcript
Working With Code Legacy @maciejoczko #tddberlin
Code is you didn’t write this morning (yet). What is
LegacyCode? Code is legacy code as soon as it's written. @maciejoczko #tddberlin
Code is legacy code as soon as it's written. Michael
Feathers, Working Effectively with Legacy Code What is LegacyCode? Code is you didn’t write this morning (yet). @maciejoczko #tddberlin
Code without tests* Inherited code Poorly designed code Too complicated
code Illegible code *Michael Feathers What is LegacyCode? Code is legacy code as soon as it's written. Michael Feathers, Working Effectively with Legacy Code @maciejoczko #tddberlin
Testing scenario #1 Task @maciejoczko #tddberlin
How to approach it? Identify change points Find an inflection
point Cover the Make changes Refactor the covered code inflection point @maciejoczko #tddberlin
B A D C E inflection point @maciejoczko #tddberlin
Violation of Single Responsibility Principle Violation of Open-Closed Principle inflection
point @maciejoczko #tddberlin
inflection point Covering external dependencies Break @maciejoczko #tddberlin
inflection point Covering external dependencies internal dependencies Break Break @maciejoczko
#tddberlin
inflection point Covering external dependencies internal dependencies Write tests Break
Break @maciejoczko #tddberlin
inflection point Covering external dependencies internal dependencies Write tests Break
Break @maciejoczko #tddberlin
- (NSUInteger)calculatePrice { ... StockAnalyzer *analyzer = [[StockAnalyzer alloc] init];
... } - (id)initWithAnalyzer:(id <AnalyzerProtocol>)analyzer { self = [super init]; if (self) { _analyzer = analyzer; } return self; } external dependencies Break @maciejoczko #tddberlin
external dependencies Break internal dependencies Write tests Break inflection point
Covering @maciejoczko #tddberlin
- (CGSize)calculateSize { ... UIScreen *screen = [UIScreen mainScreen]; ...
} - (CGSize)calculateSize { ... UIScreen *screen = [self screen]; ... } - (UIScreen *)screen { return [UIScreen mainScreen]; } Break internal dependencies @maciejoczko #tddberlin
external dependencies Break internal dependencies Write tests Break inflection point
Covering @maciejoczko #tddberlin
Write tests @maciejoczko #tddberlin
Make changes @maciejoczko #tddberlin
Testing scenario #2 Task @maciejoczko #tddberlin
When to Refactor? Too wide class responsibility Duplicated code Not
readable code Too many method arguments (more than 2) Method has more than 20 lines Class has more than 150-200 lines @maciejoczko #tddberlin
Keep in mind Composition over inheritance Avoid singletons Isolate dependencies
Inject dependencies @maciejoczko #tddberlin
Thanks! @maciejoczko #tddberlin