What's New And Different About Apple's New Swift Programming Language?

We tore apart Apple's 850-page iBook on its new, simpler programming language, to find out why Apple would introduce a new language--despite all the headaches it will cause.

Apple's new Swift language is the first time Cupertino has seriously changed its software underpinnings since it bought NeXT, which became the guts of Mac OS X. So how different is it, really? And more importantly--why fix what isn't broken?

"Its pretty wild, man," was the first reaction from Brooklyn-based senior iOS developer Christopher White after he saw the news. White is lead developer on the Cameo app at Vimeo (as well as my former business partner at an iOS dev shop in Williamsburg). "It's what a lot of native developers have wanted," he told me. "To do something more like a scripting language."

That's because more and more programmers are becoming fluent in web languages. White says Swift's scripting-like syntax modernizes Apple's developer environment in a way that will feel more familiar to web developers. "It lowers the barriers of entry for anyone who comes from a scripting background," he says, which would include a lot of web developers--especially developers used to writing in Perl or PHP. "Their Hello World app is one line--that's very much like a scripting language," says White. "So they're just modernizing the style, really."

There are performance improvements, too, but White says the sandbox feature--"where you can run stuff in Playgrounds to be able to change code on the fly without recompiling"--is an even bigger boon. "The overall syntax is very JavaScripty in a way--they're moving toward not having hard type variables," White says. He calls it a mishmash of a scripting language, with all the power of a compiled language. "It's still native, it still compiles, but it's a style of programming that a lot of people--especially backend developers--are used to."

There's another facet to Swift, however: keeping up with the Joneses. "They're doing more now to advance their languages and maintain technical dominance, competing with Google, which has Go," speculates White. "It's cachet, in a way. You're doing your own language, Google? We're doing our own language too, assholes!"

But Swift's changes aren't entirely positive, at least at first glance. Objective-C was famously verbose, meaning it was easy to read. "[Swift] definitely seems less verbose, whereas with Objective-C it's so goddamn verbose! You can almost always follow what's going on [in Objective-C] because the method names are so detailed. Whereas [in Swift] you'd have to have a little more familiarity with the language before you picked it up. Especially someone else's code."

More of an obstacle is the learning curve. "It'll take a little time," says White. Developers will be asking themselves: Do I start running Swift, or do I make my project manager happy? "Most people are gonna learn it on nights and weekends, so if they get an assignment they can write it using Swift code," he says. Mixing code also means switching context, White explains: "It'll take a while for the community at large to come to grips with that. Before the bigger enterprises adopt it, they'll want to see more engineers [using it]."

Nevertheless, White is diving in. "I generally take on Apple's newest stuff and don't look back, because Apple's not looking back. It's worth it to learn Swift because that's where everything's going for them."

What's really unique about Swift? "How they kept this secret--their ability to do that is almost more amazing than anything else," says White. We wanted to get more specific than that, so we set about to do a quick teardown of Apple's Swift guide and find out exactly how Swift departs from Objective-C and other C-derived languages. Here's what we found.

How Swift Differs From C And Objective-C

The first thing that piqued our interest: You can now use emoji in your code. (Not to be confused with artist Ramsey Nasser's all-Emoji language, which we covered here.)

Perhaps to make up for the slightly less verbose nature of Swift, you can now nest multi-line comments in your code to help others (or yourself) know what each section of your codebase does.

Semicolons aren't required anymore, except where they are.

Operators in Swift make arithmetic easier--as well as more advanced floating-point calculations. It helps you prevent careless errors when writing those operations, too.

Writing in Swift also means fewer overall package files, since a single file can auto-generate its own interface for other parts of the application to access it. The "note" below feels like an overture to web developers. Traditionally in Objective-C, individual instances of a type are called "objects," as in "object-oriented programming," hence the name Objective-C. But in object-oriented web JavaScript, for example--a fairly new programming pattern for web development--these individual objects are called instances. Apple has chosen to go with more web-native vocabulary here.

Sub-properties of an instance are also easier to manage.

And object inheritance also behaves in a more straightforward way, which should save web developers from tearing their hair out during debugging, trying to figure out why their object/instance is inheriting properties seemingly from nowhere.

Add New Comment