An Introduction to Functional Swift

As a recent graduate with a CS degree, my experience so far with computer programming is dominated by Object-Oriented-Programming, and more specifically “state-ful” programming. Thinking about it, it makes sense — abstraction is something we do all the time in the real world, so why wouldn’t we superimpose the way we perceive the world on the way that we approach programming problems.

A classic example that I’m sure anyone with a modicum of programming experience has encountered is the car: you see a car driving past you. That car has a make and model, velocity, drag, and a variety of other properties that vary in their importance to the perfectly realistic car-related problem you see in your high school or college intro classes. It’s ingrained into our minds from the get-go that state (what the object has) and behavior (what the function does) need to come together to form the holistic Object.

The problem is, in iOS development, current best practices aren’t “best” because they are the best, they are best practices because they are easy. You have a UIViewController that interprets user interaction, the UIView that contains the different user-facing elements on the application, and the model (and possibly viewModel) which handles computation. It’s the natural way to organize your app — any iOS programmer would probably take a look at their iPhone and come up with some version of this paradigm. But as your app begins to get more complex, it’s almost impossible for all these well-intentioned responsibilities to be independent of each other.

I don’t mean to say that this way of programming can’t create a good app — better programmers than I have stuck to this and that’s why it’s still used. This is just my way of looking at programming, and I think it’s the best way to make the foundation of your app quickly. There are obvious situations, involving custom behavior and animation that make your app unique, where taking a more OOP approach would suit better, but an advantage of functional programming is that it makes behavior stable, consistent, and repeatable.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: