WWDC 2014 — Swift, Scenekit, and YOU

WWDC 2014 — Swift, Scenekit, and YOU

What you probably want to know:

Apple just made programming iOS and Mac apps about as easy as working with Javascript. Maybe easier.

Apple has just announced a new programming language called Swift. It's kind of like some kind of unholy love child of Go, Rust, Python, and Objective-C. Most importantly — no pointers, incredibly easy to learn (there's a free book), compiles to binary (and runs faster than Obj-C/C++ for at least some things), and it's also relatively safe ("managed code").

Apple also just made native game development in iOS (casual, at least) about as easy as using Unity or other similar frameworks by significantly beefing up SceneKit and SpriteKit.

You can import content from Cheetah 3D — including animations — with three lines of code. (Material support seems decidedly weaker — I suspect that may be a problem at C3D's end.)

Here's the three lines of Swift code:

Code:
let url = NSBundle.mainBundle().URLForResource("example", withExtension: "dae")
var error: NSErrorPointer? = nil
let scene = SCNScene.sceneWithURL(url, options: nil, error: error!)

Apple has also announced Metal — an OpenGL replacement — initially only for iOS, but it may also replace both OpenGL and OpenCL for Mac OS X since it provides GPGPU functionality. In particular, Metal allows developers to bypass the impedance mismatch between OpenGL and modern hardware (e.g. obsession with minimizing "draw calls" is an artifact of OpenGL, not the underlying graphics hardware). This probably affects Martin more than us :)
 
Last edited:
Hi,
I was actually pretty irritated by the Swift presentation. I didn't really understand why Apple compared the performance of a compiled language with a interpreted language like Python. I also don't think that the world needs another programming language. I'm personally a big fan of ObjC++. For high level code I use ObjC and for performance relevant code I use C++.

That Swift is faster than ObjC didn't surprise me too much since ObjC can be pretty slow for certain tasks. Especially calling functions (messages) is very slow compared to C++. So far I haven't seen any performance comparisons but I'm pretty sure that Swift won't be faster than C++. That's probably the reason why they compared Swift against Phython and ObjC and not against C++.

Should you find some C++ vs. Swift performance comparisons I would be really interested to read them. But I personally expect that C++ will also be the HPC king of the future.

But lets see, maybe my gut instincts are wrong.:redface:

Bye
Martin
 
Obj-C's message overhead is significant but largely bypassable (either by caching selectors or simply falling back to C). I don't think Swift's performance benefits derive from eliminating message overhead since it seems go do the same things under the hood (indeed Swift seems much like a new syntax for Obj-C).

You can mix Obj-C++ code with Swift easily enough, so it's not either/or.

I think the point of comparison to python or whatever is that Swift is a "safe" language (like python or java) but fast (probably faster than Java and comparable to C++). I'm skeptical of performance claims since Apple loves to cherry pick (doesn't everyone). So they optimized RC4 — whoop de do.
 
I'm very sure that the speed boots mentioned on the keynote comes form eliminating the message overhead in certain cases. For example in the sort benchmark. Since Swift uses closures instead of comparison functions the compiler can easily inline them. And inlining makes it really fast. Calling a C functions is still pretty slow compared to that. If you want to write really fast code you also have to eliminated C functions calls. Since std::sort() already inlines the comparison function I don't expect a speed gain in that special example compared to C++. ObjC doesn't do any inlining at all. That's one of the reasons why it's no good choice for HPC.

So I'm pretty skeptical concerning it's performance advantage. At least if you already use C++ for performance relevant code.

That Swift is a managed language doesn't out-wait it's complete lack of portability. The more I read about Swift the more I get the feeling that Apple just wants to make porting to other platform even more difficult. So my personal favorite for the future will be C++11. That's a language I really like.:smile:

Bye
Martin
 
I've just watched the WWDC videos about Metal. And it looks like that it is a really beautiful and powerful API. Very elegant how they merged rendering and GPGPU. Sad that it is iOS/A7 only.:frown:

Bye
Martin
 
I hope they plan to extend metal support (A8+ is a given) but it's hard to imagine they'll support a whole bunch of third party legacy hardware, so at best it might be stuff from now on.

W.r.t. Inlining:

http://stackoverflow.com/questions/11985307/static-extern-and-inline-in-objective-c

The problem I assume is you can't inline obj-c method calls, only C/C++ calls, which is also how blocks work (at the C level not the obj-c level). So what swift really does is level the playing field.

