Like most people, upon hearing of Swift, I rushed to download Xcode and the programming guide to try it out. 48 hours later I decided to leave it. I’ve tried it on and off since then and, while it has seen improvements, my overall opinion of Swift has stayed the same: it’s not yet fit for purpose.
Put simply, Apple has completely botched the launch of Swift. It was released in an incomplete state with tools that were bordering on unusable. Despite supposedly having 4 years of development, it feels incredibly rushed with many parts ill thought out. And worst of all it seems that on launch day there were no apps written in Swift for Apple to show (even the WWDC app they claimed was re-written in Swift was still mostly Obj-C).
One of the biggest issues with Swift is it feels like it was designed for the compiler rather than for developers. It certainly enables a lot more compiler checks and optimisations, but it seems rather little thought was put into the ease of use, the enjoyment or the overall productivity of the language. It’s very un-apple-like in making developers work to fit the computer rather than the other way round.
The other issue is that it seems it was designed as a replacement to Objective-C, rather than its successor. They may sound like the same thing, but the key distinction is that a successor to Objective-C would have had Objective-C very much in mind when it was developed (it would basically have been the Objective-C without the C many have asked for).
Being a replacement isn’t necessarily bad, it gives you a lot more freedom to change things as it provides a clean break. Unfortunately it means that if you stray too far from the language you’re replacing, any attempts at compatibility lead to problems. An awful lot of Swift’s ugliness come from these compatibility issues. Optionals are awkward and confusing, and the method/argument naming syntax makes blocks seem like the height of simplicity. I suspect these would be designed very differently if Obj-C compatibility wasn’t part of the equation.
This isn’t to say Swift is all bad. It has some very good ideas and an awful lot of potential. Powerful structs and enums, pattern matching in switch statements, the pervasiveness of immutability. But it throws away a huge amount of good ideas too. Message sending, the dynamic power of late binding, sending messages to nil. So many features that Apple has trumpeted for years and that have enabled them to build powerful and flexible frameworks (and upon which those frameworks depend) are simply thrown away.
Apple could have gone a very different route. It would have been riskier and required more work, but that’s in Apple’s DNA. They could have announced Swift as a tech demo, along with a new set of frameworks to replace Cocoa. Over the next 2-3 years they could have responded to feedback, improved the frameworks and written and shipped apps of their own built entirely in Swift. Then, they could have released a mature and well tested Swift 1.0 to the community. This is the approach they’ve used to ship many new developer tools and APIs.
The clean break from Cocoa would have allowed Swift to sing, rather than being shoehorned into of a framework that it doesn’t fit. This may only be a temporary stepping point and the Cocoa replacement may be coming, but until then Swift feels an awful lot like another Java Cocoa bridge, an attempt to put a “modern” language on top of Cocoa, which just doesn’t work.
Ultimately, how Swift develops is important. I write for Apple’s platforms and APIs because I enjoy them. Objective-C is a hell of a lot of fun to use and works incredibly well with Cocoa. The two are made for each other. Swift, in it’s current form, is just not enjoyable for me. I’ve described it to others as feeling like a “suit and tie” language, one you would use purely to pick up a pay cheque, rather than a language that you want to play and experiment with.
It’s certainly possible that Swift may change and will become a more enjoyable language with frameworks that work as well with its features as Cocoa does with Objective-C. But it’s also possible it won’t, and that saddens me. It would mean that this platform which I’ve enjoyed developing for for over 10 years would no longer give me any pleasure. At that point I’d have to question whether writing Mac or iOS apps is something I want to continue putting so much time into, or whether my focus should move elsewhere.