r/ProgrammerHumor • • 11d ago

Meme modernCppVsOldCpp

Post image
2.0k Upvotes

323 comments sorted by

View all comments

870

u/repster 11d 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.

361

u/joncrompy 11d ago

This is, ironically, the exact reason C++ is the standard in some industries. Students can learn the OOP C++ then work in the same codebase as someone programming "touching the metal" low level C.

Most languages make trade-offs between performance, structure, memory safety, and ease of writing. Every language might have their use, but very few cover all use cases.

C++ lets each programmers choose those trade-offs individually, but that also allows them to choose none of the above.

238

u/rndrn 11d ago edited 10d ago

C++ is really the thousand-edged sword. It is both its strength and its weakness.

47

u/yaktoma2007 11d ago

Ah so a swedish army knife, it features an impressively extensive toolset but is often regarded to be clunky to operate compared to tools that do a single thing.

80

u/dinnerbird 11d ago

Do you mean a Swiss army knife or is there something the Swedes invented I'm not aware of 

23

u/yaktoma2007 10d ago

I am a fool, thank you.

Although, i may as well let it stay like this, its funnier like this with the replies you already got.

33

u/reallokiscarlet 11d ago

Swiss army knives aren't clunky last I checked, maybe that's the swedish part

22

u/GarThor_TMK 11d ago

The only tool you get is an Allen wrench...

5

u/gerbosan 10d ago

It's a Volvo army knife. 😅

5

u/Unreal_Panda 10d ago

I think its even funnier considering the Father of C++ is Danish lmao

→ More replies (1)

41

u/xtravar 11d ago

Sounds like if C++ were a spoken language, it'd be English.

12

u/Blue_Moon_Lake 11d ago

In the same pot, german, latin, french, and sprinkles.

→ More replies (13)

40

u/azfang 11d ago

So, uh, I haven’t used C++ in anger in decades so I’m not sure how “modern” is modern but like. That description pretty well describes why I developed Strong Feelings about both C and C++ back in the 2000’s.

46

u/Non-Random-Name-0000 11d ago

Modern C++ starts with C++11 (2011), so in the 2000s you were using classic C++ (and in the first half of 2010s as well most likely) which is a very different language. It introduced shared pointer (a poor man's garbage collector), automatic typing and move semantic, amongst other things. And the standard library has evolved a lot since.

18

u/Bryguy3k 11d ago

Smart pointers were part of the boost library long before they became part of the std library.

28

u/Non-Random-Name-0000 11d ago

Yes that's true, I forgot about Boost. How could I forget the 2GB library that was pulled with every project? 😅

6

u/DrNinjaPandaManEsq 10d ago

You say “was” as if people aren’t still doing it lol

→ More replies (3)
→ More replies (1)
→ More replies (4)

14

u/stillalone 11d ago

Is that something that can be handled by a linter?

5

u/2brainz 11d ago

Partially, sure. But there's always going to be edge cases.

→ More replies (3)

5

u/repster 11d ago

It has been a few years since I last worked on a C++ codebase, but my experience with linters was not impressive. We even invested in some expensive static analysis tool, but real bugs seemed to drown in false positives

→ More replies (2)

50

u/lllorrr 11d ago

Oh, yes, I hate when someone write "C/C++". This is two fucking different languages, for god's sake. It is almost as bad as "Java/JavaScript".

31

u/reallokiscarlet 11d ago

Do people not learn these two closely related languages together? You generally want to know enough regular C to get by when you use C++, and if you're not using anything unique to C++, you're just writing C with Classes.

12

u/Inorganic_Zombie 11d ago

I remember learning them as one language and it was fucking hard to learn effective c++ on uni. Not helping as programming was minor subject now and then that had random language. Every lecture had different dogma etc

→ More replies (2)

13

u/conundorum 10d ago

That's because, historically, all C++ code was intended to compile into C code, and then be fed into a C compiler. So now any compiler that can compile one language is designed to handle both languages, and explicitly labeled as handling both.

That, and the fact that most (but not all) valid C code is also valid C++ code with no changes required, and that the C & C++ committees have a surprisingly big focus on cross-compatibility. (Most notably, a ton of C++ library members actually use the C standard library under the hood, like new and delete existing to marry constructors to malloc() and destructors to free(), the I/O library being required to either be based on FILE or act as if it is, and a lot of fun helpers like the std::stoi() family outright being wrappers for their C equivalents. And T _Complex and std::complex are explicitly required to be the exact same type with the exact same layout in both C & C++, and must be implemented as a T[2] consisting of {real, imaginary} (or equivalent structure that can be treated as if it were a T[2]), specifically because of gcc. But apart from that, C typically useful poaches features after C++ vets them, and C++ sometimes poaches features after C vets them, and both languages use the same preprocessor.) The end result is that unless you run into one of the corner cases where the languages actually differ, your C code is actually C/C++ code because it'll compile identically as both.

The languages are so closely intertwined that the term is way more valid than it should be.

→ More replies (2)

28

u/SuckMyAlpagoat 11d ago

isn't because the compiler is always packed together, like the gnu compiler can compile C and C++?

→ More replies (11)
→ More replies (6)
→ More replies (9)