Archive for December 15, 2015

Tuesday, December 15, 2015

Craig Federighi on Swift

John Gruber:

Apple senior vice president of software engineering Craig Federighi joins the show for a wide-ranging half-hour discussion about Swift — Apple’s new programming language that just went open source.

John Siracusa provides follow up (of course).

Craig Federighi:

And slowly we’ve also been bringing back much of the dynamism. Now there are some things that are impossible in Objective-C, and most of the dynamism that you really want is the ability to figure out what classes this really needs, to be able to cast the class dynamically to a particular protocol, to be able to do a kind of response to select or perform selector check. All of these things are possible in Swift today. And there are some other things that aren’t, but certainly we consider important to ultimately bring to the language. So, this thing about a dynamic programming model is still very important to us.

Now there are still some very unsafe things that people do in Objective-C, and I’ve been guilty of this myself, where you walk the Objective-C runtime and hack the method table — and that’s cool. But it is highly unsafe and doesn’t lead to very maintainable, scalable large programs.

There’s a lot of dynamic behavior between -respondsToSelector: and dangerous swizzling, for example adding methods at runtime and capturing messages as objects. It’s also worth noting that much of what did make it into Swift doesn’t work with pure Swift. So it won’t work on Linux or if your code is using the more advanced language features. For example, pure Swift protocols don’t support optional methods, and dynamic properties imply @objc, which comes with lots of limitations. Hopefully this will change.