The education of Paul Weichhart

Write like nobody is reading

Programming in Swift

This article doesn‘t aim to teach any [new, shiny, fancy] things about Apple’s Swift programming language — instead it’s a short recap of my journey of programming in Swift so far.

How it all started

I started learning Objective-C in my spare time some years ago. Back when I had the chance to play with the iPhone 3G for the first time, I instantly wanted to write apps for this new device. So I bought several books on iOS development, took the Stanford iOS course & worked through the chapters. However, Objective-C never really grew on me. Working with strings, for example, seemed unnecessary complex compared to other languages (it still is with Swift, but for a good reason). Using pointers for objects also showed the age of the language.

Functional programming

But things changed for good with the release of Swift. The language features some really great functionalities like tuples, generics & optionals — already known & loved from other programming languages. However, one thing didn’t catch my attention during the presentation of Chris Lattner: Swift is not only a object oriented but also a functional programming language. The awesome people at objc.io, for example, immediately jump shipped Objective-C and showcased what was possible and released functional swift snippets & even released an entire book called „Functional Swift“ covering the basics of functional programming in Swift.

Applying functional concepts

My journey started by using more & more lets instead of vars (Xcode also encourages you to do this). I also tried to write smaller more concise functions & reuse or combine them. The next step involved applying higher order functions in my code base. It took quite some time to feel comfortable but they are now spread all over my files. This interactive Playground really helped a lot grasping the benefits of using them. Currently I try to avoid global declarations & do my best to adopt to the new challenge of organizing my classes with way more functions.

Book & Video Recommendations

If you, like me, didn‘t have the chance to learn this programming paradigm, I can‘t recommend the book „Functional Swift“ enough. It introduces the reader to concepts and methodologies known from other languages. Another helpful resource for learning functional programming is picking up a new language like Haskell or Closure. I also started reading „Learn a Haskell for great good“ & learned quite a lot. It teaches the basics of functional programming very well and encourages the reader to try new approaches for solving problems.

There is also a Video series called „Point Free“ teaching the fundamentals of functional programming in Swift. Brandon Williams & Stephen Celis really do an awesome job explaining the fundamentals & mathematical concepts behind functional programming.

Another great book I’m currently reading is called „Professor Frisby’s mostly adequate guide to functional programming“ which is available for free on Github.

Wishlist

While it is great that Swift enables us to use functional programming, however due to the Objective-C legacy, object oriented programming is still the way to go when programming for iOS. Many frameworks like Core Data aren’t capable of using it through the whole codebase. But I can’t wait for new language features introduced in the near future!