4 ms·
Here's my perception of Rust: It is a system's low level language (more like C or C++) that is very expressive. It's performance is compared to C++, so faster t
by sargas 10y ago
Here's my perception of Rust: It is a system's low level language (more like C or C++) that is very expressive. It's performance is compared to C++, so faster than Go/Python/Java.
----------------------------------------
In term of expressiveness, it offers:
- Expression-based languages (instead of statement-based)
- Has anonymous functions (lambdas)
- It has a match mechanism which is powerful
- Enums are enumerated data-types rather then integer types
- Has traits and explicit implementation blocks for them (vs Go's implicit interface contracts)
----------------------------------------
Other than that, it also offers:
- Built-in concurrency
- It has a thing called the borrow checker that makes sure you're handling memory safely (this will get a little but of getting used to, but it is powerful)
- Everything is private by default. You put `pub` in front of an identifier if you want it to be public
- It isn't very verbose in the Java sense, but you still have to write a crap lot of code in comparison to Go and Python. The trade off is that the code is very explicit, and you get to type more in order to have zero cost abstractions at runtime
- Zero cost abstraction at runtime
Please correct me if any of those points are wrong/misleading, I'd love to learn more about Rust too.
- bbatha 10y ago> - Built-in concurrency This is a bit misleading, rust does not come with concurrency out of the box. The compiler is able to infer some basic properties of your program to ensure that it is 'concurrency safe'[1] any additional concurrency features are offered through libraries that mostly wrap C libraries. The std lib only comes with system threads, and some basic primitives like mutexes and channels. However, because of these features its fairly easy to build libraries that offer concurrency primitives. For example, `mio`[2] can be used for async socket programming, `rayon`[3] can be used for some parallel computation. [1] http://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.html http://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.ht... [2] https://crates.io/crates/mio https://crates.io/crates/mio [3] https://crates.io/crates/rayon https://crates.io/crates/rayon
- sargas 10y agoThanks for the explanation. Would you please clarify something to me? 1. So to say that a language has concurrency built-in is, in general, misleading, correct? 2. Than a language may have concurrency primitives, but the capability comes from C through the OS?
- steveklabnik 10y agoIt's more like "We designed the type system to take concurrency into account, and then provided various types ourselves in the standard library (like Send/Sync) to be used with them. We also provide a bunch of concurrency abstractions and tools, in the standard library, but due to the guarantees being more in the type system, others can also write their own. Some of these do rely on OS-level capabilities as well. In general, very little of Rust is technically "in the language", but to the user, something in the standard library vs the language itself often doesn't matter, it's the same experience either way.
- sargas 10y agoThat's very insightful. So my understanding now it that Rust provides low level "blocks" that, as a whole, is an extensible language. Thus language vs standard library doesn't really matter, since Rust = Language spec + standard library. Am I getting close to its definition? BTW, I remember in the alpha days when the decision was made to make Rust support concurrency in the standard library rather in the language itself. So in that sense (Rust = language spec + stdlib) Rust does have concurrency built-in.
- steveklabnik 10y agoWell, using Rust without the standard library is a big use-case: stuff like device drivers, OSes, embedded, things like that. So to some users, it matters. But there's little use overly qualifying what you're talking about when you're just talking, so someone might say "Rust" to mean "Rust + std + crates.io crates" or "Just the language, no standard library", based on context. But once you get into the details, it's important to get at exactly what you mean.