2014-06-04

Co.Labs

Why Apple's New Swift Language Will Keep Developers Loyal (And Away From Android)

With many of the niceties of web languages, could Swift be the key to Apple's transition to a web company?




When Tim Cook took to the stage this year it was the first time in WWDC’s history where Apple dedicated a third of the event to talking about the new developer features in OS X and iOS during the keynote. Cook called it “the mother of all releases for developers” and no one can say he was exaggerating. By the end of the keynote Apple had announced over 4,000 new APIs for iOS.

But the thousands of new APIs weren’t the thing that generated the most excitement among developers. The announcement that garnered literal screams of elation from the crowd was when Craig Federighi, Apple’s senior vice president of Software Engineering, walked onstage with a big grin on his face and announced Swift, the company’s new programming language that has been secretly in development for years. Federighi said Swift “totally rules.” But does it? We talked to some prominent developers to find out.

Putting Developers In A Flap

Befitting its name, it didn’t take long for coders to launch into creating test apps using Swift. One of the first people out the gate was Nate Murray, cofounder of Fullstack.io, creator of the popular Game for Cats (not humans) and an early employee at IFTTT. Instead of the “Hello World” message programmers traditionally use to test a new system, Murray created a Swift implementation of Flappy Bird, the frustratingly addictive mobile hit which did the rounds earlier this year.

“It took me about four hours to read the e-book on programming Swift and put it together,” he says. “I put out a tweet right before I went to bed just to share it with a few friends and it blew up. That tweet [got] almost 500 retweets.” Less than 24 hours later, the news had already amassed 2,700 stars on GitHub.

“Swift is surprisingly fantastic, especially for a language that's been developed in secret for years,” he continues. “It has the functional programming features that folks like the Ruby community will like, coupled with performance features lower-level programmers demand. And [it’s] fast—surprisingly fast, even to compile.”

The Need For Speed

This point is one that is echoed across the developer community.

“My first impression is that it is a fun, clean language to work with that should result in easier-to-read, shorter code,” says Keith Blount, the developer behind acclaimed writing software Scrivener. “The introduction of the ability to have multiple return values from functions is particularly welcome. In Objective-C, if I want to, say, create a function that tells me the most commonly used font in a document and how many times it is used—and maybe also whether it is used in more than half of the text—I either have to have separate functions or create extra pointer parameters, which results in some pretty clumsy and ugly function or ‘method’ names. That’s going to be much more elegant in Swift.”

For Blount and for many coders like him, the simplicity of Swift syntax (and its ensuing speediness) is one of its most valuable qualities. For example, to create a record of people’s favorite numbers would look something like this in Objective-C:

NSDictionary *favoriteNumbers = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInteger:7], @"Jane", [NSNumber numberWithInteger:21], @"Bob", [NSNumber numberWithInteger:99], @"Sarah", nil]];

That same code in Swift would actually be far more straightforward:

var favoriteNumbers = ["Jane": 7, "Bob": 21, "Sarah": 99]

While the Objective-C line won’t make much sense to non-coders, the Swift line is quickly comprehensible to anyone. “More readable code is more maintainable code,” Blount says.

“Swift will be a powerful new way to quickly develop certain classes of feature or entire apps,” says Till Schadde, CEO of equinux, the Apple Design Award-winning company behind VPN Tracker, Mail Designer Pro, and Spot Maps. “We hope that it will be possible to speed up some standard aspects of app development that are currently still quite time-consuming. By eliminating things like memory management issues and other common pitfalls, Swift should also help to increase overall app stability and quality.”

The Code Of The Next Generation

“Coding is the new literacy” is a phrase that has resonated through the halls of various departments of education around the world in the last few years. It’s not just hyperbole either. The number of programming jobs is only thought to grow in the coming years, so it’s important to get younger people into coding. To that end Swift will likely be a valuable tool in ushering in a new wave of developers, many of whom will bring fresh ideas to the party.

“We’ve found that it usually takes students a while to get to grips with Objective-C,” says Schadde, who runs an annual iOS development course with Munich’s TU Technical University in his native Germany. “Despite recent improvements, Objective-C is still very much a C-based language and it shows. Students typically have Java, C#, JavaScript or other scripting language experience, so dealing with memory management—be that allocation or deallocation of memory—and other issues you don’t have in more modern languages is often a challenge.”

In this space, he thinks Swift will be a marked improvement.

“We hope that Swift’s easier learning curve and safe programming model will allow our students to focus more on creating great user experiences and UIs, and spend less time on battling with the intricacies of Objective-C and write less boilerplate code,” he says.

