An Analysis of Apple's Swift from a Microsoft perspective

APRIL 17, 2015 // By Jason Bock

I love programming languages. Software development as a whole interests me, but for some reason languages draw me in. I find it interesting to see what different languages provide for their users and how that functionality is expressed with its syntax. Pattern matching, metaprogramming, data binding, multiple inheritance – each programming language I’ve studied and used brings something new to the table for me to digest. And every time that experience has enriched me with a new idea I can use for the projects I’m working on.

So when I had the opportunity to work on a small iPhone project in 2008, I jumped at the chance. iPhones were relatively new, and the Apple world was a new one to me. My career has primarily involved using tools in the Microsoft stack, so I welcomed a chance to broaden my horizons. The project timeline was short – only 4 weeks – so I wasn’t able to do a deep dive, but I got to work with XCode and Objective-C. The end result was, in a word, frustrating. Gratifying, yes, but it definitely has its moments of irritation.

I admit that a fair amount of that frustration was self-generating. It takes time to become proficient at something when it’s completely unknown to you. The Dan Plan is a great example of this in the golfing world. Dan McLaughlin had never played golf in any serious way, and he decided to devote 10,000 hours of practice to become a professional golfer. He started in April 2010, and as of the writing of this article, his handicap is 3.3, which is quite respectable. But it’s taken 4 years of continuous practice to get from a person who could barely swing a club decently to someone who can play very well. The point is that at the beginning of any journey into the unknown, the first steps may be very awkward just because you’re new at it. Therefore, I can’t put all the blame on the tooling and the language.

However, it was frustrating to code in Objective-C. I’ve spent time in my life using languages like C#, Java, VB and JavaScript (among others) and for the most part I’ve always been able to wrap my head around the syntax. Even if I didn’t know the language at all, sometimes I was able to read the code and understand the gist of it (Python is a good example of this). But Objective-C was not a friendly language. The syntax felt inconsistent and confusing at first glance, and it never got better the more I used it. I was able to make progress understanding Interface Builder and getting parts of the application wired up – heck, I was even able to find a unit testing library for Objective-C and wire it up into XCode so it could automatically run unit tests. But the only language I could use to create an iPhone program was one that did not leave a positive lasting impression.

Throughout its history, Objective-C was never a desirable language for software developers. The only reason it became so popular was due to the incredible rise in popularity of iPhones. If you wanted to create an application for the iPhone ecosystem, you had to use Objective-C. No other choice was available, which is why in mid-2009 its usage took off. Such a restriction seemed odd to me. If you want to create programs that run on the Windows platform, the number of choices is high. You can create scalable real-time systems in Erlang. You can run web servers in Node.js. You can develop web applications using Ruby on Rails or Django. You can craft rich Windows applications using C# and XAML. The point is, you have choices on the Windows platform.

Fortunately, the world is changing for Apple developers. Recently at the WWDC 2014 event, Apple announced a new programming language, Swift. Apple describes Swift as “a new object-oriented programming language for iOS and OS X development. Swift is modern, powerful, and easy to use.” From what I’ve been able to glean from the documentation, I would agree. Here’s just a couple of features that caught my eye:

  • Generics – Though it’s not clear if Swift supports covariance and contravariance yet, it’s refreshing to see Swift included generics out of the gate.
  • Closures – Having a functional construct like closures opens up a lot of rich development opportunities in APIs.
  • Extensions – While it may seem similar to extensions in .NET, it appears to have more capabilities available to developers to extend types.

I’m glad to see Apple release Swift. It’s a refreshing, modern change that seems to bring the Apple programming environment closer to what others have enjoyed for years. The syntax is a nice, reasonable combination of a number of programming dialects and concepts. The Playground looks like IPython, Mathematica or F#. Unfortunately, I can’t play with it. I don’t own a Mac, and the only way to kick the tires on Swift is if you have a Mac. This isn’t true of many languages I know of. If I want to try Ruby, I can easily do that. Same with TypeScript or F#. But nothing like that exists for Swift right now outside of the Apple world. So all my speculation is based on what I’ve read from Apple’s documentation.

There’s no doubt that Swift will be popular in Apple’s world, if for no other reason than it’s just better than Objective-C. In my local area of the Twin Cities, there’s already a SwiftMN user group and I’m sure others will be created elsewhere in the future. You’ll also see books on writing iOS applications with Swift as well as Swift talks at conferences and code camps. Those are all good things. But it remains to be seen what kind of impact Swift will have in other environments. Currently, Swift is closed to Apple’s domain. It’s rumored that Swift will be open-sourced by the time it’s released, but even if it is, will developers that use C# or Ruby or Python switch to Swift if the language is made available in useful domains? Right now there are viable options to write mobile applications for the iPhone using C# or JavaScript. Will Swift make any inroads into other environments? Will anyone be writing web servers on Windows or Android applications with Swift? I don’t know – crystal ball gazing is not one of my skills. But it seems to me that having a cross-platform strategy is a good thing. Being able to target multiple runtimes without rewriting logic or sacrificing performance is a win in many ways, and I hope that Swift is able to make this claim in the future.

Categories // Custom Application Development
Tags // C#, Apple, Enterprise, iOS, Mobile, Objective-C, OS X, Swift Language, WWDC, Xcode 6

Get Started

Contact Us