SlideShare uma empresa Scribd logo
1 de 30
Baixar para ler offline
© 2015 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
Swift Custom Operators:
The Good, the Bad and the Ugly
© 2015 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
About the Author: Mike Gerasymenko
• Working on iOS since 2008 (iOS 2.2)
• Around 35 apps for the AppStore
• With Wire since March 2014
3
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
Preface: Terminology
• Operator describes operation, which is a calculation from zero or more input values
(operands) to an output value.
• Arity of operators:
• unary: !x, x++, x--, x~, --x, ++x
• binary: x+y, x-y
• ternary: x? a : b
• n-ary
• Placement
• Prefix: !x
• Infix: x+y
• Postfix: x++
4
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
Preface: Precedence and Associativity
• During the evaluation of the expression, first the operators with the higher precedence
are being evaluated, for example:
• x = a + b * c is x = a + (b * c)
• Given that the precedence is equal for the operators, the operators are evaluated
according to their associativity, left, right or non-associative. Having left associativity
means that the operations are performed from left to right, for example:
• x = a + b + c is x = (a + b) + c
5
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
Preface: Extras
• Overloading means that the same operator can work with different types:
• operator+ can be applied to Int, Double, …
• Short-circuit evaluation means that operand is only calculated when necessary:
• evaluation of false && obj.isTrue() would not invoke obj.isTrue()
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
The Good: Syntax
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
Game: spot the operator
8
goo.gl/FIPNQ0
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
Those are also Operators
• postfix ?, !
• as, as?, as!, is
• …, ..<
• in
• try, try?, try!
9
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
The Good: Syntax
• Swift is really flexible with operator definition:
• Operator definition consists of two parts: operator declaration and at least one
function that gives the meaning to an operator
• Arity, placement, precedence and associativity can be defined per operator
• Rich set of operators that could be defined (standard operation characters + UTF8)
• Swift gives the ability to overload almost any existing operator (except is, as, as?,
=, ??, prefix &, postfix ?, ! and «? :»)
10
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
The Good: Syntax: Operator Declaration
11
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
The Good: Let’s define an operator
• Playground time (page DefiningOperator)
12
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
The Good: Being functional
• Playground time (page BeingFunctional)
13
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
The Bad
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
The Bad: Usefulness
• Why there’s no such operator before?
15
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
The Bad: Usefulness
16
• Playground time (page AttributedString)
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
The Bad: Understanding of new operators
• New operator could be puzzling for other developers
• Overloading an existing operator could give a hard time debugging the code where it is
not clear that new overloaded implementation is used
17
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
The Bad: Global Scope
• Whatever you define, it would appear at the global scope.
• Operators from frameworks are visible in user code
• Being in global scope makes it easy to collide implementing same operator in the
different way in framework and in user code
18
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
The Ugly
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
The Ugly: Going Nuts
• Playground time (page GoingNuts)
20
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
Conclusion
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
Curiosities
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
Non-associative
• operator== is non-associative, so it is harder to shoot your
own foot:
• For example, x == y == z in C would evaluate as (x == y) == z,
and not to x == y, y == z
23
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
Nice applications
24
• Libraries that are making use of custom operators
• Cartography
• Euler by mattt
• Swift go
• …
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
Questions
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
Regards to my fellow colleagues
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
References
• The Swift Programming Language https://developer.apple.com/library/ios/
documentation/Swift/Conceptual/Swift_Programming_Language/
• Facets of Swift, Part 5: Custom Operators https://medium.com/swift-programming/
facets-of-swift-part-5-custom-operators-1080bc78ccc#.l40cmmsy2
• Functional Programming in Swift http://five.agency/functional-programming-in-swift/
• Railroad Diagram Generator http://www.bottlecaps.de/rr/ui
• 100 Most Popular Cat Names https://www.cuteness.com/popular-cat-names
28
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
Contact data
Mike Gerasymenko
mihail@gerasimenko.me
(find me on Wire using this email)
mike@wire.com
© 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.

Mais conteúdo relacionado

Destaque

Будь здоровым вместе с Традо
Будь здоровым вместе с ТрадоБудь здоровым вместе с Традо
Будь здоровым вместе с ТрадоЕлена Шальнова
 
Educ6706 literate environment analysis
Educ6706 literate environment analysisEduc6706 literate environment analysis
Educ6706 literate environment analysislivepeace
 
Pietilä, Vonk: Terve suu yhteisenä tavoitteena, osa 1
Pietilä, Vonk: Terve suu yhteisenä tavoitteena, osa 1Pietilä, Vonk: Terve suu yhteisenä tavoitteena, osa 1
Pietilä, Vonk: Terve suu yhteisenä tavoitteena, osa 1Kouluterveyskysely
 
