Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Dirty Code
Search
Jason
October 20, 2018
Programming
2k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Dirty Code
Dirty Code from me.....
Jason
October 20, 2018
Other Decks in Programming
See All in Programming
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.2k
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.1k
すこし踏み込む CancellationToken
htkym
2
1.7k
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
32k
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
880
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2k
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
Next.js: The final boss of Web Performance
guaca
0
250
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
270
golang-bob.pdf
iwatsukayura
0
130
Jetpack Compose Mechanisms
skydoves
3
820
Domain-Driven Transformation
hschwentner
2
2.3k
Featured
See All Featured
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
460
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
Optimizing for Happiness
mojombo
378
71k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
270
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
A better future with KSS
kneath
240
18k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
730
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
820
Writing Fast Ruby
sferik
630
63k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
580
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Transcript
Dirty Code 凋零的程式碼 Jason Wu 1
⾃自我介紹 • Jason Wu • iOS ⼯工程師經驗三年年 • rod5438 @gmail.com
2
⼤大綱 • Clean Code 無瑕的程式碼 • Jungle Pattern 叢林林模式 •
Dirty Code 範例例分享 !3
Clean Code 無瑕的程式碼 !4
• 完美應付PM未來來(開完Spec後...)的需求 • 完美應付老闆未來來(開完Spec後五天...)的需求 • 完全不需要額外⽂文件 • 完全沒有模凌兩兩可 • 完全沒有多餘的code
• etc.. !5
Do not reinvent a wheel !6
This is not a wheel !7
– Jason Wu 「Do not reinvent a wheel, And broken
wheel is not a wheel。」
Open-Closed principle !9
!10
Jungle Pattern 叢林林模式 !11
發明⼈人 • Benson Lu • CTO of • 我真的⽤用這個Pattern 寫
code 12
None
• ⼀一堆系統同時運作且肯定不是獨立運作 • 幾乎不可能維護 但竟然還是有⼈人可以維護 • Closed-open principle !14
• 程式寫起來來很像迷失在叢林林 • 你就是不想進去叢林林 • 對! 因為你現在住在都市 !15
• Anti-Pattern • Andrew Richard Koenig • https://en.wikipedia.org/wiki/Anti-pattern !16
Dirty Code 範例例分享 !17
• 拼錯字 • 變數與⽅方法任意放置 • 程式碼風格沒有⼀一⾄至 !18
• 命名不精確 • ⽅方法有多餘的 side effect • ⽤用錯 Design Pattern
(⽤用了了叢林林模式...) • etc. !19
• 有⼀一個 Class A 的 Class method a1 • a1
叫⽤用了了 Class B 的 Class method b1 • 後來來我才發現 b1 竟然是去叫⽤用 Class A 的 a2..... !20
• Code review 我看到這樣 [self showView:YES]; • 點去標頭檔寫這樣 - (void)showView:(BOOL)hidden;
• ⼤大哥....不要這樣.... !21
• 有⼀一個 Class 介⾯面很精簡 • 還以為是遇到 Clean Code!! • 原來來他的
input 都是依賴 NSUserDefaults !22
• ⼤大約有八種View 都在聽 NotificationReload • 且 八個data source 都來來⾃自於⼀一整包 userInfo
• 所以每個view 有可能會 reload 八次 !23
• 我看到 - (void)downloadA:(void (^)(void))completion; • 還看到 - (void)downloadB:(void (^)(void))completion;
• 竟然還有 - (void)downloadAB:(void (^)(void))completion;
• 有⼀一個 ViewController • 在他的 root view 底下 有將近40個 sub
view • 沒問題 再繼續加 20 個 ! !25
• 2015年年初這個 Class 才 8000 ⾏行行 • 經過兩兩年年的努⼒力力 • 2017年年中
達到了了 18788 ⾏行行 !26
• 有個 View ⽤用 int style 來來表⽰示 View 的風格 •
但是 style 0, 1, 2, 3 都不是PM要的 • 所以我⼜又加入⼀一堆 if (style == 4) !27
• 那個萬⾏行行的 Class 裡⾯面滿滿的 switch statement • 其中每個 statement ⾄至少
20 個 case • 甚⾄至⼀一個 function 內還塞了了兩兩組 switch statement !28
• 有關 UICollectionView 的 BUG • 把所有操作再丟⼀一次 main queue 就解決了了
• 我也不知道為什什麼 !29
• 有⼀一個 Array 被初始化了了五次 • 但是第五次資料是錯的⽽而產⽣生了了 BUG • 為了了解 BUG
我初始化了了第六次...... !30
• 有⼀一個 AdView 他也負責下載廣告資料 • 但是有些地⽅方只需要廣告 ⽤用不到 AdView • 我還是
new 這個 AdView 出來來幫我下載廣告 !31
• 有個舊功能需要顯⽰示使⽤用者姓名、電話 • 寫成 NSArray <NSString *> *names, *numbers; •
新功能我再寫了了四個陣列列存了了地址、星座、興趣、⼤大頭貼 !32
• 有⼀一個Class 他很客氣的給了了 80 個 property • 其實仔細看可以發現 每⼗十個 property
有⾼高度聚合 • 再給他加 20 個 湊 100 !33
⼯工程師兩兩難 • 不⽋欠技術債 • ⽋欠技術債 • https://medium.com/@p5d12000/⼯工程師應該放⼼心⼤大膽地 創造技術負債-a8022d85810 !34
The End