SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
Switch/Case
Fika Time

zonble
很多時候你不該⽤用
Boolean,⽽而是 Enum
你真的需要
這麼多 Boolean 嗎?
其實你需要的是 Enum
其實你需要的是 Enum
• ⼀一起聽只有:未連線、台長、聽眾,三種狀狀態

• ⽤用三個 Bool 會變成八種狀狀態,但有五種狀狀態不可能出現

• 如果進入這五種狀狀態,就是 Bug
⼀一個需要分段載入的畫⾯面
⽤用了了多個 Bool 表⽰示「是否初次載入」、
「是否載入中」、「是否還需要改入更更多資料」…
⼀一個需要分段載入的畫⾯面
需求往往不是⼀一次提出來來的…
• ⼀一開始沒做載入中動畫,為了了呈現載入進度,所以多⼀一個
Bool 判斷…

• ⼀一開始沒做錯誤處理理,為了了呈現錯誤,所以多⼀一個 Bool 判
斷…

• ⼀一開始沒做 Empty Set,所以多⼀一個 Bool 判斷…

• 但,放任歷史的遺跡殘留留,就會讓程式碼失控
UI Stack
•Ideal State
•Empty State
•Error State
•Partial State
•Loading State
⼀一個需要分段載入的畫⾯面
加上⼀一點 Swift 特性
⼀一個需要分段載入的畫⾯面
⼀一個需要分段載入的畫⾯面
測試 case 也好寫了了
• 測試某些 Action 是否會讓畫⾯面進入某個 State

• 測試某個 State 下 Layout 出來來的畫⾯面是否符合預期
歌曲辨識
其實就是:
Empty State
Loading State
Ideal State
Error State
什什麼可以⽤用
Switch/Case 改寫?
FizzBuzz
根據不同時段給不同圖片
Tuple

Weitere ähnliche Inhalte

Was ist angesagt?

Colorful world-of-visual-automation-testing-latest
Colorful world-of-visual-automation-testing-latestColorful world-of-visual-automation-testing-latest
Colorful world-of-visual-automation-testing-latestOnur Baskirt
 
Playwright: A New Test Automation Framework for the Modern Web
Playwright: A New Test Automation Framework for the Modern WebPlaywright: A New Test Automation Framework for the Modern Web
Playwright: A New Test Automation Framework for the Modern WebApplitools
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with ExamplesGabriele Lana
 
用 Go 語言實戰 Push Notification 服務
用 Go 語言實戰 Push Notification 服務用 Go 語言實戰 Push Notification 服務
用 Go 語言實戰 Push Notification 服務Bo-Yi Wu
 
Pipeline based deployments on Jenkins
Pipeline based deployments  on JenkinsPipeline based deployments  on Jenkins
Pipeline based deployments on JenkinsKnoldus Inc.
 
기본적인 테스트에 대한 pytest 자동화 접근
기본적인 테스트에 대한 pytest 자동화 접근기본적인 테스트에 대한 pytest 자동화 접근
기본적인 테스트에 대한 pytest 자동화 접근SangIn Choung
 
Introducing BDD and TDD with Cucumber
Introducing BDD and TDD with CucumberIntroducing BDD and TDD with Cucumber
Introducing BDD and TDD with CucumberKnoldus Inc.
 
Robot Framework Introduction
Robot Framework IntroductionRobot Framework Introduction
Robot Framework IntroductionPekka Klärck
 
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...Edureka!
 
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022Johnny Sung
 
WebRTC 품질 측정 기초
WebRTC 품질 측정 기초WebRTC 품질 측정 기초
WebRTC 품질 측정 기초Blisson Choi
 
Setting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation FrameworkSetting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation Frameworkvaluebound
 
Cypress-vs-Playwright: Let the Code Speak
Cypress-vs-Playwright: Let the Code SpeakCypress-vs-Playwright: Let the Code Speak
Cypress-vs-Playwright: Let the Code SpeakApplitools
 
Easy REST Integrations with Lightning Components and Salesforce1
Easy REST Integrations with Lightning Components and Salesforce1Easy REST Integrations with Lightning Components and Salesforce1
Easy REST Integrations with Lightning Components and Salesforce1Salesforce Developers
 
