4 ms·
I like how C++ gets the verbose template parameter name of RandomAccessIterator (repeated 3 times), while Rust gets T. It's sort of like he's saying, "if you c
by xedrac 4y ago
I like how C++ gets the verbose template parameter name of RandomAccessIterator (repeated 3 times), while Rust gets T. It's sort of like he's saying, "if you choose to use C++, this is the sort of muck you'll have to deal with." He's not wrong, it's just funny.
- veilrap 4y agoThe C++ code could have also just have been `T`. It's a bit odd of a comparison because `RandomAccessIterator` is just a name the author chose for the template typename.
- zerocrates 4y agoI think that's what the person you responded to was saying actually, that the author specifically chose a verbose template parameter for the C++ examples.
- ncmncm 4y agoThat author missed the significance of a detail that illustrates a major difference in the expressive power of C++ vs. Rust.
- tialaramex 4y agoYou've confused RandomAccessIterator (a perfectly reasonable name for a Rust trait, but not really in the usual style of the C++ standard library) for std::random_access_iterator an actual concept defined in C++ 20 std::random_access_iterator like most of its fellows in C++ 20 is largely duck typed, there's a semantic "model" provided, but this is not enforced anywhere and your compiler will actually accept completely bogus types so long as the syntax matches. The standard washes its hands of the consequences by saying that if you don't obey the model your program is not valid C++ and the compiler is not expected to detect that and tell you about it.
- ncmncm 4y agoNo, on both counts. No, I did not confuse it, but chose not to quibble over spelling. And, no, C++ concepts are not limited to "duck typing".
- ncmncm 4y agoAs of C++20, with "Concepts", that name is not just a placeholder. It means something that enables the compiler to do work for you that Rust cannot. The most trivial of that work is to check that the type provided implements a comparison operator, which mostly affects error messages if you pass a type without, but you can use it to make types pick up a great deal more reponsibility. It is not often mentioned on HN that whole swathes of functionality modern C++ coding relies on are entirely missing from Rust. Clearly, people can get along without powerful features -- important programs are coded even in C -- but it is a great deal more work. One consequence is that C++ and, to a degree, Rust programs are faster than programs coded in weaker languages, simply because more time is available to pay attention to performance, and any such attention to a library may help many more programs. Weaker languages are simply unable to express usability improvements and optimizations you would like to capture in a library.
- oconnor663 4y ago> check that the type provided implements a comparison operator If I understand correctly, this is done with traits in Rust. In this case, the PartialOrd and Ord traits. More elaborate use cases for traits cover things like "is this type safe to send between threads" and "does this type have a statically known size on the stack".
- avgcorrection 4y agoPresumably they intended to say that the (1) cplusplus thing can express something that Rust cannot, and (2) here’s an example of Thing. But then they didn’t properly delineate the two things so that it might come off as if (2) is an argument for (1), but really (1) just talks about Thing in isolation and not as a comparison to Rust... The example was just a standalone example, unrelated to Rust.
- ncmncm 4y agoIf you read what it says, you will see that it says Rust has built-in the most trivial of the things that concepts are used to do, and cannot express the rest at all.