Business Continuity & Disaster Recovery introductie
Business Continuity & Disaster Recovery introductieBusiness Continuity & Disaster Recovery introductie
Business Continuity & Disaster Recovery introductieB.A.
 
Corso di formazione Export Management
Corso di formazione Export ManagementCorso di formazione Export Management
Corso di formazione Export ManagementOctagona Srl
 
Biochip report
Biochip reportBiochip report
Biochip reportMohit Garg
 
How to make your presentation stick
How to make your presentation stickHow to make your presentation stick
How to make your presentation stickDr. Mohamed Haggag
 
Поиграем с детьми
Поиграем с детьмиПоиграем с детьми
Поиграем с детьмиtagobr58
 
Презентация обувного магазина "La grange" Презентация для входа в ТЦ. Презент...
Презентация обувного магазина "La grange" Презентация для входа в ТЦ. Презент...Презентация обувного магазина "La grange" Презентация для входа в ТЦ. Презент...
Презентация обувного магазина "La grange" Презентация для входа в ТЦ. Презент...Агентство Презентаций "Romanoff"
 
Buy or Rent in Columbia SC?
Buy or Rent in Columbia SC? Buy or Rent in Columbia SC?
Buy or Rent in Columbia SC? Clint Hammond
 
OpenStack系列公开课2 -20130508
OpenStack系列公开课2 -20130508OpenStack系列公开课2 -20130508
OpenStack系列公开课2 -20130508OpenCity Community
 

Destaque (20)

Будь здоровым вместе с Традо
Будь здоровым вместе с ТрадоБудь здоровым вместе с Традо
Будь здоровым вместе с Традо
 
Educ6706 literate environment analysis
Educ6706 literate environment analysisEduc6706 literate environment analysis
Educ6706 literate environment analysis
 
Manal p.
Manal p.Manal p.
Manal p.
 
Pietilä, Vonk: Terve suu yhteisenä tavoitteena, osa 1
Pietilä, Vonk: Terve suu yhteisenä tavoitteena, osa 1Pietilä, Vonk: Terve suu yhteisenä tavoitteena, osa 1
Pietilä, Vonk: Terve suu yhteisenä tavoitteena, osa 1
 
Кто выбирает Традо?
Кто выбирает Традо?Кто выбирает Традо?
Кто выбирает Традо?
 
THE COLA WAR
THE COLA WARTHE COLA WAR
THE COLA WAR
 
Business Continuity & Disaster Recovery introductie
Business Continuity & Disaster Recovery introductieBusiness Continuity & Disaster Recovery introductie
Business Continuity & Disaster Recovery introductie
 
Corso di formazione Export Management
Corso di formazione Export ManagementCorso di formazione Export Management
Corso di formazione Export Management
 
Biochip report
Biochip reportBiochip report
Biochip report
 
Satya Nadella
Satya NadellaSatya Nadella
Satya Nadella
 
How to make your presentation stick
How to make your presentation stickHow to make your presentation stick
How to make your presentation stick
 
Поиграем с детьми
Поиграем с детьмиПоиграем с детьми
Поиграем с детьми
 
Teorias organizativas
Teorias organizativasTeorias organizativas
Teorias organizativas
 
Relative pronouns
Relative pronounsRelative pronouns
Relative pronouns
 
Презентация обувного магазина "La grange" Презентация для входа в ТЦ. Презент...
Презентация обувного магазина "La grange" Презентация для входа в ТЦ. Презент...Презентация обувного магазина "La grange" Презентация для входа в ТЦ. Презент...
Презентация обувного магазина "La grange" Презентация для входа в ТЦ. Презент...
 
Escuela profesional
Escuela profesionalEscuela profesional
Escuela profesional
 
Buy or Rent in Columbia SC?
Buy or Rent in Columbia SC? Buy or Rent in Columbia SC?
Buy or Rent in Columbia SC?
 
Paragraph types
Paragraph typesParagraph types
Paragraph types
 
Unit 57 terminology becky doyle
Unit 57 terminology becky doyleUnit 57 terminology becky doyle
Unit 57 terminology becky doyle
 
OpenStack系列公开课2 -20130508
OpenStack系列公开课2 -20130508OpenStack系列公开课2 -20130508
OpenStack系列公开课2 -20130508
 

Semelhante a Custom Swift Operators: The Good, the Bad and the Ugly

Advanced UI styling and animations for iOS
Advanced UI styling and animations for iOSAdvanced UI styling and animations for iOS
Advanced UI styling and animations for iOSMike Gerasymenko
 
