C++ can do all that rust does?

As our OP's question was inspired by some quote from Bjarne Stroustrup in an article entitled: "C++ Creator Bjarne Stroustrup Weighs in on Distributed Systems, Type Safety and Rust" I thought it would be useful to actually read that article.

Well, firstly the articles title is somewhat click baity. The word "Rust" appears in the article exactly twice. Hardly what I would call "weighing in". And only once in any solid technical context.

There is a little more talk of Rust in the actual interview, but not much: Ask Me Anything with Bjarne Stroustrup, hosted by John Regehr - YouTube Well worth a watch.

Interesting things I did find:

Q: "What do you think the main areas where you think C++ compilers could do better?"

A: I won't quote the whole reply here but Bjarne talks at length about: Static analysis, dangling pointers, memory corruption, no range errors, null pointer dereferencing.

He says: "We know how to do that [static analysis]. It can be done."... "I would like my static guarantees to hold for million line programs." ..."I really don't want my planes to crash and I want the brakes in my car to work."

When asked about memory safety the reply includes: Use the core guidlines. Need static anaysis. Mention of Ownership. Better if you don't have memory reference cycles.

When asked about ownership the reply is: "we're [C++] going there, I think we can do better [than Rust]"

When asked about his favorite languages he is wisly circumspect:

"It would not be a nice world if we only had one language that everybody had to fit into because I don't believe there is or could be a perfect programming language."

Now, I interpret all that as Bjarne fully endorsing what Rust is doing w.r.t. memory safety, wishing it was in C++, and has promised to do it better in C++. They are rising to the challenge, as it were.

We shall see...

Except I won't. Any of that ownership or static analysis is likely far away. Unlikely it will make much progress for the next next standard revision in 2023, more like 2026/2029. That is too long for me when I have Rust here and now. Along the way C++ will grow another couple of layers of unfathomable complexity.

5 Likes