A brief summary of eight Swift features that have, in particular, affected our lives as iOS developers.
I gave this talk in a ESL-Inaka Get Together event on April 30th, 2016. The talk was mostly spoken, the slides themselves only show a summary of all the items I spoke about.
7. www.erlang-solutions.com
Swift (Static Types)
More restrictions when
writing code.
It's harder to get along
with the compiler and be
good friends, but that's a
good thing.
SWIFT IS STATICALLY TYPED
OBJ-C (Dynamic Types)
More freedom when
writing code.
However, this magic
comes with the high cost
of experiencing undesired
behavior or potential
crashes at runtime.
9. www.erlang-solutions.com
Swift
You need to define specific
paths for null vs non-null
scenarios.
You are not allowed to
perform operations on a
nil variable that's
supposed not to be nil.
SWIFT HAS GOT OPTIONALS
OBJ-C
You can call a method
with a pointer variable
that is nil, and nothing
will happen.
This no-op leads to
unpredictable behavior.
10. www.erlang-solutions.com
SWIFT HAS GOT OPTIONALS
▸ We are forced to deal with null types
▸ Our code becomes safer
▸ We get used not to forget the error paths
▸ We code with intention
▸ Sometimes, we discover hidden scenarios that
haven't been defined in the specs yet.
▹ In consequence, we become more proactive
in the development loop.
12. www.erlang-solutions.com
SWIFT TAKES A FUNCTIONAL APPROACH
▸ Enums on steroids
▸ Pattern matching
▸ Functions as first-class citizens
▹ Perfect fit for completion closures
▹ Higher order functions
▹ Map, filter, reduce
▸ The importance of:
▹ Immutability
▹ Value types
▹ Avoiding state
▸ Testable code as a consequence
14. www.erlang-solutions.com
SWIFT IS A PROTOCOL ORIENTED PROGRAMMING LANGUAGE
▸ Protocols in Swift have been given more features
and are more encouraged
▸ Favor composition over inheritance
▸ Code is more extensible and flexible
▸ In combination with generics, they become way
powerful
18. www.erlang-solutions.com
SWIFT HAS GOT GENERICS
▸ With generics, we can solve general problems writing
less code...
▸ This concept encourages us to:
▹ Think of more layers of abstraction
▹ Solve problems in a generic way
▹ Find out common code architecture patterns in our
apps and generalize them
▹ Write more open-source code
20. www.erlang-solutions.com
MODELS IN SWIFT ARE MORE POWERFUL
Swift
You can define classes,
structs and enums.
They all have the same
power at their core.
OBJ-C
You can define classes,
structs and enums.
While classes is the only
one that has real power,
structs and enums are
vastly poor in comparison
(they come from C).
21. www.erlang-solutions.com
▸ Structs and Enums have been leveled up
▸ We started to use them much more
▸ We have learned:
▹ The value of value types
▹ How to avoid side effects
▹ Pattern-matching
▹ Why the if clause can be avoided
▹ The importance of immutability
MODELS IN SWIFT ARE MORE POWERFUL
23. www.erlang-solutions.com
SWIFT IS EASIER TO READ, WRITE, MAINTAIN, ETC...
▸ Cleaner syntax
▸ Better expressiveness
▸ Much more friendly
▸ More similar to modern languages
▸ Encourages more devs to learn it
▹ Community is getting way bigger
bye-bye-brackets.png
25. www.erlang-solutions.com
SWIFT IS OPEN SOURCE!
▸ Language is evolving around the community
▹ Proposals are encouraged
▹ So are discussions
▹ Much more documentation
▹ More people getting involved
▸ Bring Swift to other platforms
▹ Linux
▹ Android
▹ Windows
27. www.erlang-solutions.com
IN CONCLUSION
Swift has changed the way we
program and how we think of
programming.
We've got less error prone code
and more solid codebases.
We are also learning from other
paradigms, which makes us more
flexible and open-minded.