4 ms·
This is really fantastic to get an understanding of how Rust works in a real world environment. As a non-systems developer I am finding the Rust language to be
by threeseed 11y ago
This is really fantastic to get an understanding of how Rust works in a real world environment. As a non-systems developer I am finding the Rust language to be a little cryptic though in particular the many new syntax elements that don't exist in other languages.
I would be curious to know if there are plans like Swift to simplify the language syntax in the future or if it is just something to get used to.
- steveklabnik 11y agoIt depends on what you mean by "simplify". We've just accepted an RFC for ?, for example, which should make certain code more concise, but it is an additional feature, so is that more simple?
- quickben 11y agoGeneral notes: - Semicolons inconsistent usage makes Rust harder to process. Is that semicolon extra? Is it not? Will that be a compilation error? Saving single keystrokes will be paid in cognitive load. Programming is already a demanding task, this isn't helping. - Chaining multiple statements on a single line is bad for various reasons. Dependencies / headers / modules: - C++ is better precisely because it's more grained on the initialization side. The paragraph starting with 'Rust wins, here', is just a general turnoff to read the rest of the article. When I read the title 'Rust vs. C++: Fine-grained performance' I was honestly expecting either a table with performance times across various algorithms, or a savvy optimization guide. I wasn't expecting a LoC duke-it-out. Input file processing - Both are conceptually boilerplate code. There is more for Rust apparently. - There is an interesting &⊛env:: in there that makes the language looks like it needs a bit more work. Three operators just to do something with the first object? - Are they intentionally trying to copy C++ with the :: operator but removing visually arbitrary semicolons? Just replace the :: with something else. Data structure and input setup - Remove the 'let' from the language, and it does look cleaner than the C++. Input state machine - Why isn't "(0..7).rev()" "(7..0)" - On the bottom part, lamba-like usage will makes in less comprehensible (and probably undebuggable the way it's written) General lack of performance numbers - "I found that iterating over an array with (e.g.) “array.iter()” was much faster than with “&array”, although it should be the same..." "Curiously, changing scores to an array of 16-bit values slowed down (earlier versions of) the C++ program by quite a large amount – almost 10% in some tests – as the compiler yields to temptation and forces scores into an XMM register. The Rust program was also affected, but less so." Edit: Unicode
- steveklabnik 11y agoI didn't write this blog post, though I did help the author optimize their Rust code when they dropped by #rust, so I'll respond to the generic Rust stuff rather than those details. > Semicolons inconsistent usage You've asserted this, but not demonstrated it: semicolon usage is consistent in Rust. Rust is not C++, so it doesn't necessarily follow the same rules, but it is consistent, even though it may be different. > C++ is better precisely because it's more grained on the initialization side. Can you elaborate on this? I'm not exactly sure what you're saying. > There is an interesting &⊛env:: in there that makes the language > looks like it needs a bit more work. See above: this kind of thing is about how Rust views coercion and heap allocation: explicit, not implicit. > Just replace the :: with something else. We tried that. We still ended up with :: as a scope operator. > Remove the 'let' from the language, and it does look cleaner than the C++. `let` has a few advantages, in that it allows you to take advantage of patterns, and makes initialization explicit. > Why isn't "(0..7).rev()" "(7..0)" Because ranges always iterate forward, from start to end. rev() reverses the direction. > On the bottom part, lamba-like usage I'm not sure what you're referring to here.
- quickben 11y agoI get the feeling that Rust design is concerned more about write-ability of the code than readability. Code has to be maintained, read by random people, comprehended. It will grow up in hundreds of megs on large projects, and it will take time to compile. With the above in mind: > You've asserted this, but not demonstrated it: semicolon usage is consistent in Rust. Rust is not C++, so it doesn't necessarily follow the same rules, but it is consistent, even though it may be different. Writing code is consistent and unaffected, code comprehension (debugging, integration efforts, etc) by third parties will be hampered. >Can you elaborate on this? I'm not exactly sure what you're saying. Not importing the entire library will result in faster compilation. Unless rust has a concept similar to precompiled headers, etc. I apologize at this point. I'm not sure what Rust does in that respect, but my initial thoughts were that as the project grows, the parser will slow on includes. The internal symbol resolver will slow on lookups because too many things are included. All of the above is only if you are trying to match what C++ does for large teams. I guess it's up to the developers of the language what direction they want to take it in. More agile or more enterprise oriented. (From personal experience: I was on a team looong time ago, where codebase took 12 hours to compile on a powerful cluster. Any gains, even by few hours, changed schedules drastically) >See above: this kind of thing is about how Rust views coercion and heap allocation: explicit, not implicit. I understand your viewpoint, however three operators on a single object still seems conceptually excessive to me. >Because ranges always iterate forward, from start to end. rev() reverses the direction. Since both are supported, maybe the parser can be made smarter? > I'm not sure what you're referring to here. Well this piece of code: let scores = words.iter() .filter(|&word| word & !seven == 0) .fold([counts[count];7], |mut scores, &word| { for place in 0..7 { scores[place] += (word >> bits[place]) & 1; } scores }); Is not easily read or debugged ( on which line do you set the breakpoint, etc). Outside of minor things like this, I like what Rust is trying to do. I think it's a great effort and I do look forward to where it will lead.