Of course, a valid question is whether or not an easier barrier of entry is going to be viewed as a positive by established developers in an already crowded app marketplace. While Apple benefits financially from the 1,206,899 apps (and counting) currently in its iOS App Store, established programmers may well feel different. However, Rishi Modha, director of FIPLAB, says that this fear is overrated.

“Whilst Swift may encourage more developers to start writing apps for Mac and iOS due to a lower barrier to entry, I think the impact of greater competition for established market players who are already developing top-quality applications will be negligible,” he says.

Sustained success in tech demands a long-term vision, and while lower barriers of entry might mean a slew of new app makers entering the frame, in the long haul a stronger developer community will be better for everyone.

As for users, is Swift likely to make an impact? Sort of.

“As developers get up to speed with Swift, they'll be able to build better products by writing code faster and more efficiently,” Modha says. “However, the end user impact from this may not be immediately obvious for anything other than games and resource intensive applications.” When all is said and done, the real impact of this year’s WWDC may wind up being some of the “value added” features Apple has incorporated into iOS 8, such as Widgets, Extensions, and the seamless Handoff switching between devices.

Staying Objective About The Transition To Swift

“It’s hard to be objective (no pun intended) about a new language when you have hundreds of thousands of lines of code in the existing language,” says Keith Blount. “My hope is that Objective-C will continue to be supported for years to come, so that developers with large and complex apps such as myself can transition gradually. Although Swift looks exciting, converting an extensive, mature, and stable codebase written in Objective-C is not something that can be done overnight. So as much as I’m enjoying learning it, I’m also dreading implementing it—which is why I’m very glad that Objective-C and Swift files can sit side-by-side in the same app.”

For all of these reasons, Swift is unlikely to overtake Objective-C overnight. "At first I was very annoyed [when I heard about Swift],” says Lee Armstrong, CTO at Plane Finder. “We work on a lot of other platforms here so already do a lot of Objective-C, C, C#, JavaScript, Python, PHP, and Java. However, after digging into the docs and having a quick play it appears to have some of the niceties of a scripting language, but the performance of native compiled code. I think once the learning curve has been overcome it will make development much faster and more importantly less crashes in developer code. Transition will be slow and I can see it being 2-3 years before Objective-C becomes the poor relation.”

Ultimately, there are also few, if any, discernible disadvantages to Apple’s new language. "Swift is the future of programming for Mac and iOS devices,” says Frankie Laguna, lead developer for FIPLAB. “It takes all the good parts of Objective-C and makes them fun, fast, and best of all, less verbose. Also, it lowers the barrier to entry for developers who are looking to start developing for the Mac/iOS because its new syntax feels familiar to languages people already know such as JavaScript and C."

No wonder Craig Federighi looked so happy at WWDC.

[Image: Flickr user Keng Susumpow]




Add New Comment

8 Comments

  • Apple may keep developers loyal and away from Android but not their apps. Our ambition is to free developers from the pointless time and costs associated with redeveloping their mobile apps from one platform to another. To that end we are currently developing MyAppConverter, a service platform, which will automatically convert native iOS code to android Java code. Our mobile code conversion approach is based on Semantic Driven Code Transformation, which is unique compared to current market tooling solutions. Beta service starts in August.

  • You do realize that Objective-C has had literal creation syntax for awhile? Your Objective-C sample these days would look like

    NSDictionary *favoriteNumbers = @{ @"Jane" : @7, @"Bob" : @21, @"Sarah" : @99 };

    Outside of the proliferation of at-signs, not that scary.

  • This code isn't an accurate depiction of Swift's brevity (albeit wonderful). Modern Objective-C allows for the statement you used above to be expressed as:

    NSDictionary *favoriteNumbers = @{ @"Jane" : @7, @"Bob" : @21, @"Sarah" : @99 };

  • This code isn't an accurate depiction of Swift's brevity (albeit wonderful). Modern Objective-C allows for the statement you used above to be expressed as:

    NSDictionary *favoriteNumbers = @{ @"Jane" : @7, @"Bob" : @21, @"Sarah" : @99 };

  • "NSDictionary *favoriteNumbers = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInteger:7], @"Jane", [NSNumber numberWithInteger:21], @"Bob", [NSNumber numberWithInteger:99], @"Sarah", nil]];

    That same code in Swift would actually be far more straightforward:

    var favoriteNumbers = ["Jane": 7, "Bob": 21, "Sarah": 99]"

    In this case in Objective-C you can write it as following:

    NSDictionary *favoriteNumbers = @{@"Jane": @7, @"Bob":@21, @"Sarah": @99}

    But yes, Swift is the future :)