[COSCUP 2022] Kotlin Collection 遊樂園
[COSCUP 2022] Kotlin Collection 遊樂園[COSCUP 2022] Kotlin Collection 遊樂園
[COSCUP 2022] Kotlin Collection 遊樂園Shengyou Fan
 
Automating deployments from GitHub using SaltStack
Automating deployments from GitHub using SaltStackAutomating deployments from GitHub using SaltStack
Automating deployments from GitHub using SaltStackLINE Corporation
 
Angular and The Case for RxJS
Angular and The Case for RxJSAngular and The Case for RxJS
Angular and The Case for RxJSSandi Barr
 

Was ist angesagt? (20)

Colorful world-of-visual-automation-testing-latest
Colorful world-of-visual-automation-testing-latestColorful world-of-visual-automation-testing-latest
Colorful world-of-visual-automation-testing-latest
 
Playwright: A New Test Automation Framework for the Modern Web
Playwright: A New Test Automation Framework for the Modern WebPlaywright: A New Test Automation Framework for the Modern Web
Playwright: A New Test Automation Framework for the Modern Web
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
用 Go 語言實戰 Push Notification 服務
用 Go 語言實戰 Push Notification 服務用 Go 語言實戰 Push Notification 服務
用 Go 語言實戰 Push Notification 服務
 
Pipeline based deployments on Jenkins
Pipeline based deployments  on JenkinsPipeline based deployments  on Jenkins
Pipeline based deployments on Jenkins
 
기본적인 테스트에 대한 pytest 자동화 접근
기본적인 테스트에 대한 pytest 자동화 접근기본적인 테스트에 대한 pytest 자동화 접근
기본적인 테스트에 대한 pytest 자동화 접근
 
Ant, Maven and Jenkins
Ant, Maven and JenkinsAnt, Maven and Jenkins
Ant, Maven and Jenkins
 
Introducing BDD and TDD with Cucumber
Introducing BDD and TDD with CucumberIntroducing BDD and TDD with Cucumber
Introducing BDD and TDD with Cucumber
 
Robot Framework Introduction
Robot Framework IntroductionRobot Framework Introduction
Robot Framework Introduction
 
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
 
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
 
WebRTC 품질 측정 기초
WebRTC 품질 측정 기초WebRTC 품질 측정 기초
WebRTC 품질 측정 기초
 
Setting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation FrameworkSetting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation Framework
 
Cypress-vs-Playwright: Let the Code Speak
Cypress-vs-Playwright: Let the Code SpeakCypress-vs-Playwright: Let the Code Speak
Cypress-vs-Playwright: Let the Code Speak
 
Easy REST Integrations with Lightning Components and Salesforce1
Easy REST Integrations with Lightning Components and Salesforce1Easy REST Integrations with Lightning Components and Salesforce1
Easy REST Integrations with Lightning Components and Salesforce1
 
[COSCUP 2022] Kotlin Collection 遊樂園
[COSCUP 2022] Kotlin Collection 遊樂園[COSCUP 2022] Kotlin Collection 遊樂園
[COSCUP 2022] Kotlin Collection 遊樂園
 
Testing Services
Testing ServicesTesting Services
Testing Services
 
Automating deployments from GitHub using SaltStack
Automating deployments from GitHub using SaltStackAutomating deployments from GitHub using SaltStack
Automating deployments from GitHub using SaltStack
 
Selenium
SeleniumSelenium
Selenium
 
Angular and The Case for RxJS
Angular and The Case for RxJSAngular and The Case for RxJS
Angular and The Case for RxJS
 

Mehr von Weizhong Yang

怎樣在 Flutter app 中使用 Google Maps
怎樣在 Flutter app 中使用 Google Maps怎樣在 Flutter app 中使用 Google Maps
怎樣在 Flutter app 中使用 Google MapsWeizhong Yang
 
關於延長役期這件事情
關於延長役期這件事情關於延長役期這件事情
關於延長役期這件事情Weizhong Yang
 
導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事Weizhong Yang
 
iPlayground: CarPlay and MFI Hearing Aids
iPlayground: CarPlay and MFI Hearing AidsiPlayground: CarPlay and MFI Hearing Aids
iPlayground: CarPlay and MFI Hearing AidsWeizhong Yang
 
