r/ProgrammerHumor • • 24d ago

Meme programmingLanguagesWhenYouAskThemToDoSomthing

Post image
1.6k Upvotes

224 comments sorted by

View all comments

-11

u/Choice-Committee203 23d ago

what is wrong with c++? if we're talking about modern c++ (at least c++11 or even latest c++23) then it's a pretty good language, you can just... use the stl. it's not c with classes anymore, it has lots of lots of actually good features. you can literally just code without worrying about memory management like in c. c++ works on RAII, where object's constructor allocates memory (often automatically now) and destructor frees it (also automatically). it's much more similar to java, but with more features. i think nowdays you need to think more about memory in java, take string comparation or array copying for example, in java str == "meow" is compating the pointers so the result is almost always false, so you have to use ugly str.equals("meow") workaround. in c++, there's a thing called operator overloading, where you don't write the .equals() methods, but just overload the == operator itself for that object, so str == "meow" works as intended. or in java when you do array2 = array1 then it's again copying the pointers, so that array1 and array2 now again point to the exact object in memory. in c++, again, the std::array which you hopefully should use instead of c-style arrays, is again overloaded, so array2 = array1 actually deep copies the data from array1 to array2. if you keep using raw c pointers*, raw c arrays[], raw c malloc/free, raw c strings (char*) then OBVIOUSLY you're going to receive a segmentation fault some day, if you use safe std::unique_ptr/std::shared_ptr, std::array/std::vector, raii principles, and std::string, then c++ is a fucking modern safe language!!!! #stopcppstereotypes

anyways, about the image: c++ should be "On it, boss!" c should be "Segmentation fault (core dumped)

7

u/Choice-Mango-4019 23d ago

anything can give segfault if you're good enough

0

u/Choice-Committee203 23d ago

but in c is WAAAAAAY more common