Recently I've been spending time getting know the Swift language a bit better going beyond just applying my existing Object-C programming skills. I picked up a copy of Functional Programming in Swift, which has so far been an interesting read. The more I learn about Swift the more I can feel the push towards a functional programming style, or at least a mix of functional and object-oriented views on a system.

One of the topics I keep coming across and is touched upon in the book is the idea that we should be avoiding mutability in our programs and in particular making use of stucts in Swift and avoiding classes. There's an interesting talk by Andy Matuschak about this Controlling Complexity in Swift which goes into more about dividing applications into Value and Object layers in order to take advantage of the properties of value types in order to reduce complexity of software. It's a really interesting talk and well worth a watch. It's certainly provided me with a couple of new ideas. There's also a related article on by Andy if you don't want to watch the video.

I don't think this idea of avoiding mutability is anything new. The problem this solves is partly caused by Swift's lack of an ability to enforce const correctness on classes as well as structs. It would be nice if the mutating keyword could be adopted for classes. This doesn't entirely address the issues arising from shared references leading to increasing complexity which is certainly valid and worth addressing. Anyway, it's an interesting talk so go watch it.


Share this: