A Few Thoughts on Functional Programming and Swift

So the first programming language I learned was an Object Oriented Programming (OOP) language. It was easy to think this way because we live in an object oriented world. It is always changing. That’s what makes life beautiful, and yet chaotic. We hold on to things we value. But we can’t always control what happens to them. Functional programming aims to eliminate the side-effects of life by making change intentional.

*Same* Data In, *Same* Data Out

Recently the software development community has been taking focus on functional programming (FP) for its strength in performing stateless tasks concurrently. Facebook is using Haskell, a purely functional language, to reduce spam. And newer languages have also been developed such as Google’s Go, Mozilla’s Rust, and Apple’s Swift. It’s easy to acknowledge FP’s strengths, but one shouldn’t be blinded by it.

One of the greatest martial artists of all time once said,

Absorb what is useful, discard what is not, and add what is uniquely your own.

He said this because he knew, you shouldn’t put limits on what you can achieve. And more importantly, that it takes the right tool for the job.

Steve Jobs was also very adamant about not limiting your life by conforming to one thing over another. It is this thought process that really makes Apple’s Swift programming language very attractive. It is not solely functional, nor object oriented. It is a multi-paradigm programming language.

Most recently Apple has decided to take a Protocol Oriented Programming (POP) approach with Swift. This allows you to develop your software in a very abstract, safe manner that can make use of both OOP and FP to architect your software. Even better it seems we are starting to understand that OOP and FP can mix really well together. In session 414 at WWDC they elaborated on when you might want to use reference semantics(OOP) or value semantics(FP) based on what you are trying to achieve.

A few other notable resources you should check out are:


Want to chat? You can reach me @iJoeCollins on twitter.