The Fantastic Voyage to PaaS - Are we there yet? (Cloud Foundry Summit 2014)
The Fantastic Voyage to PaaS - Are we there yet? (Cloud Foundry Summit 2014)The Fantastic Voyage to PaaS - Are we there yet? (Cloud Foundry Summit 2014)
The Fantastic Voyage to PaaS - Are we there yet? (Cloud Foundry Summit 2014)VMware Tanzu
 
Introduction to Marketing Cloud UI, Adobe Summit 2014
Introduction to Marketing Cloud UI, Adobe Summit 2014Introduction to Marketing Cloud UI, Adobe Summit 2014
Introduction to Marketing Cloud UI, Adobe Summit 2014Damien Antipa
 
Working effectively with OpenShift
Working effectively with OpenShiftWorking effectively with OpenShift
Working effectively with OpenShiftShekhar Gulati
 
Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...
Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...
Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...cornelia davis
 
Testing and Troubleshooting with AWS Device Farm - MBL301 - re:Invent 2017
Testing and Troubleshooting with AWS Device Farm - MBL301 - re:Invent 2017Testing and Troubleshooting with AWS Device Farm - MBL301 - re:Invent 2017
Testing and Troubleshooting with AWS Device Farm - MBL301 - re:Invent 2017Amazon Web Services
 
Asynchronous Services – A promising future for OSGi - T Ward
Asynchronous Services – A promising future for OSGi - T WardAsynchronous Services – A promising future for OSGi - T Ward
Asynchronous Services – A promising future for OSGi - T Wardmfrancis
 
Scalable, Available and Reliable Cloud Applications with PaaS and Microservices
Scalable, Available and Reliable Cloud Applications with PaaS and MicroservicesScalable, Available and Reliable Cloud Applications with PaaS and Microservices
Scalable, Available and Reliable Cloud Applications with PaaS and MicroservicesDavid Currie
 
Emulators as an Emerging Best Practice for API Providers
Emulators as an Emerging Best Practice for API ProvidersEmulators as an Emerging Best Practice for API Providers
Emulators as an Emerging Best Practice for API ProvidersCisco DevNet
 
XebiaLabs - Optimizing App Deployment to IBM WebSphere
XebiaLabs - Optimizing App Deployment to IBM WebSphereXebiaLabs - Optimizing App Deployment to IBM WebSphere
XebiaLabs - Optimizing App Deployment to IBM WebSphereXebiaLabs
 
Running open source PHP applications on you IBM i
Running open source PHP applications on you IBM iRunning open source PHP applications on you IBM i
Running open source PHP applications on you IBM iProximity Group
 
Real life-maf-2015
Real life-maf-2015Real life-maf-2015
Real life-maf-2015Luc Bors
 
CI and CD Across the Enterprise with Jenkins (devops.com Nov 2014)
CI and CD Across the Enterprise with Jenkins (devops.com Nov 2014)CI and CD Across the Enterprise with Jenkins (devops.com Nov 2014)
CI and CD Across the Enterprise with Jenkins (devops.com Nov 2014)CloudBees
 
Building a right sized, do-anything runtime using OSGi technologies: a case s...
Building a right sized, do-anything runtime using OSGi technologies: a case s...Building a right sized, do-anything runtime using OSGi technologies: a case s...
Building a right sized, do-anything runtime using OSGi technologies: a case s...mfrancis
 
Real life-maf-2015-k scope-final
Real life-maf-2015-k scope-finalReal life-maf-2015-k scope-final
Real life-maf-2015-k scope-finalLuc Bors
 
Revive your ERP with APIs and Hybrid Integation Magic by Mikael Sand
Revive your ERP with APIs and Hybrid Integation Magic by Mikael SandRevive your ERP with APIs and Hybrid Integation Magic by Mikael Sand
Revive your ERP with APIs and Hybrid Integation Magic by Mikael SandAdam Walhout
 
Authentication and Identity with Amazon Cognito & Analytics with Amazon Pinpoint
Authentication and Identity with Amazon Cognito & Analytics with Amazon PinpointAuthentication and Identity with Amazon Cognito & Analytics with Amazon Pinpoint
Authentication and Identity with Amazon Cognito & Analytics with Amazon PinpointAmazon Web Services
 
Webinar 5 challenges of mobilization april 9 2014
Webinar   5 challenges of mobilization april 9 2014Webinar   5 challenges of mobilization april 9 2014
Webinar 5 challenges of mobilization april 9 2014Appear
 
