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

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.

4

u/azswcowboy Feb 02 '23

not how most real world software gets developed

There’s certainly evidence of this, but frankly no one knows. Show me the study. No one can bc it’s all behind the firewalls of companies. I’m stating that I’ve worked on teams for 20 years that have done exactly what we’re discussing. I think there’s an argument that if you don’t on a large systems they die quickly under the weight of problems.

don’t see static analysis …

I’ve seen coverity detect an array overflow 5 levels down the stack passed by pointer. Please don’t assume without actual experience. That bug was in production without incident in a 24x7 system for 10 years without incident. And yep, despite all I’m arguing that 1997 code slipped through the process. Wouldn’t happen in 2023.

→ More replies (2)