Readability First

I find a lot of advanced functional code to be unreadable thanks to 5+ custom operators. There are many ways to be clever if you follow functional programming concepts.

But at the end of the day, if you’re working on a team, the most important thing is to have readable code. If an intern or just a new developer joins your team, will they be totally lost? If you focus on writing readable code (instead of being fun and clever), they should be able to contribute right away.

Remember that readability is priority over being clever (unless you’re doing a fun side project where the goal is to be fun and clever of course!).

Don’t fight the frameworks

Of course, in iOS programming, having no global side effects is not possible a lot of the time due to how the Cocoa framework is set up, and that fact that there is user input / output (in a purely mathematical world, there truly are no external side effects, but that’s not where we live!).

For example, if you’re setting up a custom formatter (e.g. currency formatter) that is used in several places in your code, it’s most efficient to use a singleton. You also have to use UIViewControllers and UIViews for the UI Layer. There are ways to isolate your logic into nice immutable components to help with the mutability of these, but don’t go overboard fighting the framework to an unrecognizable (read unreadable) state.

Learn Advanced Functional Programming

While again, you shouldn’t go crazy clever with your Swift code (unless you’re just experimenting / having fun). I highly recommend learning the extremes functional programming to understand the higher level concepts and figure out where that functional line is in Swift for you.