For the last 5 months, I have been working on an iOS project using Swift. Its been an interesting experience. While the language has some parts I like, personally I feel mostly disappointed at the complexity of the language cause, honestly, I don’t see how they help me write apps faster.
A friend of mine described Swift as a “Mirror Programming Language”: everyone who looks at it sees what he wants to see, which I find pretty true. I have had JavaScript developers see it very similar to JavaScript, Scala devs see it like Scala, Ruby devs see it like Ruby etc etc. To be fair, Swift probably took elements from all of the above, but its still interesting to hear the conversation.
My Hopes for Swift
I attended WWDC this year and was there during the Keynote when Apple announced Swift.The moment they showed a swift program with variables defined with the “var” keyword, I got really excited. I am actually a fan of JavaScript, which I generally recommend as a first language to learn for folks trying to get into programming (My only gripe has been lack of a formal definition for “Classes” which seems to be coming in ECMAScript 6). Additionally, Apple introduced “Playgrounds”, an interactive workspace very inspired by Bret Victor’s work as seen in the video below. Bret Victor is another of my heroes, one of the few developers who questions why programming today is still stuck in the text-and-compiler metaphor that was invented over 40 years ago. If you haven’t already, do watch the video below where he goes through some of his thinking.
But between a js-like syntax and an interactive playful workspace, I thought Apple had finally cracked it and democratized programming. On the flight back, I was so sure that Swift would be the programming language that I would now recommend to students going forward.
Working with Swift
Working in Swift the last few months, my opinion has changed a lot. The simplicity that (I thought) Swift promised never really happened and I find the language a lot more laborious to work with than even Objective-C which I generally liked.
- Optionals?: Swift introduced Optionals that let you explicitly declare that certain variables may not hold data at all times. I am not sure what kind of bugs this is helping me avoid. And I am tired of unwrapping Optionals all over my code. Additionally, Optionals introduce a whole new slew of potential errors.
- Type casting in Swift sucks. Swift does nothing automatically. Want to add an Int to a CGFloat? Well make sure the you convert your Int to a CGFloat yourself. This gets very annoying when you want to do things like manipulate view dimensions by multiplying with and adding/subtracting constants. I have reached a point where I only do one simple math operation per line.
- Unexpected types: Why the hell does array[1..10] return a Splice object that you have to cast to an Array?! If I am asking for a part of a collection, just return it as the same data type.
- Way too much: There is a lot of smart in Swift, and I am sure it attracts a certain kind of personality. Operator Overloading, Literal Convertables, etc etc. But personally I find very little of that really valuable.
- Readability: Personally I ding a programming language for every meta character in code (?, ! etc) as I think they generally hamper readability. Swift has a lot of that.
- XCode 6 is terrible: XCode has gotten really bad. SourceKit editor crashes all the time, errors make no sense, quick fixes don’t actually fix (video below). Its surprising how poor XCode stands up to other modern IDEs.
Swift has some nice parts too. Playgrounds/REPL are actually useful to debug small pieces of code and the lack of header files is a blessing, but besides that, I am not too excited by it. To me Swift is a disappointment, something I had hoped would open mobile development to a larger pool of people just getting into programming. Instead its another language that seems to have been developed by very smart people for very smart people. Nothing wrong with that, its just not what gets me excited.
I mostly agree with Marco on this when he said:
Swift looks interesting, but in all of Overcast’s development so far, I’ve never run into a problem that’s the language’s fault that Swift would have handled better. It appears to solve problems I don’t have, to gain small (and still theoretical) optimizations that I don’t need, at the expense of many Objective-C features I really like.
Further reading:
Nice write up. I’m mostly in agreement. I do find it to be considerably more readable in the sense that explaining code to someone looking over my shoulder I’m explaining less. The issue with Swift that’s making it begin to get under my skin is that it’s less dynamic. I realize that it’s supposed to by a move toward safety. But I think it kills the languages potential for elegance.
LikeLike