CocoaPods private repo
CocoaPods private repoCocoaPods private repo
CocoaPods private repoWeizhong Yang
 
Flutter 踩雷心得
Flutter 踩雷心得Flutter 踩雷心得
Flutter 踩雷心得Weizhong Yang
 
那些年被蘋果 Ban 掉的 API
那些年被蘋果 Ban 掉的 API那些年被蘋果 Ban 掉的 API
那些年被蘋果 Ban 掉的 APIWeizhong Yang
 
苦集滅道:透過開發客製 Sketch Plug-in 改善產品設計流程
苦集滅道:透過開發客製 Sketch Plug-in  改善產品設計流程苦集滅道:透過開發客製 Sketch Plug-in  改善產品設計流程
苦集滅道:透過開發客製 Sketch Plug-in 改善產品設計流程Weizhong Yang
 
怎樣寫出比較沒有問題的 Code
怎樣寫出比較沒有問題的 Code怎樣寫出比較沒有問題的 Code
怎樣寫出比較沒有問題的 CodeWeizhong Yang
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented ProgrammingWeizhong Yang
 
Mac OS X 與 iOS 的 Audio API
Mac OS X 與 iOS 的 Audio APIMac OS X 與 iOS 的 Audio API
Mac OS X 與 iOS 的 Audio APIWeizhong Yang
 
Python 的文件系統
Python 的文件系統Python 的文件系統
Python 的文件系統Weizhong Yang
 

Mehr von Weizhong Yang (20)

Flutter BLE
Flutter BLEFlutter BLE
Flutter BLE
 
怎樣在 Flutter app 中使用 Google Maps
怎樣在 Flutter app 中使用 Google Maps怎樣在 Flutter app 中使用 Google Maps
怎樣在 Flutter app 中使用 Google Maps
 
關於延長役期這件事情
關於延長役期這件事情關於延長役期這件事情
關於延長役期這件事情
 
Dart null safety
Dart null safetyDart null safety
Dart null safety
 
導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事導入 Flutter 前你應該知道的事
導入 Flutter 前你應該知道的事
 
Github Actions
Github ActionsGithub Actions
Github Actions
 
iPlayground: CarPlay and MFI Hearing Aids
iPlayground: CarPlay and MFI Hearing AidsiPlayground: CarPlay and MFI Hearing Aids
iPlayground: CarPlay and MFI Hearing Aids
 
CocoaPods private repo
CocoaPods private repoCocoaPods private repo
CocoaPods private repo
 
Flutter 踩雷心得
Flutter 踩雷心得Flutter 踩雷心得
Flutter 踩雷心得
 
那些年被蘋果 Ban 掉的 API
那些年被蘋果 Ban 掉的 API那些年被蘋果 Ban 掉的 API
那些年被蘋果 Ban 掉的 API
 
苦集滅道:透過開發客製 Sketch Plug-in 改善產品設計流程
苦集滅道:透過開發客製 Sketch Plug-in  改善產品設計流程苦集滅道:透過開發客製 Sketch Plug-in  改善產品設計流程
苦集滅道:透過開發客製 Sketch Plug-in 改善產品設計流程
 
怎樣寫出比較沒有問題的 Code
怎樣寫出比較沒有問題的 Code怎樣寫出比較沒有問題的 Code
怎樣寫出比較沒有問題的 Code
 
貪食蛇
貪食蛇貪食蛇
貪食蛇
 
Aspect Oriented Programming
Aspect Oriented ProgrammingAspect Oriented Programming
Aspect Oriented Programming
 
Mac OS X 與 iOS 的 Audio API
Mac OS X 與 iOS 的 Audio APIMac OS X 與 iOS 的 Audio API
Mac OS X 與 iOS 的 Audio API
 
Html 5 native drag
Html 5 native dragHtml 5 native drag
Html 5 native drag
 
Retina mac
Retina macRetina mac
Retina mac
 
Python 的文件系統
Python 的文件系統Python 的文件系統
Python 的文件系統
 
Refactoring
RefactoringRefactoring
Refactoring
 
Core animation
Core animationCore animation
Core animation
 

使用 switch/case 重構程式碼