How Significant Is Apple’s Swift Language for Programming?
At its Worldwide Developers Conference in June, Apple (NASDAQ:AAPL) announced the introduction of a new programming language that has big implications for the way developers create apps for iOS and OS X devices. Swift, created by Apple’s Chris Lattner, is intended as a faster, more effective way for developers to build apps for iPhones, iPads, and Macs. Apple’s Swift website describes writing code in Swift as “interactive and fun.” The company says that the language’s “syntax is concise yet expressive, and apps run lightning-fast.”
Wired’s Cade Metz (rather enthusiastically) reports that Swift will “instantly remake computer programming,” because it’s built for the average programmer. Swift offers a tool called Playgrounds, which will effectively enable people to teach themselves to code. But even better, Swift is fundamentally simpler and easier to use than Objective-C, the language that developers currently have to use to build iOS and OS X apps.
Metz writes that that’s what gives developers an incentive to use Swift immediately: “The larger point here is that such an enormous number of programmers have an immediate reason to use Swift. Today, hundreds of thousands of developers build apps for iPhones and iPads using a language called Objective-C, and due to the immense popularity of Apple’s consumer gadgets, these coders will keep building such apps. But Swift is a significant improvement over Objective-C — in many respects — and this means the already enormous community of iPhone and iPad developers are sure to embrace the new language in the months to come.”
As Metz notes, new programming languages typically take a period of years to develop a large audience, as developers need to find a reason to use the new language instead of ones with which they’re already familiar. But, Metz writes, Swift’s inherent incentive makes the new language “a different animal. When it’s officially released this fall, it could achieve mass adoption with unprecedented speed, surpassing even the uptake of Sun Microsystems’ Java programming language and Microsoft’s C# in the late 1990s and early 2000s.”
Developers who already use Objective-C will still need to learn to use Swift when they make the switch, but Swift is easier to use and more of a standard language than Objective-C. Metz writes, via Wired: “In and of itself, Swift isn’t that much more attractive than many other languages available to the world of software coders, including C#, Ruby, Python, and others. But it’s a big advance over Objective-C, a language that dates back to the mid-80s and, frankly, isn’t as easy to use as more modern languages.”
Programmers who already use other languages will find it easier to use Swift than Objective-C. Swift’s structure, plus its inclusion of tools designed to protect against mistakes and bugs, and features like Playgrounds, which lets developers see a program as they write it, make coding iOS and OS X “more approachable and fun,” Swift creator Lattner writes on his homepage. Lattner added a comment about his high hopes for the adoption of Swift, writing, “I hope that by making programming more approachable and fun, we’ll appeal to the next generation of programmers and to help redefine how Computer Science is taught.”
Mike Ash, a developer with years of experience writing code for Apple hardware, posted a list of Swift features that he found “interesting and unusual from the perspective of Objective-C.”
Those features include:
“Explicit optionals: Swift makes optional values a first-class language construct, and requires that any optional type be explicitly marked as such.
Multiple return values: Swift allows a function to return multiple values. Or if you look at it in a different way, Swift functions always return one value, but that value can be a tuple which is easily unpacked at the call site.
Generics: Swift supports generic classes and functions.
Type inference: Static typing is nice, but it can lead to painful redundancy in code. . . Verbosity in programming can be good to an extent, to help readability. But Objective-C and Cocoa can take it to an absurd extreme in many cases, and it will be great to have the option to cut down on that.
Class-like structs: Like Objective-C, Swift has both classes and structs. Unlike Objective-C, Swift structs can contain methods.
Trailing closures: This is a nifty feature that’s simultaneously pointless and really nice. . . It’s great to be able to arrange the code in a more natural way.
Operator overloading: In addition to overloading existing operators, Swift allows you to define entirely new operators from a limited character set.“
Ash also adds that he looks forward to using Swift, noting that the language “has a lot of features that may seem foreign to someone coming from Objective-C, but I think they ultimately make a lot of sense and will be nice to use.”
IT World’s Phil Johnson reports that Swift has “already established a firm foothold among developers,” citing GitHub data that placed the new language 15th on the list of most popular programming languages by new repositories created. (GitHub is a repository for the sharing of open source software.) Johnson’s research shows that developers are both searching for information on Swift and beginning to use it to write code. They created an average of 60 Swift repositories on GitHub per day and 47 per day after June 19, the date when the initial spike following Swift’s announcement at WWDC settled down.
Johnson also compared the number of new Swift repositories to the number of new repositories for Objective-C, the language that Swift is intended to replace. “I wanted to get a sense of whether developers are actually switching from Objective-C to Swift, or whether the new Swift code being created was in addition to what iOS developers are doing with their old standard,” Johnson wrote.
He found that from January through the end of May, an average of 294 new Objective-C repositories were created daily. Since Swift’s June release, and the subsequent spike in interest, the average declined to 246 new Objective-C repositories daily. Johnson admits that it’s impossible to infer causality from the drop in Objective-C repositories, but does note that the “drop of 48 repos per day is pretty close to the average number of new Swift repositories created per day since its release and initial spike in interest,” per IT World.
In a post on Apple’s Swift blog, the company says that developers can start using Swift now, as any apps written in it now will be compatible with the iOS 8 OS X Yosemite releases planned for the fall. Additionally, the post explains that “Swift is ready to use today, in brand new apps or alongside your proven Objective-C code.” Apple has provided several resources for developers working with the Xcode 6 beta pre-released to registered Apple developers, including an iBook guide to the new language, videos from WWDC, and downloadable samples of code.
Metz notes that Apple isn’t the only company to have developed its own programming language, with Facebook (NASDAQ:FB), Google (NASDAQ:GOOG)(NASDAQ:GOOGL), and Mozilla introducing languages of their own — Hack and D by Facebook, Go by Google, and Rust by Mozilla. Because most of these languages are open source, they can, in theory, spread across devices and services more easily than Swift, which is not open source. Some worry that Apple will too tightly control the language, limiting its growth, but others believe that the language will eventually be made open source, especially because Lattner has a long history of developing open source software.
While it’s not clear yet whether Swift will eventually evolve into a language for use on platforms other than Apple’s, it is clear that the company wants it to become developers’ language of choice for iOS and OS X apps. Once Swift has been around longer, it will be easier to tell if the early trends indicate an actual switch from Objective-C to Swift. And even if it’s not particularly likely that Swift will remake computer programming as a whole, it’s very likely that Swift is the future of Apple.