I think it's unfair to treat swift as an attempt to lock in developers first and foremost so much as an attempt to address obj-c's issues with lock-in being a happy side effect (not like obj-c isn't also a lockin). Incidentally, looks like swift was created largely by the LLVM guy.
 
Another interesting thread on StackOverflow:

https://stackoverflow.com/questions/24101718/swift-performance-sorting-arrays

Swift is way slower than C/C++ with default optimizations, but with aggressive optimizations [-Ofast] it actually performs on par with C/C++.

That makes me even more skeptical since I don't really trust the -Ofast optimization. C++ doesn't need -Ofast to be dam fast. And since most middleware is written in C++ developers have to learn C++ earlier or later anyway. So why not start with learning C/C++/ObjC. I also have serious doubts that Swift can be learned more easily. The syntax is not very nice. At least for my taste.

For the first I definitely won't use it. I just see no advantages in Swift. I have no problems with the C in ObjC. I actually like it. :wink:

Bye
Martin
 
I think it's unfair to treat swift as an attempt to lock in developers first and foremost so much as an attempt to address obj-c's issues with lock-in being a happy side effect (not like obj-c isn't also a lockin). Incidentally, looks like swift was created largely by the LLVM guy.

That's why I use C++ wherever possible. In the past I used almost exclusively ObjC but that was a big mistake. I really can't recommend young developers to use languages like ObjC or Swift on big projects. You basically give up the possibility to release your software on other platforms for pretty much no advantage. So if I would start again with Cheetah3D I would limit the usage of languages like ObjC or Swift to an absolute minimum. And for that absolute minimum we really don't need another language.

Chris Lattner is a true genius. In my eyes LLVM/clang is the best piece of software which was written in that millennium. So I have some serious doubts that the non-potability of Swift code was really his idea. Sound more like a Apple management decision. :wink:

Bye
Martin
 
Is there anything to say swift is non portable? Apple won't port it i assume.

I for one like swift's syntax, but it's not really worth my while bothering with it in the short term (no docs for most libraries, etc.) but in the long term it seems like there are lots of wins (memory management, functional programming).
 
Last edited:
I haven't finished reading the primer yet, but what I have read I like. But then I am a Java developer :)

Swift seems to take nice features from several languages and brings them together, which is nice, but it does leave some "interesting" in consistencies (at least to my mind).
I just updated my, very old by modern computer stands iMac to Mavericks so I could have a play with swift.

I like the idea of Objective C but it isn't very nice to actually write, and I find Xcode extremely unhelpful, though that could be i don't know the shortcuts like I do for Eclipse or IntelliJ, if I am honest if I was to do any serious Objective C I would probably pay for AppCode.

C++ 11 is getting a lot of good reviews, but if I am honest, I think I would find C++ just as hard as Objective C if i had to use it, I did learn C before Java, and even used it in the "real" world.

There is nothing to say swift can't be ported to other platforms, just there is no reason for apple to do so. They would have to port the libraries, and that would mean ensuring support for a larger array of hardware then they currently do.
I just don't see Apple trying to create a new language like Sun did with Java, as far as I can tell Apple are happy with their little universe, and the self selecting entry system, that you wanna play in their universe you use their tools.
On the one hand it should me a better experience, i. everything should just work ;), on the other you have more of a lock in for your code.
Is that much different from writing in VB (shudder) or C#? I don't think you can write for windows 8 in C# and have it run on mono without effort?

With respect to SpriteKit, I am hoping that they have sorted out the "stupidity" where you have to drop back down to UIKit to "render" more than a few words. Total night more handling text in SpriteKit, you start having to work around the framework to display and format text, which seems like a huge kludge to me.
SceneKit might be interesting, is that new? or just something that they are biging up?
I am not sure about HealthKit or any of that stuff.
 
I haven't finished reading the Swift primer yet, but what I have read I like. But then I am a Java developer :)

Swift seems to take nice features from several languages and brings them together, which is nice, but it does leave some "interesting" in consistencies (at least to my mind).
I just updated my, very old by modern computer stands iMac to Mavericks so I could have a play with swift.

I like the idea of Objective C but it isn't very nice to actually write, and I find Xcode extremely unhelpful, though that could be i don't know the shortcuts like I do for Eclipse or IntelliJ, if I am honest if I was to do any serious Objective C I would probably pay for AppCode.

C++ 11 is getting a lot of good reviews, but if I am honest, I think I would find C++ just as hard as Objective C if i had to use it, I did learn C before Java, and even used it in the "real" world.

There is nothing to say swift can't be ported to other platforms, just there is no reason for apple to do so. They would have to port the libraries, and that would mean ensuring support for a larger array of hardware then they currently do.
I just don't see Apple trying to create a new language like Sun did with Java, as far as I can tell Apple are happy with their little universe, and the self selecting entry system, that you wanna play in their universe you use their tools.
On the one hand it should me a better experience, i. everything should just work ;), on the other you have more of a lock in for your code.
Is that much different from writing in VB (shudder) or C#? I don't think you can write for windows 8 in C# and have it run on mono without effort?

