This article was written using Rust 1.13 nightly (the latest as of September 2016) with unstable features. Certain unstable features may have been changed or removed since.
Have you ever noticed how similar Rust and Swift are? I don’t mean just syntactically either– the languages have a lot of similar design philosophies:
- Both languages have pretty good static type systems that prevent many errors at compile time, like
NULL reference errors
- Both languages often encourage using simple struct and enum values with traits/protocols where possible, over using object-oriented class hierarchies
- Both languages provide very nice high-level constructs (things like
map, or pattern matching) that get compiled and optimized into a static, native (and fast!) binary
Really, you can’t go wrong with using either language: both are really compelling for building things in a wide range of different domains!
That said, I personally prefer Rust, so learning about Swift inspired me to sit down and think, “what can Swift do that Rust can’t, and why?” To me, the most glaring thing was that Swift is really good for app development, while Rust in this regard is… lacking.
For now, let’s just talk about building Cocoa apps for macOS. Sure, you can build a native Cocoa app in Rust right now using the
cocoa crate, but it’s very far removed from writing a Cocoa app in Swift: notice the very procedural nature of their “hello world” example app.
So, how can we improve on the ergonomics of the