r/ProgrammerHumor • • Oct 24 '26

Meme dreamLanguage

Post image
1.4k Upvotes

211 comments sorted by

View all comments

-1

u/FallenDeathWarrior Oct 24 '26

I will never understand why people say that C++ is unsafe. You can write it perfectly fine and safe. Yeah you have to think while you code, but that isn't a big deal 

27

u/chat-lu Oct 24 '26

And when are programmers going to start doing that?

2

u/svick Oct 24 '26

When they perfectly understand every aspect of the language.

6

u/Zinho3311 Oct 24 '26 edited Oct 24 '26

Yeah, good luck with that. You literally cannot possibly understand every aspect of C++ at all times. That's how complex it is. The spec alone is a mess of 2,000 pages, not to mention different compilers diverge on the implementation of a ton of stuff.

The thing about C++ isn't just that it's memory unsafe, it's also that it's so complex by default with hidden abstractions and strange behaviors that every little mistake ends up propagating downstream and blowing it all up in your face.

I'd argue C++ is even more dangerous than C. While it is easier for you to make mistakes in C, usually it's easier to debug and less catastrophic because there are no hidden abstractions. Although, to be fair, that's not a hill I'd die on.

Eventually, if you write C++, you WILL end up making a mistake and some teenager with a fuzzer WILL pwn you.

Even the most badass programmers I know didn't break that rule. It's also asymmetric because the attackers only need you to make one single mistake. Those days when you're running on caffeine or had an argument and wasn't thinking too straight is the perfect type of day to make a mistake that ends up with someone making fun of you on /g/

→ More replies (5)
→ More replies (3)

57

u/ihavebeesinmyknees Oct 24 '26

"I will never understand why people say 1920s skyscraper construction sites were unsafe. You can be perfectly fine and safe, you just have to be careful not to fall, but that isn't a big deal"

22

u/spiralenator Oct 24 '26

Right? People act like having a hand rail means you can't jump over it you really want to do something stupid.

If we're speaking of C++ being unsafe, we're likely comparing it to Rust. In Rust, that safety is a hand rail on a balcony. You can hop it if you put some effort into it. C++ safety is a door on the 60th floor that opens out into nothing.

3

u/redlaWw Oct 25 '26

Hey, at least the door has a label on it telling you what you need in order to open it safely, listed as a sequence of item codes that you can look up in the directories scattered around the skyscraper.

→ More replies (1)

2

u/mslass Oct 24 '26

Cue Roger Rabbit

15

u/crystalchuck Oct 24 '26

Which is why there are multiple organizations regularly publishing entire books on how to use it safely, because it's just not a big deal and you can easily figure it out with some thinking

6

u/floriv1999 Oct 24 '26

The last time somebody confidently said that to me I asked him for his last cpp project and ran it through valgrind. There where a lot of issues. The next day he asked me how to get started with rust.

5

u/willow-kitty Oct 24 '26

Modern C++ makes it a lot more straightforward to write safe C++ (and gets you closer to the "obviously not unsafe" end of things vs the "not obviously unsafe" end of things, which is so crucial for safe code), and you could always do it if you knew what you were doing, but it was often complex and kinda extra-linguistic (like by adding prefixes to pointer parameter names to indicate intended borrowing semantics and stuff), and maaaaaaaaaaaaybe checking it with a really fancy linter. It wasn't until relatively recently that it was mostly about thinking about it (probably C++11ish, when they added std::unique_ptr and std::shared_ptr). But even today, because all the legacy stuff is still in there, it can be mess to sort through what's actually appropriate for a given task. I've heard it referred to as "the meta," like people say in fighting games where there's a correct way to play out of all the options available, and I think it's pretty apt, tbh.

Also, pretty much every named vulnerability of all time has been caused by C or C++ coding errors that allowed improper memory access of some kind.

1

u/derefr Oct 25 '26

IMHO all C++ needs to regain popularity is for someone to create a C++ compiler that, at least in its default mode, only accepts the "good, modern parts" of C++; and then to brand the result as a different language entirely, with no advertised association to C++. You only find out that what you've been writing is technically all also legal C++, when that fact is sprung on you at the very end of the extended language tutorial / textbook / etc. "You fool! I just got you to learn C++!"

(Or, to put that another way: C++ needs a labelled, marketable Schelling point of good praxis for people to be able to congregate around, hire for, etc.)

As a bonus, unlike C++ itself, that differently-named subset-of-C++ language would have the opportunity to start fresh in terms of compatibility burden. So it could have e.g. canonical ecosystem packaging tooling and such, that C++ as a whole fundamentally cannot (since "C++" includes things like e.g. random one-off abandonware toolchains created by microcontroller OEMs, that wouldn't, and mostly can't, sensibly implement a client for some constantly-evolving packaging APIs.)

→ More replies (1)

8

u/UdPropheticCatgirl Oct 24 '26

No language with undefined behavior can be safe… That’s entire problem with having it.

8

u/M4rshmall0wMan Oct 24 '26

“Avoiding null types is easy, you just gotta add a check every function.”

That’s such a non-human answer to a problem that shouldn’t even exist. You miss one, and your program blows up. That’s not a skill issue.

5

u/chat-lu Oct 24 '26 edited Oct 24 '26

The analogy I like to use is that it's like walking in a minefield with a detector. You just point it, press the button, and if it beeps there is a mine. Easy peasy.

How confident are you that you won't ever forget one time while crossing the whole field?

3

u/M4rshmall0wMan Oct 24 '26

Perfect metaphor. 

2

u/Batman_AoD Oct 24 '26

Hm, not sure I completely agree. Rust has undefined behavior in unsafe constructs, so perhaps "no language without guardrails around its undefined behavior" might be more accurate. But unfortunately it's necessary for languages with direct hardware/memory access to have some amount of undefined behavior. (It's also frequently stated that UB is necessary for modern optimizations, but I find that claim less believable, even having watched Chandler Carruth's talk defending that claim.) 

2

u/-Ambriae- Oct 24 '26

But that’s the thing, rust code that can have UB is opt in (supposing safe rust is void of UB which is not strictly speaking true, but is being worked on) whereas C++ UB isn’t even opt out

→ More replies (3)

2

u/Orio_n Oct 24 '26

Lots of people can shove a 9 inch dildo up their ass perfectly safe. Why dont you give it a try and let me know how it goes

2

u/the_vikm Oct 24 '26

"don't make any mistakes" energy

1

u/Yiurule Oct 24 '26

It's like saying that it's safe to fuck condomless, you just need to check everytime you and your partner before doing it.

I mean sure, if everything was done properly it would be safe, but still better to put a condom to at least protect per default.

1

u/EskilPotet Oct 24 '26

I'll never understand why people say Python is safe, I can write a script to delete system32!

1

u/burnalicious111 Oct 24 '26

That's literally what unsafe means lmao

1

u/mrheosuper Oct 25 '26

Safe C++ code is as real as unicorn

1

u/Suspicious_Fudge1702 Oct 25 '26

I do c++ and well I mean it's not unsafe but just make sure you don't make your pointers point at some system files and modify them. But most of the times it's safe, especially when I do competitive programming on codeforces.