On 18/07/2024 23:41, Lynn McGuire wrote:
"C++ Must Become Safer" by Andrew Lilley Brinker
https://www.alilleybrinker.com/blog/cpp-must-become-safer/
"Not everything will be rewritten in Rust, so C++ must become safer, and
we should all care about C++ becoming safer."
"It has become increasingly apparent that not only do many programmers
see the benefits of memory safety, but policymakers do as well. The
concept of “memory safety” has gone from a technical term used in discussions by the builders and users of programming languages to a term known to Consumer Reports and the White House. The key contention is
that software weaknesses and vulnerabilities have important societal
impacts — software systems play critical roles in nearly every part of
our lives and society — and so making software more secure matters, and improving memory safety has been identified as a high-leverage means to
do so."
Not gonna happen since to do so would remove the purpose of C and C++.
Lynn
The problem with a lot of "memory safe language" ramblings is that so
many people seem to imagine that "memory safety" is a binary issue.
They divide languages into two groups - "memory safe" languages and
"memory unsafe" languages and think that all code written in the former category is automatically "safe", and all code written in the later is inherently "unsafe".
This is, of course, total drivel.
It is not at all hard to have resource leaks in garbage collected
languages. You can happily have out of bounds accesses that crash the
program. Equally, you can perfectly well write safe code in C and C++.
The "safe" languages can make it harder to write certain kinds of
mistakes in the code, and can reduce the consequences of errors. They
can automate some things, reducing the manual work and error risk
involved. And that's great. There's a lot that gets written in
low-level languages such as C when it would be more productive and lower
risk to use a higher level language.
And with modern C++, you can also automate lots of things and write
clearly memory-safe code, just as well as many managed languages. The difference is that with C++ you can /also/ write unsafe code with all
the risks available to more manual low-level programming. Resource
management with smart pointers and standard containers can be as "memory
safe" as code written in Python - but C++ also lets you use manual
malloc() and C-style arrays and pointers, with the risks these entail.
(Of course you can write correct memory-safe code in that style too.)
I believe that the people who re-write ancient C code in Rust, producing
code with fewer bugs, could have had just as much success if they had re-written the old C code in new C, using modern C standards, modern C
tools, and modern C development techniques. It's not the language
change that makes the difference - it's throwing out accumulated cruft, avoiding old, riskier techniques, and writing code with an emphasis on
safety and correctness instead of trying to get efficient results from
limited tools.
That said, I think it will be good to see more safety-related features
added to C++, such as contracts and borrow checking. And more static
analysis to make it harder to write risky code is always a nice thing.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)