4 ms·
> Rust is relatively easy to read I think. I write C++, Kotlin and Go code day to day, and I respectfully disagree. the syntax is incredibly terse. Most rust c
by maccard 4y ago
> Rust is relatively easy to read I think.
I write C++, Kotlin and Go code day to day, and I respectfully disagree. the syntax is incredibly terse. Most rust code I've encountered sprinkles macros with functions, which have slightly different semantics (note this is not an indictment of C or C++'s macros, far from it), and the combination of macros, pattern matching and unwrap lead to code like [0], which frankly I find incredibly difficult to work with.
> Rust eradicates whole classes of errors in safe code, and unsafe code is more safe than the equivalent C or C++.
Completely agree here, and nopt only does it do that it does so _without sacrificing performance_ in many cases.
[0] https://github.com/mozilla/sccache/blob/main/src/compiler/gcc.rs#L275 https://github.com/mozilla/sccache/blob/main/src/compiler/gc...
- nu11ptr 4y agoI suspect the style and library code used matters greatly. Said differently, the constructs that Rust has make it _possible_ IMO to write code that is easier to read than equivalent C. Obviously even this depends, as the simplest use case will look very simple in C, but the most complex use case it is possible to write cleaner looking code in Rust due to he inclusion of higher level constructs that C simply does not have, so it typically resorts to hiding this via macros.
- maccard 4y agoI've only interacted with a small amount of rust code over the last 3-4 years, but it's all been a similar style to the above. I'd love to be proven wrong with any examples of well written understandable rust code though!
- johnisgood 4y agoWhat even is "if let ..." in Rust? What is the purpose of it? need_explicit_dep_target = true; if let DepArgumentRequirePath::NotNeeded = need_explicit_dep_argument_path { need_explicit_dep_argument_path = DepArgumentRequirePath::Missing; } I am currently trying to translate "simple" Rust code to C but I am having difficulties. https://github.com/RustCrypto/formats/blob/master/base32ct/src/alphabet.rs#L43 https://github.com/RustCrypto/formats/blob/master/base32ct/s... Where is `threshold` and `offset` coming from? How come running `cargo test` in directory `base32ct` actually tests nothing (I get 0 everywhere) despite there being some test code? Messed up `Cargo.toml` file? sighs Lots of mysteries in Rust, at least for me.
- nu11ptr 4y agoThe purpose is to enter the if block if and only if the pattern is matched. In your example, if "need_explicit_dep_argument_path" matches enum "DepArgumentRequirePath::NotNeeded" the if block will be entered (else it will be skipped). This is a bit of an atypical example as there are no bindings in the pattern match, but most times there are, and they are then scoped within the if block. For example: let my_option = Some("test"); if let Some(my_str) = my_option { println!("I matched this string: {my_str}"); }