SlideShare uma empresa Scribd logo
1 de 34
Making Swift even safer
18 months of development
120k+ lines of Swift
≈40 releases
6 months in production
Juno Rider iOS
Stricter interface
extension Array {
public subscript (safe index: Int) -> Element? { … }
}
extension Int {
public init?(safe value: Float) { … }
public init?(safe value: Double) { … }
public init?(safe value: UInt) { … }
}
!
NonEmptyString
NonEmptyArray
NonNegativeDouble
Stronger types
struct LocationCoordinate<A> {
let value: Double
init(_ value: Double) { self.value = value }
}
enum Lat {}
enum Lon {}
struct Location {
let latitude: LocationCoordinate<Lat>
let longitude: LocationCoordinate<Lon>
}
Phantom types
struct TaggedValue<ValueType, Tag> {
let value: ValueType
init(_ value: ValueType) { self.value = value }
}
enum PickupTimeTag {}
typealias PickupTime = TaggedValue<NSDate, PickupTimeTag>
enum DropoffTimeTag {}
typealias DropoffTime = TaggedValue<NSDate, DropoffTimeTag>
Phantom types
enum PhoneTag {}
typealias Phone = TaggedValue<String, PhoneTag>
extension TaggedValueType where Tag == PhoneTag, ValueType == String {
func trimCountryCode() -> Phone {
return Phone(trimCountryCode(self.taggedValue.value))
}
}
private func trimCountryCode(phone: String) -> String { … }
Phantom types
extension TaggedValueType where ValueType: JSONEncoding {
func encodeJSON() -> AnyObject {
return self.taggedValue.value.encodeJSON()
}
}
Phantom types
enum StringKey {
case AccessibilityHomeConfirmButton
case DialogInsufficientFundsTitle
...
}
func localized(value: Strings) -> String {
switch value {
case .AccessibilityHomeConfirmButton:
return String.localized(“Accessibility.Home.Confirm.Button”)
...
}
}
Static resources
extension HTTP {
enum Error: ErrorType {
case InvalidResponse(request: NSURLRequest, response: NSURLResponse?)
case TransportError(request: NSURLRequest, error: NSError)
case HTTPError(request: NSURLRequest, response: NSHTTPURLResponse, responseData: NSData?)
case CannotCreateURL(components: NSURLComponents)
case InvalidURL(urlString: String)
case AuthServiceFailure
case CannotBindStreamPair(request: NSURLRequest)
case StreamWriting(request: NSURLRequest, error: NSError?)
case StreamGzipEncoding(request: NSURLRequest, operation: HTTP.Error.GzipOperation)
}
}
Strong ErrorType
extension JSON.Error {
struct Encode: ErrorType {
public let error: NSError
public let source: Any
}
enum Decode: ErrorType {
case Unexpected
case Serialization(error: NSError, data: NSData)
case SchemeMismatch(error: JSON.Error.SchemeMismatch, body: AnyObject?)
}
struct SchemeMismatch: ErrorType {
public let pathComponents: [String]
public let reason: String
}
}
Strong ErrorType
public enum JSONTaskError: ErrorType {
case Task(error: HTTP.Error)
case Request(error: JSON.Error.Encode)
case Response(response: HTTP.Response, error: JSON.Error.Decode)
}
Strong ErrorType
Changing code
Components
Context
App
Context
May contain dirty things dealing with global state
Context
May contain dirty things dealing with global state
Unit tests
Context
typealias AppContext = protocol<
StringsServiceContainer,
StaticImageServicesContainer,
BundleImagesServiceContainer,
ReachabilityServiceContainer,
AnalyticsServiceContainer,
SchedulerContainer,
RemoteNotificationsContainer,
RemoteNotificationsPermissionContainer,
RemoteNotificationClearActionContainer,
LocationServiceContainer,
ApplicationServiceContainer,
DeviceServiceContainer,
…
>
class ElDependor: AppContext { … }
class MockContext: AppContext { … }
App
Pure state machine
App
Pure state machine
- Unit tests
- Integrated acceptance tests
Acceptance tests via TestApp
class Allow_Rider_to_Have_Max_X_Cards_per_Account_Spec: QuickSpec {
override func spec() {
var app: TestApp!
beforeEach { app = TestApp() }
given("rider is entering CC details on Add CC screen") {
beforeEach {
app.login()
app.goToHomeScreen()
app.receiveSomePaymentMethods()
app.openPayments()
app.payments.paymentMethods.tapAddPayment()
app.payments.addPayment.enterSomeCC()
app.payments.addPayment.tapNext()
app.payments.addPayment.enterSomeZipCode()
}
when("rider taps Add CC button") {
beforeEach { app.payments.addPayment.tapDone() }
and("BE returns the message about max number of active cards") {
beforeEach { app._context.addCreditCard.receive(.Failed(.TooManyPaymentMethods)) }
then("present the Max Cards Added alert") {
app.payments.addPayment.expectToPresentAlert()
}
when("rider taps Ok button") {
beforeEach { app.payments.addPayment.alert.tapOK() }
then("dismiss the alert") {
app.payments.addPayment.expectToNotPresentAlert()
}
View: screenshot testing
View: screenshot testing
View: screenshot testing
Detecting & investigating bugs in the field
- smart assertions
- diligent logging
- daily duty
junoAssert
in Debug - crash 🙀
in Release - log.error(), trackNonFatal() and recover 🙏
Logging
switch error {
case let .InvalidResponse(value):
log.warn(
category: logCategory,
message: "Unexpected response",
payload: [
.RequestIdentifier: error.requestIdentifier,
.ResponseIdentifier: error.responseIdentifier,
.Description: "(value.response)",
.Path: value.request.path,
.URL: value.request.absoluteURL
]
)
…
Logging
Analytics junoAssert
↓ ↓
log.verbose log.info log.warn log.error
↓ ↓ ↓ ↓
{'key0':'value0','key1':‘value1'}
↓
append to txt file
↓
roll & upload to AWS
↓
Elasticsearch + Kibana
Logging
Production quality comes at a price
- takes up to x2 dev effort
- challenging for new team members
- performance considerations
But it brings satisfaction
Thank you

Mais conteúdo relacionado

Mais procurados

ReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better TogetherReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better TogetherColin Eberhardt
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvmArnaud Giuliani
 
One Year of Clean Architecture - The Good, The Bad and The Bob
One Year of Clean Architecture - The Good, The Bad and The BobOne Year of Clean Architecture - The Good, The Bad and The Bob
One Year of Clean Architecture - The Good, The Bad and The BobOCTO Technology
 
Intro to ReactiveCocoa
Intro to ReactiveCocoaIntro to ReactiveCocoa
Intro to ReactiveCocoakleneau
 
Introduction to idris
Introduction to idrisIntroduction to idris
Introduction to idrisConor Farrell
 
What make Swift Awesome
What make Swift AwesomeWhat make Swift Awesome
What make Swift AwesomeSokna Ly
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersBartosz Kosarzycki
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017Hardik Trivedi
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive CocoaSmartLogic
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyIván López Martín
 

Mais procurados (20)

JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 
Introduction to typescript
Introduction to typescriptIntroduction to typescript
Introduction to typescript
 
ReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better TogetherReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better Together
 
Compile time polymorphism
Compile time polymorphismCompile time polymorphism
Compile time polymorphism
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
 
One Year of Clean Architecture - The Good, The Bad and The Bob
One Year of Clean Architecture - The Good, The Bad and The BobOne Year of Clean Architecture - The Good, The Bad and The Bob
One Year of Clean Architecture - The Good, The Bad and The Bob
 
Overloading
OverloadingOverloading
Overloading
 
Intro to ReactiveCocoa
Intro to ReactiveCocoaIntro to ReactiveCocoa
Intro to ReactiveCocoa
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Introduction to idris
Introduction to idrisIntroduction to idris
Introduction to idris
 
Logging in code
Logging in codeLogging in code
Logging in code
 
What make Swift Awesome
What make Swift AwesomeWhat make Swift Awesome
What make Swift Awesome
 
Spring Transaction
Spring TransactionSpring Transaction
Spring Transaction
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
 

Semelhante a Making Swift even safer

Sane Sharding with Akka Cluster
Sane Sharding with Akka ClusterSane Sharding with Akka Cluster
Sane Sharding with Akka Clustermiciek
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every dayVadym Khondar
 
Improving Correctness with Types Kats Conf
Improving Correctness with Types Kats ConfImproving Correctness with Types Kats Conf
Improving Correctness with Types Kats ConfIain Hull
 
Taming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeTaming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeMacoscope
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Juan Pablo
 
Scalable Angular 2 Application Architecture
Scalable Angular 2 Application ArchitectureScalable Angular 2 Application Architecture
Scalable Angular 2 Application ArchitectureFDConf
 
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2Jeado Ko
 
Codestrong 2012 breakout session hacking titanium
Codestrong 2012 breakout session   hacking titaniumCodestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session hacking titaniumAxway Appcelerator
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard LibrarySantosh Rajan
 
Is your C# optimized
Is your C# optimizedIs your C# optimized
Is your C# optimizedWoody Pewitt
 
Restful Web Service
Restful Web ServiceRestful Web Service
Restful Web ServiceBin Cai
 
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
“iOS 11 в App in the Air”, Пронин Сергей, App in the AirAvitoTech
 
Improving Correctness With Type - Goto Con Berlin
Improving Correctness With Type - Goto Con BerlinImproving Correctness With Type - Goto Con Berlin
Improving Correctness With Type - Goto Con BerlinIain Hull
 
TDD and mobile development: some forgotten techniques, illustrated with Android
TDD and mobile development: some forgotten techniques, illustrated with AndroidTDD and mobile development: some forgotten techniques, illustrated with Android
TDD and mobile development: some forgotten techniques, illustrated with AndroidCodemotion
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance TuningMinh Hoang
 

Semelhante a Making Swift even safer (20)

Sane Sharding with Akka Cluster
Sane Sharding with Akka ClusterSane Sharding with Akka Cluster
Sane Sharding with Akka Cluster
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every day
 
Improving Correctness with Types Kats Conf
Improving Correctness with Types Kats ConfImproving Correctness with Types Kats Conf
Improving Correctness with Types Kats Conf
 
Rx workshop
Rx workshopRx workshop
Rx workshop
 
Taming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeTaming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, Macoscope
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
Scalable Angular 2 Application Architecture
Scalable Angular 2 Application ArchitectureScalable Angular 2 Application Architecture
Scalable Angular 2 Application Architecture
 
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2
 
mobl
moblmobl
mobl
 
Codestrong 2012 breakout session hacking titanium
Codestrong 2012 breakout session   hacking titaniumCodestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session hacking titanium
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
Codable routing
Codable routingCodable routing
Codable routing
 
Is your C# optimized
Is your C# optimizedIs your C# optimized
Is your C# optimized
 
Restful Web Service
Restful Web ServiceRestful Web Service
Restful Web Service
 
CAVE Overview
CAVE OverviewCAVE Overview
CAVE Overview
 
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
 
Improving Correctness With Type - Goto Con Berlin
Improving Correctness With Type - Goto Con BerlinImproving Correctness With Type - Goto Con Berlin
Improving Correctness With Type - Goto Con Berlin
 
TDD and mobile development: some forgotten techniques, illustrated with Android
TDD and mobile development: some forgotten techniques, illustrated with AndroidTDD and mobile development: some forgotten techniques, illustrated with Android
TDD and mobile development: some forgotten techniques, illustrated with Android
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
 

Último

DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 

Último (20)

DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 

Making Swift even safer

  • 2. 18 months of development 120k+ lines of Swift ≈40 releases 6 months in production Juno Rider iOS
  • 4. extension Array { public subscript (safe index: Int) -> Element? { … } } extension Int { public init?(safe value: Float) { … } public init?(safe value: Double) { … } public init?(safe value: UInt) { … } } !
  • 6. struct LocationCoordinate<A> { let value: Double init(_ value: Double) { self.value = value } } enum Lat {} enum Lon {} struct Location { let latitude: LocationCoordinate<Lat> let longitude: LocationCoordinate<Lon> } Phantom types
  • 7. struct TaggedValue<ValueType, Tag> { let value: ValueType init(_ value: ValueType) { self.value = value } } enum PickupTimeTag {} typealias PickupTime = TaggedValue<NSDate, PickupTimeTag> enum DropoffTimeTag {} typealias DropoffTime = TaggedValue<NSDate, DropoffTimeTag> Phantom types
  • 8. enum PhoneTag {} typealias Phone = TaggedValue<String, PhoneTag> extension TaggedValueType where Tag == PhoneTag, ValueType == String { func trimCountryCode() -> Phone { return Phone(trimCountryCode(self.taggedValue.value)) } } private func trimCountryCode(phone: String) -> String { … } Phantom types
  • 9. extension TaggedValueType where ValueType: JSONEncoding { func encodeJSON() -> AnyObject { return self.taggedValue.value.encodeJSON() } } Phantom types
  • 10. enum StringKey { case AccessibilityHomeConfirmButton case DialogInsufficientFundsTitle ... } func localized(value: Strings) -> String { switch value { case .AccessibilityHomeConfirmButton: return String.localized(“Accessibility.Home.Confirm.Button”) ... } } Static resources
  • 11. extension HTTP { enum Error: ErrorType { case InvalidResponse(request: NSURLRequest, response: NSURLResponse?) case TransportError(request: NSURLRequest, error: NSError) case HTTPError(request: NSURLRequest, response: NSHTTPURLResponse, responseData: NSData?) case CannotCreateURL(components: NSURLComponents) case InvalidURL(urlString: String) case AuthServiceFailure case CannotBindStreamPair(request: NSURLRequest) case StreamWriting(request: NSURLRequest, error: NSError?) case StreamGzipEncoding(request: NSURLRequest, operation: HTTP.Error.GzipOperation) } } Strong ErrorType
  • 12. extension JSON.Error { struct Encode: ErrorType { public let error: NSError public let source: Any } enum Decode: ErrorType { case Unexpected case Serialization(error: NSError, data: NSData) case SchemeMismatch(error: JSON.Error.SchemeMismatch, body: AnyObject?) } struct SchemeMismatch: ErrorType { public let pathComponents: [String] public let reason: String } } Strong ErrorType
  • 13. public enum JSONTaskError: ErrorType { case Task(error: HTTP.Error) case Request(error: JSON.Error.Encode) case Response(response: HTTP.Response, error: JSON.Error.Decode) } Strong ErrorType
  • 17. Context May contain dirty things dealing with global state
  • 18. Context May contain dirty things dealing with global state Unit tests
  • 19. Context typealias AppContext = protocol< StringsServiceContainer, StaticImageServicesContainer, BundleImagesServiceContainer, ReachabilityServiceContainer, AnalyticsServiceContainer, SchedulerContainer, RemoteNotificationsContainer, RemoteNotificationsPermissionContainer, RemoteNotificationClearActionContainer, LocationServiceContainer, ApplicationServiceContainer, DeviceServiceContainer, … > class ElDependor: AppContext { … } class MockContext: AppContext { … }
  • 21. App Pure state machine - Unit tests - Integrated acceptance tests
  • 22. Acceptance tests via TestApp class Allow_Rider_to_Have_Max_X_Cards_per_Account_Spec: QuickSpec { override func spec() { var app: TestApp! beforeEach { app = TestApp() } given("rider is entering CC details on Add CC screen") { beforeEach { app.login() app.goToHomeScreen() app.receiveSomePaymentMethods() app.openPayments() app.payments.paymentMethods.tapAddPayment() app.payments.addPayment.enterSomeCC() app.payments.addPayment.tapNext() app.payments.addPayment.enterSomeZipCode() } when("rider taps Add CC button") { beforeEach { app.payments.addPayment.tapDone() } and("BE returns the message about max number of active cards") { beforeEach { app._context.addCreditCard.receive(.Failed(.TooManyPaymentMethods)) } then("present the Max Cards Added alert") { app.payments.addPayment.expectToPresentAlert() } when("rider taps Ok button") { beforeEach { app.payments.addPayment.alert.tapOK() } then("dismiss the alert") { app.payments.addPayment.expectToNotPresentAlert() }
  • 23.
  • 27. Detecting & investigating bugs in the field - smart assertions - diligent logging - daily duty
  • 28. junoAssert in Debug - crash 🙀 in Release - log.error(), trackNonFatal() and recover 🙏
  • 29. Logging switch error { case let .InvalidResponse(value): log.warn( category: logCategory, message: "Unexpected response", payload: [ .RequestIdentifier: error.requestIdentifier, .ResponseIdentifier: error.responseIdentifier, .Description: "(value.response)", .Path: value.request.path, .URL: value.request.absoluteURL ] ) …
  • 30. Logging Analytics junoAssert ↓ ↓ log.verbose log.info log.warn log.error ↓ ↓ ↓ ↓ {'key0':'value0','key1':‘value1'} ↓ append to txt file ↓ roll & upload to AWS ↓ Elasticsearch + Kibana
  • 32. Production quality comes at a price - takes up to x2 dev effort - challenging for new team members - performance considerations
  • 33. But it brings satisfaction