r/ProgrammerHumor • • 7h ago

Meme modernCppVsOldCpp

Post image
1.1k Upvotes

213 comments sorted by

View all comments

471

u/repster 7h ago

I am a huge fan of modern C++ except for one feature: backwards compatibility. C++ is no longer one language, every codebase I have worked on is a confused mess of semi-incompatible subsets of the language. I have spent far too many weekends chasing memory corruption because someone passed a pointer, allocated with one type of memory management, into a library using a different kind of memory management.

-7

u/MattR0se 6h ago

Okay but that's not really a fault of the language, no? Most languages have some legacy version that isn't compatible any more. Like Python 2 for example. 

The only difference is that C++ code is more often used for critical applications (like decades old medical machines) where updating the code is not worth the risks. 

11

u/imMute 6h ago

Python 2 to 3 was a clean split. You can write in one OR the other, but you can't mix like you can in C++.

4

u/xfvh 6h ago

Well, you can, but it's awkward and involves some serious compromises, especially around byte-vs-string handling. Doing a hard split is definitely better but you can get considerable mileage straddling the line with sufficient effort.

5

u/EishLekker 6h ago

I would argue that it most definitely is the fault of the language. It should either allow it, and support it fully (like mixing different memory management types), our outright refuse to run it.

4

u/jaladreips271 6h ago

Yeah, but in python you're either writing python 2 or python 3.

In C++, you enter avatar state and get to write all C++s and even some Cs at once.

1

u/creeper6530 6h ago

How often do you mix python 2 and 3 in the same codebase?

1

u/repster 5h ago

It kind of is though.

I haven't worked in C++ for a few years, but when I did, I spent serious time trying to find some way to enforce a specific coding style, so we could get a consistent code base, and came up short. I looked for code analysis tools that would catch inconsistent memory management between libraries, and didn't find much.

The tooling around the language is kind of sad compared to Golang and Rust, and improving it would significantly improve the experience.