this post was submitted on 21 Mar 2024
31 points (97.0% liked)

C++

1778 readers
2 users here now

The center for all discussion and news regarding C++.

Rules

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 16 points 8 months ago (2 children)

Honestly his defence is rather weak. “It’s been improving and there are ways to use it safely.”

That is not to say I agree with the administration’s statement. Not only is secure code only one aspect among a myriad to consider when choosing a language, using a “safer” language does not necessarily lead to more secure code.

[–] [email protected] 11 points 8 months ago

Yeah, I like his argument about profiles maybe going to be able "e.g., to eliminate most range errors relatively soon."

Well maybe C++ could be considered safe "relatively soon" then but not right now.

Like he says: "Of the billions of lines of C++, few completely follow modern guidelines, and peoples’ notions of which aspects of safety are important differ."

That said, I don't really consider C++ to be inherently unsafe, there's a lot that goes into secure programming in any language. Just because you can't write to an array out of bounds in python doesn't mean your code is magically immune to vulnerabilities and just because you can in C, it doesn't mean your code is magically vulnerable to RCE from some buffer overflow.

I also don't really trust myself to write perfectly safe production C++ though. I feel like it's still too easy to feel like you know exactly what you're doing and accidentally miss something small (hence the many thousands of memory safety CVEs in professional software).

[–] lysdexic 1 points 8 months ago (2 children)

Honestly his defence is rather weak. “It’s been improving and there are ways to use it safely.”

I think it's a very good and clear point to make.

Some programming languages are blindly deemed "safe" in spite of supporting unsafe memory management strategies, and somehow not enforcing those rules does not render them unsafe.

Why is this logic not applied to C++?

[–] technom 5 points 8 months ago

Unsafe code, at least in Rust, is given special treatment and care. Such code is usually 5% or less of the total codebase. Such unsafe blocks are also commonly reused fundamental designs. This leads to them being designed as libraries that are shared.

You can of course give C++ the same consideration. But then 100% of that code base will have to be given special care. And the reusability of unsafe code goes out the window.

People who argue that Rust (not sure about GC languages) is equivalent to C and C++ because of escape hatches like unsafe, completely neglect the localization of unsafe code and the benefits it brings.

[–] arendjr 5 points 8 months ago

Some programming languages are blindly deemed “safe” in spite of supporting unsafe memory management strategies, and somehow not enforcing those rules does not render them unsafe.

You’re applying a strawman argument here, because nobody is blindly deeming any languages as safe. But they are recognizing some languages as safer than others. Safety isn’t a binary switch, and most people recognize that. Most people also recognize that using tools that make it harder to achieve safety, does, in fact, make it harder to achieve safety. And thus, if safety is important, avoiding those tools makes perfect sense.