JavaOne 2014: Java vs JavaScript
JavaOne 2014:   Java vs JavaScriptJavaOne 2014:   Java vs JavaScript
JavaOne 2014: Java vs JavaScriptChris Bailey
 

Semelhante a Custom Swift Operators: The Good, the Bad and the Ugly (20)

Advanced UI styling and animations for iOS
Advanced UI styling and animations for iOSAdvanced UI styling and animations for iOS
Advanced UI styling and animations for iOS
 
The Fantastic Voyage to PaaS - Are we there yet? (Cloud Foundry Summit 2014)
The Fantastic Voyage to PaaS - Are we there yet? (Cloud Foundry Summit 2014)The Fantastic Voyage to PaaS - Are we there yet? (Cloud Foundry Summit 2014)
The Fantastic Voyage to PaaS - Are we there yet? (Cloud Foundry Summit 2014)
 
Introduction to Marketing Cloud UI, Adobe Summit 2014
Introduction to Marketing Cloud UI, Adobe Summit 2014Introduction to Marketing Cloud UI, Adobe Summit 2014
Introduction to Marketing Cloud UI, Adobe Summit 2014
 
Working effectively with OpenShift
Working effectively with OpenShiftWorking effectively with OpenShift
Working effectively with OpenShift
 
Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...
Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...
Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...
 
Testing and Troubleshooting with AWS Device Farm - MBL301 - re:Invent 2017
Testing and Troubleshooting with AWS Device Farm - MBL301 - re:Invent 2017Testing and Troubleshooting with AWS Device Farm - MBL301 - re:Invent 2017
Testing and Troubleshooting with AWS Device Farm - MBL301 - re:Invent 2017
 
Asynchronous Services – A promising future for OSGi - T Ward
Asynchronous Services – A promising future for OSGi - T WardAsynchronous Services – A promising future for OSGi - T Ward
Asynchronous Services – A promising future for OSGi - T Ward
 
Scalable, Available and Reliable Cloud Applications with PaaS and Microservices
Scalable, Available and Reliable Cloud Applications with PaaS and MicroservicesScalable, Available and Reliable Cloud Applications with PaaS and Microservices
Scalable, Available and Reliable Cloud Applications with PaaS and Microservices
 
Emulators as an Emerging Best Practice for API Providers
Emulators as an Emerging Best Practice for API ProvidersEmulators as an Emerging Best Practice for API Providers
Emulators as an Emerging Best Practice for API Providers
 
XebiaLabs - Optimizing App Deployment to IBM WebSphere
XebiaLabs - Optimizing App Deployment to IBM WebSphereXebiaLabs - Optimizing App Deployment to IBM WebSphere
XebiaLabs - Optimizing App Deployment to IBM WebSphere
 
20100616 Deployit For N How
20100616 Deployit For N How20100616 Deployit For N How
20100616 Deployit For N How
 
Running open source PHP applications on you IBM i
Running open source PHP applications on you IBM iRunning open source PHP applications on you IBM i
Running open source PHP applications on you IBM i
 
Real life-maf-2015
Real life-maf-2015Real life-maf-2015
Real life-maf-2015
 
CI and CD Across the Enterprise with Jenkins (devops.com Nov 2014)
CI and CD Across the Enterprise with Jenkins (devops.com Nov 2014)CI and CD Across the Enterprise with Jenkins (devops.com Nov 2014)
CI and CD Across the Enterprise with Jenkins (devops.com Nov 2014)
 
Building a right sized, do-anything runtime using OSGi technologies: a case s...
Building a right sized, do-anything runtime using OSGi technologies: a case s...Building a right sized, do-anything runtime using OSGi technologies: a case s...
Building a right sized, do-anything runtime using OSGi technologies: a case s...
 
Real life-maf-2015-k scope-final
Real life-maf-2015-k scope-finalReal life-maf-2015-k scope-final
Real life-maf-2015-k scope-final
 
Revive your ERP with APIs and Hybrid Integation Magic by Mikael Sand
Revive your ERP with APIs and Hybrid Integation Magic by Mikael SandRevive your ERP with APIs and Hybrid Integation Magic by Mikael Sand
Revive your ERP with APIs and Hybrid Integation Magic by Mikael Sand
 
Authentication and Identity with Amazon Cognito & Analytics with Amazon Pinpoint
Authentication and Identity with Amazon Cognito & Analytics with Amazon PinpointAuthentication and Identity with Amazon Cognito & Analytics with Amazon Pinpoint
Authentication and Identity with Amazon Cognito & Analytics with Amazon Pinpoint
 
Webinar 5 challenges of mobilization april 9 2014
Webinar   5 challenges of mobilization april 9 2014Webinar   5 challenges of mobilization april 9 2014
Webinar 5 challenges of mobilization april 9 2014
 
