3 ms·
The Rust code is very non-idiomatic, which is probably part of the reason why it seemed difficult to put together and why reading it is a bit of a chore. Compar
by kidfrommars 6y ago
The Rust code is very non-idiomatic, which is probably part of the reason why it seemed difficult to put together and why reading it is a bit of a chore. Compared to Zig or Go, naively translating C code into Rust isn't going to work nearly as well. This isn't necessarily because Rust is more complicated (although it definitely is) but has a lot to do with the fact that it's semantics are inspired almost as much by OCaml and Haskell as they are by C and C++. It's not surprising, then, that someone who is predominately a C programmer would need more than a couple hours to be able to really judge the difference between the languages.
- edflsafoiewq 6y agoThe Rust looks fine to me.
- seoaeu 6y agoNothing looks necessarily wrong to me but there are some elements that aren't exactly how this code would normally be written. Like that they don't take advantage of Iterator::enumerate() which makes the the for loop more awkward than necessary. Or how strings are treated as arrays of bytes (rather than sequences of unicode characters as the language pressures you to).
- steveklabnik 6y agoYeah. This code isn’t bad, but it’s not what I’d write. The largest difference is that, if given this problem, I would start with walkdir (and maybe glob), rather than trying to write all of this myself. Not to mention Cargo instead of a Makefile. The loops also feel very C-like, but that might still be the best you can do. I'd have to actually give it a try, but I feel like iterators could clean this up, as you say. To reiterate: that doesn’t mean this is bad or wrong. It might be a bit harder or more complex than it has to be. But also, you have to know that these things exist in the first place, which is it’s own challenge. EDIT: Oh look, someone on lobsters thought the same: https://lobste.rs/s/ndxi2r/better_c_benchmark#c_k2kwjs https://lobste.rs/s/ndxi2r/better_c_benchmark#c_k2kwjs https://github.com/jswrenn/treescan/blob/main/src/main.rs https://github.com/jswrenn/treescan/blob/main/src/main.rs
- ovis 6y agoHow would you structure it (in broad strokes)?
- sundarurfriend 6y agoHonestly I don't understand the complaints about the readability of this Rust code. I'm new to all three languages here, and I find it pretty readable. Maybe it was harder to write in Rust, I don't know, but in terms of readability the Zig and Rust code look pretty similar, and Go is the one that stands out as somewhat hard to parse and understand.