4 ms·
Rust is significantly more complex than C and more complex than C++. It seems to be a multi-paradigm language like C++. I guess it's advertised for system prog
by blub 10y ago
Rust is significantly more complex than C and more complex than C++.
It seems to be a multi-paradigm language like C++. I guess it's advertised for system programming because it's looking for its niche, but I don't see it replacing C for low level stuff due to the learning curve.
- nercury 10y agoI guess Rust may seem more complex, if you know C++ well, but from the side it may not seem like it. For example, C++ Core Guidelines [0] is longer than Rust Book. Core Guidelines is itself a great example of things one needs to keep in the head while writing C++ code. Look at implementation of something as basic as optional<T> [1]. The amount of things one needs to know is so high most C++ developers would never attempt it. [0]: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md https://github.com/isocpp/CppCoreGuidelines/blob/master/CppC... [1]: https://github.com/akrzemi1/Optional/blob/master/optional.hpp https://github.com/akrzemi1/Optional/blob/master/optional.hp...
- girvo 10y agoWhich is interesting, because I implemented Optional<T> (well, Maybe<T>) in Nim v0.14 in 20 lines of code in a single evening, to see how difficult it would be!
- gpderetta 10y agoThe reason for the complexity of that implementation are compiler bugs/nonconfromance workarounds, a fully constexpr implementation and attempt to match a standard spec.
- girvo 10y ago> a fully constexpr implementation That's actually simpler to do in Nim than you'd think, but I understand what you mean. I might expand my implementation to be const and see how complex it makes it!
- soulbadguy 10y agoUsing the size difference between the C++ code Guidelines and the Rust Book as measure of relative complexity seems misguided to me : Those two very different document, with very different purpose and target audience.
- steveklabnik 10y agoHow do you measure complexity?
- blub 10y agoI measured it by looking at posted Rust code/projects on HN an relating that to what I know about C and C++.
- steveklabnik 10y agoThat doesn't say _how_ you measure it when you look at the code.
- dbaupp 10y agoI feel like this is taking a very rosy-eyed view of C++. C++ has a massive amount of accidental complexity. To mention just two: the difference between () and {} initialisation (for some types) especially in the presence of perfect forwarding, and a set of feature/their interactions that means there's a bug in the following very reasonable looking code (can you find it?): std::unordered_map<T, U> map; // ... initialize map ... const U *selected = nullptr; for (const std::pair<T, U>& p : map) { if (condition) { selected = &p.second; } } // use selected (Credit to Effective Modern C++.) Rust may seem more complex because the compiler is noisier, but it is significantly simpler to write correctly: a computer is finding the weirdest bugs.
- soulbadguy 10y agoWhat's the bug ? (hopefully it's not just a missing break statement.
- RcouF1uZ4gsC 10y agoThe problem is that the pair in the for loop should have a const T as the first parameter. Because it does not have that, you are actually getting a temporary back and storing a pointer to a temporary in selected. The fix to avoid this is to use auto. If instead of pair, you used auto&& p: map, this would not be an issue
- blub 10y agoThat's not the point I am making. I am arguing that it's more difficult to go from idea to code in Rust because there are more programming concepts that one has to keep in mind. Additionally, the syntax is not user friendly. You are right regarding the C++ accidental complexity though. Issues like the one you highlighted tend to happen when working with pointers. They are very hard to detect during code review (I didn't see it), but I would have rejected the code at review anyway because it should be replaced by std::find. Taking raw pointers into containers is also not reasonable except for vector.
- dbaupp 10y ago