With respect to SpriteKit, I am hoping that they have sorted out the "stupidity" where you have to drop back down to UIKit to "render" more than a few words. Total night more handling text in SpriteKit, you start having to work around the framework to display and format text, which seems like a huge kludge to me.
SceneKit might be interesting, is that new? or just something that they are biging up?
I am not sure about HealthKit or any of that stuff.
 
Scenekit was in iOS 7 but seems significantly improved (also: Metal).

I find XCode to be far less annoying than Eclipse, but that's me.
 
I tend to prefer intellij over eclipse anyway, I just find eclipse to be subpar in general.
Perhaps I just need to learn the short cuts for Xcode so I can feel productive.
 
You do know that Jetbrains do a Mac IDE:

http://www.jetbrains.com/objc/

It only supports objc right now, but I imagine swift support will be very quick to appear. (I used to use WebStorm — and for a Java application it's pretty nice, but there are so many nice native editors for the Mac — I currently use BBEdit and Sublime.)
 
Yeah, AppCode.
I haven't tried the latest version, but the previous version relied on Xcode for UI layout/storyboards.
The blurbs says the latest doesn't.

It will be interesting to see if it does gain Swift support.

It is, as far as I can tell totally separate from IntelliJ, that is its not like when you pay for IntelliJ you get Objective C support in the same you get javascript support so you don't also have to buy WebStorm... though I guess it can't be helped.
 
The more I read about Swift the more I get the feeling that Apple just wants to make porting to other platform even more difficult. So my personal favorite for the future will be C++11. That's a language I really like.:smile:
This is enlightening. I didn't realize that Martin cared about portability.

The Metal shading language is based on C++11. That makes for a significant improvement over GLSL, but it's still terrible compared to Swift. I like that Swift lets me write code that's even closer to abstracted, speakable language, than C# is, but isn't garbage collected, which was always a pain, working on Unity projects.

It will be interesting to see what happens if Martin ever myelinates his Swift+Metal axons. I don't believe it's possible for a programmer to be as productive in any other environment. That said, it's possible that he's not wired for it, and he's probably doing better than any other human is capable of already. Personally, I've experienced a joy, with this combination, that I've never experience before. I can stay in flow states for so long, when working with it.

There is nothing to say swift can't be ported to other platforms, just there is no reason for apple to do so. They would have to port the libraries, and that would mean ensuring support for a larger array of hardware then they currently do.
I just don't see Apple trying to create a new language like Sun did with Java, as far as I can tell Apple are happy with their little universe, and the self selecting entry system, that you wanna play in their universe you use their tools.
I assume that it's being open sourced, and made available for Linux next, so that no potential making-money-for-Apple time is wasted with Java practice.
 
Last edited:
RE: Swift

I’ve worked with it some in Linux. No problem.

Microsoft has publicly stated they will support Swift (when? how?)

Apple seems to be doing its best to NOT make it a closed language like Microsoft attempted to do with C#.

(Apple has said it is Open Source. Yea!)
 
Yes, quite some things changed with Swift in the last two years but it is no topic for me yet. The disadvantages still outweigh the advantages and that probably won't change too fast.

I'm very sure that ObjC and C++ have a very bright future on the Mac. No matter how hard Apple pushes Swift.:wink:

Bye
Martin
 
There's no reason to switch languages if you like the language you're working with, especially if that's C/C++.

If I were picking a new language to learn right now and I didn't know Javascript it would be Swift. (Javascript is the single most useful language to know right now — you can do almost anything with it, and Swift is nicely targeted at the exact spots where Javascript is weakest.)
 
Back
Top