Rust and Swift
Comparing two exciting, new, apparently (but not always actually) similar programming languages.
Background
In summer 2015, I started learning Rust. Then, in September 2015, I started learning Swift. The superficial similarities between the two languages are obvious, and they hit their stride at roughly the same time: Rust’s 1.0 release was in May 2015 and Swift’s 2.0 release1 was in June 2015. Both cite inspiration from languages like Haskell, while retaining a C-like2 syntax which is more approachable to many of the developers inclined to pick up the language.
So, when I started reading the Swift book, comparisons were inevitable. For all that the two are very similar at a superficial level, they also make some very different choices in terms of language design and philosophy—and those choices are interesting!
Parts in the Series
This list is updated whenever I publish a new post in the series. You can also subscribe to the dedicated #rust-and-swift RSS feed, or to the more general #rust and #swift RSS feeds.
- Thoughts after reading the introduction to the Swift book.
- Basic types and the syntax around them.
- Operators, including overloading, and thoughts on brevity.
- Language design tradeoffs, highlighted by string manipulation.
- The value (and challenge) of learning languages in parallel.
- Collection types and the difference between syntax and semantics.
- Pattern matching and the value of expression blocks.
- Functions, closures, and an awful lot of Swift syntax.
- Sum types (
enum
s) and more on pattern matching. - Classes and structs (product types), and reference and value types.
- Hopes for the next generation of systems programming.
- Properties: type and instance, stored and computed.
- Methods, instance and otherwise.
- Indexing and subscripts, or: traits vs. keywords again.
- Inheritance: a Swiftian specialty (for now).
- Initialization: another area where Swift has a lot more going on than Rust.
- More on initializers!
- Deinitialization: ownership semantics and automatic reference counting
Some Notes on the Series
I am not by any means a programming language theory nut. (Or, at least, I wasn’t. This project, alongside a few other things, might be making one of me.) I am also not an expert. My opinions are considered, but not necessarily deeply informed, and you’ll see places where I have added corrections along the way as I got new information from feedback received along the way.
I also freely admit to a bit of a bias toward Rust, between the two. I like Swift, but I really like Rust. I think I come by this fairly, in that it’s just a matter of my own language-design preferences. I like Python better than Ruby, and in terms of how the languages feel, Rust is more like Python and Swift more like Ruby.
But—full disclosure—I’ve also made something of a personal investment in the future of Rust, in that I run a podcast focused on the language, from which I actually earn (a very small amount of) money.
One other thing: as of February 2016, I haven’t had a chance to build anything serious in either language—though I hope to change that over the course of this year. So these are very much surface-level impressions of the two languages. My thoughts and feelings about the two may change over time.
One last bit: the series literally started as a series of comments in a Slack team I participate in. You’ll note a substantial shift in the tone, structure, and content as I went along. The first post was really just off-the-cuff responses as I started reading. Starting with the second post, I was a good deal more intentional about what I was doing. As the series goes along, there is more and more of this, and it’s also informed by my work on New Rustacean.