cargo new hello
cd hello
cargo run
It just works!
cargo new hello
cd hello
cargo run
It just works!
I just had a revelation as to why I love Rust so much:
In the context of parametric polymorphism, I (1) agree that Rust > C++, (2) don't know enough about Swift to comment, and (3) am curious to hear your arguments on Rust > Haskell.
One thing I like about Rust is that it filters out lazy/sloppy thinkers. Even when I disagree with another Rust programmer, there is a certain level of respect that comes from knowing that they thought about the problem deeply enough to pass the borrow checker.
As to (3), Haskell's typeclass system is incoherent in the technical sense, i.e. you can end up with multiple implementations of a given typeclass for the same type, which is confusing.
However, there's an even worse kind of annoyance, which has bitten me far more frequently than incoherence: working with associated types is more cumbersome, because type definitions and typeclass impls with associated types that compile in Rust often simply do not compile in Haskell. Not to mention the requirement for several non-standard language extensions in order to perform seemingly simple tasks.
Regarding Swift, I simply feel that its protocol system is just weaker and has less features than Rust's traits, especially when it comes to expressing constraints. As a result, type-level metaprogramming is harder, or one can only provide fewer and weaker guarantees around not misusing a typed API.
And also in general very welcoming and active community, which makes picking up a new language less painful
Zero-cost abstractions
High-performance Async/Await with complete stacktraces
Immutable and Private by default
And the list goes on and on
Oh, yes, "private by default" is great especially when wrapping unsafe
abstractions, or when writing abstractions with unsafe
that relies on invariants being upheld. Public-by-default would make that a soundness nightmare. "Did I forget a private
somewhere?"
There's so much to love that it's hard to put into a sentence or two. Really compressing it down, it's these:
The likelyhood is that once you get your code to compile, it will work.
The compiler catches so many of the mistakes I would generally make - in fact if using rust-analyzer with a suitable IDE you will see the mistakes as you code.
That makes updating and refactoring code a breeze.
Make you feel at ease when you are writing code.
The superior memory safety afforded and resulting reduction in service-interrupting bugs makes Rust ideal for both disk scheduling and destination dispatch programs.
(Even if in some ways you have to wait a little longer.)
One (or two?) more "ahah" moment: HashMap
.
entry
is something I've never seen before. Java's collections have some "combination" methods like computeIfAbsent
, C++ has nothing. entry
just rocks.One more thing that's good about that is hashing performance, as well as hashing "correctness" w.r.t combining hashes in a way that doesn't accidentally lose entropy: the object or its fields don't all have to produce a complete hash individually and initialize a new hashing state each time for that; they can just share one state instead.
Same here – AFAIK it was supposed to be a solution to some borrowck limitations, but it turned out to be immensely useful even when traditional control flow would pass borrowck.
Doing an elevator pitch is tricky because there are so many good things to mention. It's definitely contingent on the audience though.
I did one at work intended to generate interest in Rust for mostly Java and C# developers by showing zero cost abstractions for iterators: the lack of these in C# and Java can be super surprising.
If you're curious, the video is here: Rust: Zero Cost Abstractions - YouTube -- I filled it out a bit with some SIMD goodies when I presented it again for the Rust Dublin meetup. Somehow it got picked up by Coding Tech and seems to be a lot more popular than I would have imagined. And more admin/pain than expected too, due to some of the usual trolling in the comments.
Anyway, at work, I did a few follow up sessions for those interested. Some our devs use Scala and have experience with Haskell, so they really "get" the ADTs, option/result, strong type system, etc. They're quite keen on the derive
macros too, especially for serde.
Interest faded a bit because I got really snowed in with some major deadlines, so I need to figure out what to do next: maybe we'll try building something small. I'm not exactly sure what though - I don't want to throw people in the deep end with async
challenges immediately.
My elevator pitch has always been: (safe) Rust obsoletes dangling pointers, memory leaks, and race conditions, and furthermore, its steep learning curve highly rewards the persistent learner by promoting efficient software architectures. Your company no longer has to worry about random software crashes at 2AM on a sunday because of a memory leak.
Some other thoughts: unlike other languages, Rust forces the programmer to consider the lifetime of variables, meaning that unlike Go/Java, passing a reference to a function doesn't automatically heap-allocate the pointee (even if unnecessary), meaning you get WAY better performance in rust.
Having to go back to java/Go/Dart after spending time in Rust is a bit depressing seeing how much unnecessary heap allocation goes on under the hood. If only those language forced their users to consider the lifetime of variables, lazily heap allocating everything wouldn't be necessary
I’m curious and not wasn’t aware of this. Could you provide an example?
Also as to the type classes vs Rust’s traits comparison, IMO there’s still significant shortcomings around the fact that you can’t have type constructor classes (I don’t know what’s the right term, I’m talking about type classes with kind (Type -> Type) -> Constraint
, type classes such as Functor, Applicative, Monad, Foldable, Traversable, etc).
If Rust supports this at some point in the future we can probably call it more strictly superior. I do like the coherence story in Rust a lot.
Ain't them Higher Kinded Types?
Fair enough, I'll try to dig out the project I last implemented in both languages; unfortunately, it was about half a year ago so I don't remember the specifics off the top of my head.