JavaOne 2014: Java vs JavaScript
JavaOne 2014:   Java vs JavaScriptJavaOne 2014:   Java vs JavaScript
JavaOne 2014: Java vs JavaScript
 

Último

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 

Último (20)

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 

Custom Swift Operators: The Good, the Bad and the Ugly

  • 1. © 2015 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. Swift Custom Operators: The Good, the Bad and the Ugly
  • 2. © 2015 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
  • 3. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. About the Author: Mike Gerasymenko • Working on iOS since 2008 (iOS 2.2) • Around 35 apps for the AppStore • With Wire since March 2014 3
  • 4. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. Preface: Terminology • Operator describes operation, which is a calculation from zero or more input values (operands) to an output value. • Arity of operators: • unary: !x, x++, x--, x~, --x, ++x • binary: x+y, x-y • ternary: x? a : b • n-ary • Placement • Prefix: !x • Infix: x+y • Postfix: x++ 4
  • 5. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. Preface: Precedence and Associativity • During the evaluation of the expression, first the operators with the higher precedence are being evaluated, for example: • x = a + b * c is x = a + (b * c) • Given that the precedence is equal for the operators, the operators are evaluated according to their associativity, left, right or non-associative. Having left associativity means that the operations are performed from left to right, for example: • x = a + b + c is x = (a + b) + c 5
  • 6. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. Preface: Extras • Overloading means that the same operator can work with different types: • operator+ can be applied to Int, Double, … • Short-circuit evaluation means that operand is only calculated when necessary: • evaluation of false && obj.isTrue() would not invoke obj.isTrue()
  • 7. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. The Good: Syntax
  • 8. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. Game: spot the operator 8 goo.gl/FIPNQ0
  • 9. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. Those are also Operators • postfix ?, ! • as, as?, as!, is • …, ..< • in • try, try?, try! 9
  • 10. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. The Good: Syntax • Swift is really flexible with operator definition: • Operator definition consists of two parts: operator declaration and at least one function that gives the meaning to an operator • Arity, placement, precedence and associativity can be defined per operator • Rich set of operators that could be defined (standard operation characters + UTF8) • Swift gives the ability to overload almost any existing operator (except is, as, as?, =, ??, prefix &, postfix ?, ! and «? :») 10
  • 11. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. The Good: Syntax: Operator Declaration 11
  • 12. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. The Good: Let’s define an operator • Playground time (page DefiningOperator) 12
  • 13. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. The Good: Being functional • Playground time (page BeingFunctional) 13
  • 14. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. The Bad
  • 15. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. The Bad: Usefulness • Why there’s no such operator before? 15
  • 16. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. The Bad: Usefulness 16 • Playground time (page AttributedString)
  • 17. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. The Bad: Understanding of new operators • New operator could be puzzling for other developers • Overloading an existing operator could give a hard time debugging the code where it is not clear that new overloaded implementation is used 17
  • 18. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. The Bad: Global Scope • Whatever you define, it would appear at the global scope. • Operators from frameworks are visible in user code • Being in global scope makes it easy to collide implementing same operator in the different way in framework and in user code 18
  • 19. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. The Ugly
  • 20. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. The Ugly: Going Nuts • Playground time (page GoingNuts) 20
  • 21. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. Conclusion
  • 22. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. Curiosities
  • 23. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. Non-associative • operator== is non-associative, so it is harder to shoot your own foot: • For example, x == y == z in C would evaluate as (x == y) == z, and not to x == y, y == z 23
  • 24. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. Nice applications 24 • Libraries that are making use of custom operators • Cartography • Euler by mattt • Swift go • …
  • 25. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. Questions
  • 26. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.
  • 27. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. Regards to my fellow colleagues
  • 28. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. References • The Swift Programming Language https://developer.apple.com/library/ios/ documentation/Swift/Conceptual/Swift_Programming_Language/ • Facets of Swift, Part 5: Custom Operators https://medium.com/swift-programming/ facets-of-swift-part-5-custom-operators-1080bc78ccc#.l40cmmsy2 • Functional Programming in Swift http://five.agency/functional-programming-in-swift/ • Railroad Diagram Generator http://www.bottlecaps.de/rr/ui • 100 Most Popular Cat Names https://www.cuteness.com/popular-cat-names 28
  • 29. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL. Contact data Mike Gerasymenko mihail@gerasimenko.me (find me on Wire using this email) mike@wire.com
  • 30. © 2014 WIRE SWISS GMBH. PROPRIETARY AND CONFIDENTIAL.