Dynamism and the future of Swift

A bunch of really smart people that I respect have been discussing the lack of dynamism in Swift, and whether it’s a problem for the future of apps for Apple platforms. As someone who has been writing Objective-C for fifteen years now, and who works as an iOS developer on a large project that’s just starting to move to Swift, it’s a question that’s on my mind as well. I love the dynamic capabilities of Objective-C, and all the incredibly useful things they allow me to do. I worry about how I’ll solve the same problems in Swift. I also want to make sure my worries aren’t simply a reaction to change.

I’ve been thinking about it for a while now, and the only conclusion that I’ve come to is that it’s just far too soon to judge. Swift is practically brand new, and with such different strengths and weaknesses than Objective-C. Swift is so dissimilar to Objective-C, that I think if Apple could have gotten away with not supporting interoperability at all, they would have been much happier. They’ve managed to do an impressive thing, getting the two to play semi-nice together, but it’s an awkward fit at best.

The proximity of one to the other, however, means that I’m constantly comparing them as I’m working. As of right now, there are lot of patterns from Objective-C, that I love and trust, that simply aren’t possible in Swift. Patterns that I instinctively reach for when attempting to build things. Metaprogramming to cleanup a bad API, monkey patching to fix a bug, binders based on KVO, dynamic lookup. One of the main focuses of my job even, Core Data, could simply not be built with Swift.

Is that a problem though? If I could design a perfect ORM for the Swift future, would it resemble Core Data? I don’t think so. Core Data is barely a good fit for what we’re doing today in Objective-C. In Swift I’d much rather have an immutable store that was thread safe. Similarly, is KVO the answer for building UIs in Swift? I have no idea. That’s the real crux of where I’ve landed with my thoughts, that we just don’t know much yet.

We have decades of established patterns for Objective-C, patterns that make the most of the capabilities of the language. And maybe those patterns will be better than anything Swift can come up with. Right now though, I’m judging things that exist against things that have yet to be built. Over the next few years Apple, and the community, are going to have to solve these problems, and only then will we find out if we need the dynamism or not.

There is one future that worries me though. I fear a scenario where we add compromise dynamism that isn’t well suited to the language. In that world I think we’d end up with something like English, which seems like it has internal logic and rules, but has so many exceptions that it makes them meaningless. A consistent language is more important than anything else. It’s a really exciting time to be a Swift developer, just as big apps are starting to use it, and we’re discovering what we don’t know we need yet. I’m really excited I get to be a part of it.