Download - Making Swift Even More Functional
Making Swift Even More Functional
- Swift Summit
Hello, I’m Veronica Ray!
Swift is great, but it could be better
Time to make change is now
–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.”
– 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.”
– Functional Programming In Swift
“Functional programming…emphasizes the importance of programming with values,
free of mutable state or other side effects.”
CLASS VS
STRUCT
WHY FUNCTIONAL?
•Helps you write clear and concise code
•Makes concurrency easier
•Reduces complexity
vs
SIMPLICITY
COMPARED TO SCALA
Too many custom operators and not opinionated enough
FP IN SWIFT•list comprehensions
•tail call optimization
FP IN SWIFT•list comprehensions
•tail call optimization
LIST COMPREHENSIONS
POWERFUL
PYTHON
PYTHON
BYTE CODE
PYTHON FOR LOOP
BYTE CODE IS 23 LINES!
vs
BYTE CODE IS THE SAME
SPELLING CORRECTOR
CONCISENESSReading code
Writing code
ADDING IT TO SWIFT
FP IN SWIFT•list comprehensions
•tail call optimization
RECURSION
TAIL CALL
TAIL RECURSIVE CALL
STACK TRACE(fact 3) (fact-tail 3 1) (fact-tail 2 3) (fact-tail 1 6) (fact-tail 0 6) 6
NOT TAIL RECURSIVE
STACK TRACE(fact 3) (* 3 (fact 2)) (* 3 (* 2 (fact 1))) (* 3 (* 2 (* 1 (fact 0)))) (* 3 (* 2 (* 1 1))) (* 3 (* 2 1))
TAIL CALL OPTIMIZATION
NOT GUANRANTEED
SWIFT CODE
BYTE CODE
jne to the label containing the conditional jump
BLOW OUT THE STACK
HOPE?
CHANGE YOUR BYTECODE
CHANGE YOUR LIFE
RECURSION KILLS
RADAR
LEARN MORE
•Functional Swift Conference •Open Radar •Dev Forums •Twitter •Natasha The Robot’s Blog
WHEN SWIFT GOES OPEN SOURCE
TIME TO MAKE CHANGE IS NOW