Swift is a more convenient Rust
Swift and Rust are both functional programming languages with LLVM-based compilers, but Rust focuses on performance and memory management, while Swift emphasizes ease of use and developer productivity.
Read original articleThe article discusses the similarities and differences between Swift and Rust, two programming languages that share many features but cater to different programming paradigms. Both languages incorporate functional programming concepts such as tagged enums, match expressions, and first-class functions, and they utilize an LLVM-based compiler for native code and WebAssembly (WASM) compilation. However, Rust is characterized as a low-level systems language that emphasizes performance and memory management through ownership, while Swift is a high-level language designed for ease of use and developer productivity. Swift employs a default value-type memory model with copy-on-write semantics, making it simpler to use, whereas Rust requires more explicit handling of memory through its ownership system. The article highlights that Swift's syntax is designed to be familiar to developers coming from C-like languages, often hiding complex concepts behind simpler constructs. While Rust's compiler enforces strict rules to catch potential issues at compile time, Swift offers a more automatic approach, which can lead to less explicit handling of certain programming challenges. Ultimately, the author concludes that Rust is better suited for systems programming, while Swift excels in UI development and server-side applications, with an expectation of increasing overlap between the two languages in the future.
- Swift and Rust share many functional programming features but differ in their approach to memory management.
- Rust is a low-level language focused on performance, while Swift prioritizes ease of use and developer productivity.
- Swift's syntax is designed to be familiar to C-like language developers, often simplifying complex concepts.
- Rust's compiler enforces strict rules, while Swift's compiler offers a more automatic handling of programming challenges.
- Rust is ideal for systems programming, whereas Swift is better for UI and server-side applications.
Related
I Hope Rust Does Not Oxidize Everything
The author expresses concerns about Rust's widespread adoption in programming, citing issues with syntax, async features, complexity, and long compile times. They advocate for language diversity to prevent monoculture, contrasting Rust with their language Yao.
Don't write Rust like it's Java
The author discusses transitioning from Java to Rust, highlighting Rust's type safety, differences in traits and interfaces, complexities of ownership, and the importance of embracing Rust's unique features for effective programming.
Language Compilation Speed (2021)
The article examines Rust's compilation speed compared to C/C++, noting frustrations among developers. It proposes a benchmarking method, revealing GCC compiles at 5,000 lines per second and Clang at 4,600.
From Julia to Rust
The article outlines the author's transition from Julia to Rust, highlighting Rust's memory safety features, design philosophies, and providing resources for learning, while comparing code examples to illustrate syntax differences.
Rust's Ugly Syntax (2023)
The blog post addresses complaints about Rust's syntax, attributing them to misunderstandings of its semantics. It suggests simplifying semantics for readability while maintaining performance and safety features.
- Rust is praised for its performance and memory management, particularly its ownership model, while Swift is noted for its ease of use and developer productivity.
- Many commenters express frustration with Swift's limitations outside the Apple ecosystem, suggesting it is primarily an Apple-centric language.
- There is a consensus that Rust has a more robust package ecosystem compared to Swift, which struggles with cross-platform compatibility.
- Some users find Rust's syntax complex and challenging, while others appreciate Swift's more straightforward syntax.
- Tooling and developer experience are significant points of contention, with Rust being favored for its superior tooling compared to Swift's limitations on non-Mac platforms.
1. A large part of why many people love Rust is that it's the first time they've used an ML family language. One of the innovations of Rust was to create a community that felt like home to Unix hackers who weren't programming language nerds.
2. Rust is the first language to bring non-GC automatic memory management to the mainstream. It won't be the last and it might well be the worst. Other languages in this space include Swift (as in OP's post), OCaml[1], and Scala[2]. These alternatives take the approach that tracking ownership is not the default, which is fine for the majority of programs and far more ergonomic.
There's also a corollary
3. The age of Smalltalk is over. It's now the age of ML. (Amusingly, going backwards in time, from 1983 to 1975). The languages that dominated the 2000s (Ruby, Python, Javscript, PHP) were all more or less derived from Smalltalk (everything is an object! dynamic types! runtime metaprogramming!) The new languages (Rust, Scala, Swift, Kotlin, etc.) are ML family languages. Similarly, back in the day you could learn, say, Ruby, and still be reasonably proficient in Python or JS. Now you can learn, say, Scala, and pick up Rust or Swift reasonably easily.
That said, the difference between the two has a lot less to do with the language itself than the world surrounding it. You can use Swift cross platform but it’s very obvious that Apple platforms are the primary target. Rust has a rich and varied package system, about the only assumption most packages make is that you’re using the Rust standard library. By comparison lot of Swift packages (which is a much smaller ecosystem anyway that’s slowly transitioning away from Cocapods, Carthage etc) will lean on OS APIs that won’t work if you compile for Linux or WASM[1].
I want Swift to be a more convenient Rust but it just isn’t there. e.g look at IBM abandoning Swift on the server not that long ago.
[1] for example, this blog post:
https://swiftrocks.com/weak-dictionary-values-in-swift
Discusses making a dictionary with weak values in Swift. It has a homegrown Swift version then discusses using NSMapTable… which isn’t available on Linux. But you wouldn’t know that reading the article because the assumption is that you’re running on an Apple platform.
They did it well, but not invented?
There very many kinds of influeces: https://www.reddit.com/r/rust/comments/le7m54/is_it_fair_to_...
Especially Cyclone, I think: https://en.m.wikipedia.org/wiki/Cyclone_(programming_languag...
In many cases Swift would be a better choice than Rust, when the convenience and developer experience is worth trading for some performance. However, Swift's biggest problem is that any usage outside of the Apple ecosystem is a second(or third) class citizen. Until this is solved, Swift will remain mostly an Apple only language, regardless of how nice it is.
struct Task {
future: Mutex<Option<BoxFuture<'static, ()>>>,
task_sender: SyncSender<Arc<Task>>,
}
You can do the exact same thing in Rust:
impl Coin {
fn valueInCents(&self) -> u8 {
match self {
Self::Penny => 1,
Self::Nickel => 5,
Self::Dime => 10,
Self::Quarter => 25,
}
}
}
This isn't true. Copy-on-write semantics are implemented only for arrays, dictionaries, and strings. Swift value-types are copied immediately.
https://docs.swift.org/swift-book/documentation/the-swift-pr...
If you are developing with Swift but not using a Mac at all, I would love to hear how your experience has been.
My only beef is that the binaries are quite large. I’m hoping the new Foundation will improve things, in the interim I’m trying to eliminate my Foundation dependencies.
Zig and Swift do it and I feel like it makes things harder to read, not easier.
`.variant` vs `Type::Variant`
IIRC the syntax is optional (you can include the type name) but it seems obvious that in any sufficiently long or complex code, not having the type name close would be annoying, especially if you didn’t have IDE like capabilities in your editor.
However outside very specific use cases, where no kind of automatic resource management is allowed, no matter what, like in high integrity computing, or critical kernel code, approaches that mix and match both solutions are much more ergonomic.
Swift isn't the only one going down this route, we see it as well in D, Chapel, Linear Haskell, OCamml Effects, Mojo, Hylo, Koka, Veronica, and probably many other research languages being born during the last 5 years.
Because in the end, programming language ergonomics and expressiveness really matters for wide scale adoption.
I would happily have something 50-100% slower than C++/Rust with good interop, alas there seems to be very little / nothing. Cython for various reasons isn't ideal.
Using an browser set to autodirect to https by default, all I get is some huge warning because the host use a certificate for svbtle, the service used to host this blog.
I know some people think that because some blogpost is public it can be served without ssl, but I think it is still nice to leave the choice of the reader to disclose or not to his provider and everyone in between what he is reading or not without seeing horrible warnings.
this works:
enum TreeNode<T> {
Leaf(T),
Branch(Vec<TreeNode<T>>),
}
https://play.rust-lang.org/?version=stable&mode=debug&editio...otherwise if it was just tuple of `TreeNode` there would be E0072 https://doc.rust-lang.org/stable/error_codes/E0072.html
Not quite right:
It sounds kind of intriguing but I know very little about the language.
Rust is currently the defactor choice if you want to make something with js/python bindings, of id you want to speed up a dynamic bottleneck because it makes it super easy.
Swift doesn't even have a good ffi.
(Yes, there's arguments that untyped throws are better for library code because it leaves you more room to add more errors as you become aware of the need for them without breaking the contract with your users, but really, client code is going to be written to the errors you're throwing anyway (i.e. Hyrum's Law). I much prefer my errors to be typed so that if an error is added, the library version has to be bumped to indicate the new incompatibility with old code. And for my own, non-library code, typed errors make sure I'm handling all the error cases.)
So no, Swift is not a "more convenient Rust". It is not Rust at all. It is more of a variant of C#/Java. And I haven't seen any indication that it is an improvement over either. The only reason to use Swift is having to deal with Apple.
I've been using Swift a long time and don't quite get what this is referring to.
Also:
> Swift too gives you complete type-safety without a garbage collector.
Type-safety and memory-safety are two entirely different things; this is an odd sentence.
Related
I Hope Rust Does Not Oxidize Everything
The author expresses concerns about Rust's widespread adoption in programming, citing issues with syntax, async features, complexity, and long compile times. They advocate for language diversity to prevent monoculture, contrasting Rust with their language Yao.
Don't write Rust like it's Java
The author discusses transitioning from Java to Rust, highlighting Rust's type safety, differences in traits and interfaces, complexities of ownership, and the importance of embracing Rust's unique features for effective programming.
Language Compilation Speed (2021)
The article examines Rust's compilation speed compared to C/C++, noting frustrations among developers. It proposes a benchmarking method, revealing GCC compiles at 5,000 lines per second and Clang at 4,600.
From Julia to Rust
The article outlines the author's transition from Julia to Rust, highlighting Rust's memory safety features, design philosophies, and providing resources for learning, while comparing code examples to illustrate syntax differences.
Rust's Ugly Syntax (2023)
The blog post addresses complaints about Rust's syntax, attributing them to misunderstandings of its semantics. It suggests simplifying semantics for readability while maintaining performance and safety features.