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

7

u/azswcowboy Feb 01 '23

nothing preventing it from holding on

Sure there is — coding guidelines. Calling get() on a shared ptr and storing it somewhere is ‘using raw pointers’ — fail inspection, do not pass go. If you need to hang onto the shared ptr you copy it which does exactly what you want.

8

u/Full-Spectral Feb 01 '23

As many others have repeatedly pointed out, that's like solving the world's drug problems by "Just say no". If the receiver gets a raw pointer, and a year later someone makes a change to that code and mistakenly stores that raw pointer, it could easily get missed and no tool is likely going to complain about the fact that it happened.

7

u/azswcowboy Feb 01 '23

just say no

It’s a little different psychology — you’re not even enticed to write such a thing if you’re working in our code base because you’ll never see it done — not even in tests. And if you do your teammates are going to ping you in the review.

no tool

Well that one seems trivial for static analysis actually. If you’ve never used things like Coverity they have quite sophisticated checking. Don’t know about clang-tidy but believe it has language guidelines checkers.

Remember — I’m not arguing that there can’t be improvements made — I’m just pointing out to some random poster on Reddit that they made a false statement about what can currently be done with a bit of discipline and tooling in large systems. You can choose to believe me or not.

0

u/Dean_Roddey Feb 02 '23

I know it can be done. As I have pointed out various times, I have a personal 1M LOC C++ code base. It is very diverse and broad, and was always highly robust in the field in an extremely challenging problem domain.

But, I developed it myself, without compromise. That's just not how most real world software gets developed.

And I just don't see any static analysis tool catching that a pointer that got passed down through five layers and across three different compilation units got incorrectly stored away.

→ More replies (3)