3 ms·
> Try and read a moderately complex Rust crate and it can be mind boggling to work out what is going on. I do that all the time, even reading the source of the
by dureuill 5y ago
> Try and read a moderately complex Rust crate and it can be mind boggling to work out what is going on.
I do that all the time, even reading the source of the std, something that I cannot do sanely in C++. IME Rust code is easy to read, with symbols that are always either defined in the current file, imported, or referred to by their full path.
- nu11ptr 5y agoAgreed, when I see comments like this I tend to think they haven't spent much time using the language. It takes a while, but after a month or so you can read just about any Rust code. Honestly, feels like a much simpler language in day to day usage than say a language like Scala (just an example) to me.
- oxymoron 5y agoI also agree with this sentiment, although there are some examples of really weird meta programming that remains opaque to me. For instance, I’m able to use `warp` as a framework, but the use of things like type level peano arithmetic is mostly incomprehensible to me at the moment. I also find that I run into Higher Rank Trait Bounds so rarely that I have a poor grasp of it (which might be as intended). All that to say that there are some odd corners of the language, given that I’ve been using it for five years now and as my main professional language for three years.
- tialaramex 5y agoTo be fair, the thing that makes a working C++ standard library unreadable is also a hazard in understanding Rust's std. Macros. The macros in a C++ standard library are horrible, because it is here that essential compliance and compatibility are squirreled away, and because the C++ macros aren't hygienic they're bigger than they'd otherwise need to be (e.g. you mustn't call it foo, say __x5_foo instead). But while they're far more readable on their own terms, the Rust macros littering std do mean it's harder to see how say, a trivial arithmetic Trait is implemented on u32 because a macro is implementing that trait for all integer types. A macro-pre-processed std might be easier for the non-expert rustacean to grok even though it isn't the canonical source. The symbol thing is pure insanity, machines have no problem knowing what symbol8164293 refers to, but humans can't get that right, and programming languages, including in theory C++ are intended for humans to write.
- khuey 5y agoThe thing that makes the C++ standard library source difficult to understand in my experience is heavy usage of templates and very deep inheritance chains.
- pcwalton 5y agoThe _Weird_identifier_naming_convention that the STL has to use to avoid colliding with potential user-defined macros doesn't help either.
- afdbcreid 5y agoRemember that expanding macros includes things like `println!()`. I'm not sure beginners will find the following particularly easy to read: { ::std::io::_print(::core::fmt::Arguments::new_v1( &["Hey ", "!\n"], &match (&name,) { _args => [::core::fmt::ArgumentV1::new( _args.0, ::core::fmt::Display::fmt, )], }, )); }; Although, to be honest, I don't think there are many usages of these macros in std.
- tialaramex 5y agoGood point. I hadn't considered panic!() in particular which is used in std, and the Debug implementations in std won't make a huge amount of extra sense after macro-pre-processing either.
- skrtskrt 5y agoMacros are extremely hard to grok and and so many use such short variable names that it looks like absolute gibberish. They also look so different than normal Rust code. Python metaprogramming still looks exactly like Python, for example.
- ReactiveJelly 5y agoOh yeah. I don't know if I've ever tried to implement a macro. The macro_rules syntax is hard to read and it doesn't feel like there are many examples explaining how it works.
- afdbcreid 5y agoThe Little Book of Rust Macros - https://veykril.github.io/tlborm/introduction.html https://veykril.github.io/tlborm/introduction.html.
- afdbcreid 5y agoMacro definitions can be hard to grok, but that's not usually what you look on. Macro uses can be hard, but macros are not used commonly in Rust (I mean, there are not many macros - but those that exist are very common). And they also look very much like Rust: `vec![a, b, c]` vs. `[a, b, c]`, `zip!(a, b, c)` (itertools) vs. `zip(a, b)` (`std::iter::zip()`), `#[tokio::main] async fn main() {}` vs `fn main() {}`... Attribute procedural macros only accept valid Rust syntax, and most of them are derive macros that just derive some trait.
- dagmx 5y agoAgreed. This was my first AOC, and I did every day in rust (except for one that I did by hand). Multiple times I'd go look at the source of a data structure and it reads very easily. I'd even share my code with friends and coworkers who weren't familiar with Rust (so we could compare..they were most familiar with Python). Not only could they easily grok my code, I showed them how docs.rs let's you easily see source. All of those that looked, could read it easily with some explanation from me on traits, pattern matching and generics. I think it's obviously a subjective thing...but I very much disagree with the author that idiomatic Rust is difficult to read or comprehend. In fact, I find Rust easier to grok, because I need to keep less in my head at any given time. Function bodies become almost self contained, without me having to think about lots of details like errors and return validity etc...
- root_axis 5y agoI love Rust, but e.g. macros, lifetimes, generic trait parameters etc are all very difficult to parse for the uninitiated. Of course, I'd bet on the readability of rust over cpp template wizardry any day of the week.