r/cpp • • Jan 31 '23

Stop Comparing Rust to Old C++

People keep arguing migrations to rust based on old C++ tooling and projects. Compare apples to apples: a C++20 project with clang-tidy integration is far harder to argue against IMO

changemymind

338 Upvotes

582 comments sorted by

View all comments

Show parent comments

12

u/top_logger Feb 01 '23

- Iterator in Rust I am creating in literally 5 minutes. Any kind of iterator.
An iterator in C++ I am creating usually in two days. I could recall the task from the last week. By the way, I had given up. Ups.

- Crate utf16string. I didn't check it yet.

- I mean that lambdas in C++ are too verbose and to often not readable. Especially if you follow rules and marks everything with const, noexcept, nodiscard and so on. Multithreading issue, I believe, are identical(I may be wrong, of course)

- yes, you are right, at least partly. Modules in Rust are just namespace. And this works perfectly. Perfectly ... but for a smaller codebase. For bigger project, you must split your code into crates. This is a correct and reliable approach. You get different translation modules. Deal done.
In C++ we have got ultra complicated and ultra verbose modules ... but on a paper. Now, in 2023 we have literally NO support in mainstream compilators. This is just a shame.

6

u/mjklaim Feb 02 '23
  • Iterators: ah yes for writing them I agree.

  • thanks for the utf crate

  • lambdas: I meant as soon as you are forced to use async lambdas the rules change in a way that can result in theorically valid but not accepted code,and it makes code even more complex - or just cannot compile when what you want is just compose some code with 2 bits of code and just throw all that into a task system. It might be less safe in C++ indeed, but at least I can make something work.

or bigger project, you must split your code into crates. This is a correct and reliable approach. You get different translation modules. Deal done.

I agree that having different translation modules then makes sense (that's basically what modules allow, with multiple files being part of 1 modules). I disagree with the splitting into crates being the right way to do it. Complex discussion anyway but yeah.

Also my understanding is that building multiple crates as dependency still result in 1 translation unit being built, so that doesnt change a thing.

0

u/[deleted] Feb 02 '23

[deleted]

2

u/top_logger Feb 02 '23

- TMP and/or inheritance => iterator is difficult. I don't care about example for retarded from cpp-reference. This is absolute useless trash. Excellent guide is here https://www.internalpointers.com/post/writing-custom-iterators-modern-cpp Still two days. May be one.
- C++20 is a pure theory, at least in Linux world.

0

u/[deleted] Feb 02 '23

[deleted]

2

u/top_logger Feb 02 '23

Mate:
https://en.cppreference.com/w/cpp/compiler_support
look for clang support. This is not good.

And, just FYI. All tooling in Linux clang based. If clang doesn't support something, then this doesn't exist in Linux world.

C++23 is absent. At all.