SWIFT - National Office Furniture · swift swift national office furniture—seating ...
Making Swift Even More Functional
-
Upload
veronica-lillie -
Category
Engineering
-
view
290 -
download
3
Transcript of Making Swift Even More Functional
![Page 1: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/1.jpg)
Making Swift Even More Functional
- Swift Summit
![Page 2: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/2.jpg)
Hello, I’m Veronica Ray!
![Page 3: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/3.jpg)
Swift is great, but it could be better
Time to make change is now
![Page 4: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/4.jpg)
–The Recurse Center User’s Manual
“Be rigorous. Understand how and why your code works. Understand your
tools. If you're working with a framework (like Sinatra or Flask), learning to use it is just scratching the surface. Go deeper. Learn how it
works.”
![Page 5: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/5.jpg)
– Functional Programming In Swift
“Functional programmers emphasize that each
program can be repeatedly broken into smaller and
smaller pieces; all these pieces can be assembled using function application
to define a complete program.”
![Page 6: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/6.jpg)
– Functional Programming In Swift
“Functional programming…emphasizes the importance of programming with values,
free of mutable state or other side effects.”
![Page 7: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/7.jpg)
CLASS VS
STRUCT
![Page 8: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/8.jpg)
WHY FUNCTIONAL?
•Helps you write clear and concise code
•Makes concurrency easier
•Reduces complexity
![Page 9: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/9.jpg)
vs
![Page 10: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/10.jpg)
SIMPLICITY
![Page 11: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/11.jpg)
![Page 12: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/12.jpg)
COMPARED TO SCALA
![Page 13: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/13.jpg)
![Page 14: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/14.jpg)
Too many custom operators and not opinionated enough
![Page 15: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/15.jpg)
FP IN SWIFT•list comprehensions
•tail call optimization
![Page 16: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/16.jpg)
FP IN SWIFT•list comprehensions
•tail call optimization
![Page 17: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/17.jpg)
LIST COMPREHENSIONS
![Page 18: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/18.jpg)
POWERFUL
![Page 19: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/19.jpg)
PYTHON
![Page 20: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/20.jpg)
PYTHON
![Page 21: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/21.jpg)
BYTE CODE
![Page 22: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/22.jpg)
PYTHON FOR LOOP
![Page 23: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/23.jpg)
BYTE CODE IS 23 LINES!
![Page 24: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/24.jpg)
vs
![Page 25: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/25.jpg)
BYTE CODE IS THE SAME
![Page 26: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/26.jpg)
SPELLING CORRECTOR
![Page 27: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/27.jpg)
CONCISENESSReading code
Writing code
![Page 28: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/28.jpg)
ADDING IT TO SWIFT
![Page 29: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/29.jpg)
FP IN SWIFT•list comprehensions
•tail call optimization
![Page 30: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/30.jpg)
RECURSION
![Page 31: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/31.jpg)
TAIL CALL
![Page 32: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/32.jpg)
TAIL RECURSIVE CALL
![Page 33: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/33.jpg)
STACK TRACE(fact 3) (fact-tail 3 1) (fact-tail 2 3) (fact-tail 1 6) (fact-tail 0 6) 6
![Page 34: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/34.jpg)
NOT TAIL RECURSIVE
![Page 35: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/35.jpg)
STACK TRACE(fact 3) (* 3 (fact 2)) (* 3 (* 2 (fact 1))) (* 3 (* 2 (* 1 (fact 0)))) (* 3 (* 2 (* 1 1))) (* 3 (* 2 1))
![Page 36: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/36.jpg)
TAIL CALL OPTIMIZATION
![Page 37: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/37.jpg)
NOT GUANRANTEED
![Page 38: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/38.jpg)
SWIFT CODE
![Page 39: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/39.jpg)
BYTE CODE
jne to the label containing the conditional jump
![Page 40: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/40.jpg)
BLOW OUT THE STACK
![Page 41: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/41.jpg)
HOPE?
![Page 42: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/42.jpg)
CHANGE YOUR BYTECODE
CHANGE YOUR LIFE
![Page 43: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/43.jpg)
RECURSION KILLS
![Page 44: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/44.jpg)
RADAR
![Page 45: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/45.jpg)
LEARN MORE
![Page 46: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/46.jpg)
•Functional Swift Conference •Open Radar •Dev Forums •Twitter •Natasha The Robot’s Blog
![Page 47: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/47.jpg)
WHEN SWIFT GOES OPEN SOURCE
![Page 48: Making Swift Even More Functional](https://reader030.fdocuments.us/reader030/viewer/2022020213/58ac7df01a28ab4c6c8b605b/html5/thumbnails/48.jpg)
TIME TO MAKE CHANGE IS NOW