Apple Swift 3: Forward-looking, but not backward-compatible

Swift 3 is a great opportunity to start fresh with the language, but if you have existing Swift codebases, be prepared to rewrite -- or dump -- them

Apple Swift 3: Forward-looking, but not backward-compatible
Thinkstock

"Move fast and break things," the saying goes. Apple does both with the 3.0 version of its Swift programming language.

Developed by Apple to replace Objective-C, Swift is now out in its first full point revision since it became an open source project. Apple deliberately made Swift 3.0 a backward-incompatible changeset to usher in better developments over the long run.

Breaking bad (but for the better)

In a blog post detailing the full body of changes for Swift 3.0, Apple singled out the two biggest breaking changes.

The first is better translation of Objective-C APIs into Swift, meaning that code imported from Objective-C and translated into Swift will be more readable and Swift-like. The bad news is any code previously imported from Objective-C into Swift will not work in Swift 3; it will need to be re-imported.

The other major change is applying the API guidelines to Swift's standard library. Most every item referenced in the standard library has been renamed to be less wordy. But again, this brings bad news for anyone with an existing Swift codebase: Apple says "the proposed changes are massively source-breaking for Swift code, and will require a migrator to translate Swift 2 code into Swift 3 code."

Apple is planning to provide migration tools for XCode 8.0 to help automate this transition, but such tools go only so far. As commentor cageface noted in Hacker News, "my experience has been that it misses a lot of things and upgrading requires many manual fixes."

Cleaner slates

Developers had several months to look at Swift 3.0 as a preview, where many other breaking changes to the language's syntax and behaviors have been outlined. But Apple's fixes for these changes are specific to its implementation of Swift (such as the XCode tools) and don't speak to the the Linux and Windows ports of the language.

If there's good news in this picture, it's that other versions of Swift haven't been as widely used as the MacOS/iOS incarnation. In Windows' case, the only port so far has been an unofficial version.

A cleaner Swift 3 slate means fewer reasons not to start developing in Swift on other platforms. Much of the breakage in Swift 3 hearkens back to Python deliberately breaking backward compatibility between versions 2 and 3 in order to shed legacy behaviors, such as inconsistent support for Unicode.

But the impact on Python was major and severe, since a massive amount of Python 2.x was already in the wild. Swift is a much younger language, with far less legacy code to bring up to speed and -- Apple is hoping -- a great deal more of it to be written across platforms later. In that light, a lot of breakage now makes sense in exchange for less breakage later.

Copyright © 2016 IDG Communications, Inc.