4 ms·
Congratulations to the team; it is nice to be around when a language is born. I remember when Ruby was born, and most people (that I knew) were like "Huh? Why R
by discardorama 11y ago
Congratulations to the team; it is nice to be around when a language is born. I remember when Ruby was born, and most people (that I knew) were like "Huh? Why Ruby, when we have Perl?".
I haven't followed Rust much, but as a total n00b: what are some practical reasons why one would choose to learn Rust? What features does this language have which others (pick: C, C++, D, etc.) don't have? What does it do better than the aforementioned languages? (Please don't take these as a challenge, but as a desire to learn more). Thanks!
- steveklabnik 11y ago> What features does this language have which others (pick: C, C++, D, etc.) The shortest answer is 'memory safety without garbage collection.' C and C++ don't have 1, D doesn't have 2. D is working on 2, but then it won't have 1. Secondary reasons: newer, better, more standard tooling, (in some cases, not others: IDE support, not nearly as good. Build system and sharing code? Way better.) Similar concepts in a more orthogonal package. Lack of legacy baggage. Easier (hopefully) for non-systems programmers to get into, as the compiler is there to help. It really depends. Reasons those languages are better than Rust: adoption, ubiquity, more tutorials and a bigger community.
- nercury 11y agoThe introduction in book (linked in announcement) actually explains exactly this, very nicely. It sounds like this: Rust is a systems programming language focused on three goals: safety, speed, and concurrency. It maintains these goals without having a garbage collector, making it a useful language for a number of use cases other languages aren’t good at: embedding in other languages, programs with specific space and time requirements, and writing low-level code, like device drivers and operating systems. It improves on current languages targeting this space by having a number of compile-time safety checks that produce no runtime overhead, while eliminating all data races. Rust also aims to achieve ‘zero-cost abstractions’ even though some of these abstractions feel like those of a high-level language. Even then, Rust still allows precise control like a low-level language would.
- Veedrac 11y agoRust manages to fight neck-to-neck with C++ on speed and runtime overhead ("fast" and "effectively none") whilst giving both safety and some really nicely made abstractions. The one everyone mentions is that Rust gets memory safety without garbage collection. But there are cooler things, like being able to implement units in the type system. Rust also gets safety right in the sense that its defaults are good - its primary random number library has ChaChaRng and IsaacRng instead of a Mersenne Twister, for example. The sensible library design goes everywhere, from Rust's functional roots, high-quality zero-overhead iteration protocol (none of the mess that C++ gives you) to simple things like a well-designed composable hashing standard. Even stuff like comparing C++'s move, copy and constructor semantics are much nicer in Rust, and in most cases even lower overhead: everything is a memcpy and is implemented automatically. I can go on. Rust is one of the few languages that IMHO gets string handling right, and has good unicode support from the outset. It's easier to write error-proof filesystem code than any other language I've used. Threading isn't a mess. There are disadvantages, such as Rust being one of the hardest languages to learn. Generics are both pervasive and difficult - they're clean unlike in C++ but they're also uncomfortably explicit. There are lots of nonlocal typesystem effects, largely due to the thirst for safety. But it's a good language. Definitely one of the most exciting I've seen in a while.
- ewillbefull 11y ago> Generics are both pervasive and difficult - they're clean unlike in C++ but they're also uncomfortably explicit. Maybe it's because I'm used to it, but do you have an example of why you think this? I think with type inference being pervasive, I've never been annoyed by generics. Additionally with type aliases a lot of pain can be avoided. One of the ugly parts is that call-site type parameters, when given explicitly, have an ugly (but consistent) syntax. This is probably unfixable. Another annoying part is the lack of anonymous return types, which makes some types annoying to read or even impossible to express, but work is being done to improve this now.
- Veedrac 11y agoYour second paragraph basically lists the difficulties. It's definitely a compromise.
- ewillbefull 11y agoAside from many of the other common reasons, Rust is a fun language to code in (once you understand it well). The language design has learned a lot from other languages, and the tooling has been influenced by many other successful ecosystems (npm as a big example) and trendy workflows (the community seems a bit centered around github, which works for me). A few examples just off the top of my head: the language doesn't hide performance tradeoffs, namespacing makes sense, "zero-cost abstractions" are beautiful and common through the ecosystem, cargo is a wonderful tool for building, creating docs, testing, etc. I've had a lot of fun using Rust to build things I really didn't need it for.