5 ms·
> Temporal memory safety and data race safety. [...] Unique to rust. [...] add a significant amount of complexity to the language. Rust seems to be a very comp
by pansa2 6y ago
> Temporal memory safety and data race safety. [...] Unique to rust. [...] add a significant amount of complexity to the language.
Rust seems to be a very complex language. Is all that complexity essential to providing memory safety without GC? Or would it be possible to have a significantly simpler language that is equally safe? A language that’s “safe & C-like” compared to Rust’s “safe & C++-like”?
- EwanToo 6y agoYou can write very simple Rust, it's worth trying it out if you haven't already. I'm not a rust developer, but I've ported over a handful of python or golang projects to see how it works. I managed to write the code without understanding much about things like the borrow checker. I'm certain my code is not as performant or elegant as it could be using some of the more complex tools and concepts in the language, but it is possible.
- adrianN 6y ago"You can write <adjective> <programming language>" is an answer that usually get rebutted by pointing out that a) you need to read a lot more code than you write and b) other people might not write <adjective> code or c) other people might have a different definition of <adjective>.
- genuine_smiles 6y agoThis is true. It’s also true that team using languages with more feature then they need can just take the parts that they need. It’s not quite as ideal as having a language that’s perfectly suited to your use cases, but it works well enough. For example, I’ve been writing JavaScript for 3+ years. I have yet to use the prototype chain directly, only through the use of the `class` keyword, and I’ve only reviewed code using it once. I hear C++ is similar in that teams use a slice of the available language features.
- pansa2 6y ago> I'm certain my code is not as performant If you don’t need maximum-possible performance, though, why use Rust/C/C++ at all? Wouldn’t a better choice be Go/Java/C#?
- GrayShade 6y agoBecause even slow Rust code might have better performance or memory usage characteristics than idiomatic code in these languages. Or because it still protects you from race conditions. Or because you like cargo more than, say, maven. Or because you want to learn the language.
- hu3 6y agoI was recently surprised that idiomatic Go can be faster than idiomatic Rust: https://news.ycombinator.com/item?id=26463967 https://news.ycombinator.com/item?id=26463967
- GrayShade 6y agoI haven't read that article yet, but I wouldn't really call the simple Rust version idiomatic. Stdin::lines() incurs a string allocation for each line (fixing this takes three lines of source code), which can be quite significant. And garbage-collected languages will have faster allocation, so I'm not too surprised. Of course, I know who the author of that code is. I just wanted to point out that it's not such a trivial comparison to make.
- littlestymaar 6y agoRe-usability is a important feature: if you write a Rust library you can reuse it from most runtime-based language with “native modules” (or whatever they are called in the said language), exactly like a C library.
- edflsafoiewq 6y agoJava and C# typically require a VM, and not everyone thinks Go is "easier to write" than Rust.
- IshKebab 6y ago> You can write very simple Rust Technically true, but only really true if you don't use many dependencies. At some point you're going to use some dependency that uses async/await all over the place or really goes wild with generics and then it is definitely not simple. Two examples: * Heim (https://docs.rs/heim/0.0.11/heim/ https://docs.rs/heim/0.0.11/heim/) is a great crate for getting system info, but it only uses async/await so you are thrown into that rather painful world even if you don't need it. * Plotters (https://github.com/38/plotters https://github.com/38/plotters) is a pretty great graph plotting library for Rust (the only one as far as I know), but they have definitely gone a bit overboard with the generics. Want to draw a scatter graph? I tried simply calling `PointSeries::new()` and got a basically impossible-to-follow error about Rust not being able to infer the type `E` here: https://github.com/38/plotters/blob/master/src/series/point_series.rs#L24 https://github.com/38/plotters/blob/master/src/series/point_... Very simple it is not!
- moltonel3x 6y agoasync/await doesn't have to be painful: Slap a `#[tokio::main]` in front of your `main()` and a `.await` after your heim functions. Done.
- IshKebab 6y agoIn the most perfect of perfect situations that's all you need. In reality it isn't nearly as simple as that. There's been a lot of discussion about the pitfalls of async Rust recently, highlighting the issues. Here's a good one: https://tomaka.medium.com/a-look-back-at-asynchronous-rust-d54d63934a1c https://tomaka.medium.com/a-look-back-at-asynchronous-rust-d...
- Measter 6y agoWell now I'm (morbidly?) curious what your Rust code looks like.
- ivanbakel 6y ago>Rust seems to be a very complex language. Is all that complexity essential to providing memory safety without GC? The language features specific to memory safety i.e. the borrow checker, are essentially irreducible. It is also Rust's biggest piece of complexity, and the one that is hardest to learn. There is no simpler language inside Rust that has the same safety guarantees, unless you strip out other useful features (traits, async, etc.).
- pansa2 6y ago> There is no simpler language inside Rust that has the same safety guarantees, unless you strip out other useful features (traits, async, etc.). This sounds like “there is no simpler language inside C++, unless you strip out useful features (classes, templates, etc.)”. Yet C exists. So there could be a simpler language with Rust’s safety guarantees if you were willing to strip out traits, async etc?
- deleted 6y ago[deleted]
- ivanbakel 6y ago>So there could be a simpler language with Rust’s safety guarantees if you were willing to strip out traits, async etc? Well yes, there exists a hypothetical C + borrow-checker language. But that language wouldn't really be significantly simpler, because the borrow-checker is the largest contributor to Rust's complexity. The only things you would have taken away are the more well-understood features, as they already occur in other languages. The C/C++ comparison doesn't really work, because there is (to my knowledge) no single C++ feature which makes up the majority of its complexity over C. You could strip out independent features of C++ one at a time to return to a simpler language. Rust doesn't have the same property.
- dgellow 6y ago> there is (to my knowledge) no single C++ feature which makes up the majority of its complexity over C Maybe template programming?
- pjmlp 6y agoObject Pascal and Modula-2 would be already much safer than plain C, although you still suffer from use-after-free errors. Then there is Ada, but it is in the same complexity level as C++, although much easier than Rust.
- moltonel3x 6y agoI don't have enough Ada experience to compare, but Rust is IMHO much easier and less complex than C++. Rust is renowned to have a steep initial learning curve, but that curve doesn't climb nearly as high as C++'s.