Live data from Hacker News

Modern C++ Won't Save Us

alexgaynor.net

101–110 of 395 posts

Re: Modern C++ Won't Save Us

#101
post #93

The C++ people are trying to refit ownership to the language without adding a borrow checker. This is painful. They've made it possible to write code that expresses ownership, but they can't catch all the places where the abstraction leaks. string_view is really a non-mutable borrow. But the compiler does not know this.

> but they can't catch all the places where the abstraction leaks.

Why does static analysis not work here?

Re: Modern C++ Won't Save Us

#102
post #101
post #93

The C++ people are trying to refit ownership to the language without adding a borrow checker. This is painful. They've made it possible to write code that expresses ownership, but they can't catch all the places where the abstraction leaks. string_view is really a non-mutable borrow. But the compiler does not know this.

> but they can't catch all the places where the abstraction leaks. Why does static analysis not work here?

[deleted]

Re: Modern C++ Won't Save Us

#103

A significant issue I have with C++ is that even if your code base is pure C++17, the standard library is a Frankenstein's monster of legacy and modern C++ mixed together that required many compromises to be made. A standard library that usefully showed off the full capabilities of C++17 in a clean way would have to jettison a fair amount of backward compatibility in modern C++ environments. I've noticed that more an…

I don't see the problem. You are free to use such a modern library (Google does, it's called absl).

The good thing here is that the standard library doesn't require 'magic' to be implemented (unlike Swift where the standard library relies on hidden language hacks).

Re: Modern C++ Won't Save Us

#104

A significant issue I have with C++ is that even if your code base is pure C++17, the standard library is a Frankenstein's monster of legacy and modern C++ mixed together that required many compromises to be made. A standard library that usefully showed off the full capabilities of C++17 in a clean way would have to jettison a fair amount of backward compatibility in modern C++ environments. I've noticed that more an…

What legacy? It's not like there was a single "before time." There are problems coming up with all of it, because the underlying runtime model provides too few guarantees. We'll be plugging holes the rest of our natural lives.

No, the problem is NOT the underlying runtime model. In fact it's often the opposite: the STL tries to provide too much.

An excellent example is std::unordered_map. This type was introduced to address perf problems with std::map. But unordered_map forces closed addressing, separate allocation, etc. which limit its performance. In return you get stronger iterator invalidation guarantees but these are rarely useful. Meanwhile Abseil's swiss tables, LLVM's DenseMap, etc. illustrate what a high-performance C++ hash table could be.

Re: Modern C++ Won't Save Us

#105

Any HN post mentioning C++ will inevitably be invaded by the Rust Evangelism Strikeforce.

You picked a bizarre article to make that comment on...It's hardly irrelevant to the post, as the author's central thesis is that there's no case for choosing C++ over languages like Rust and Swift (he says as much in the article).

Re: Modern C++ Won't Save Us

#106

Earlier quoted context omitted.

The problem, as far as I understand it (though I’m a layman), is that by the time the dead code optimization pass runs, the code has been transformed so much that there’s no obvious way for the compiler to tell the difference between “obvious programmer-intended null check that we shouldn’t optimize out” and “spurious dead code introduced by macro expansion” or (in C++) “by template instantiation”.

Couldn't user defined branches be tagged by such a compiler and if a tagged branch is eliminated the error generated with a reference to the tagged line in question?

That is a good idea and I’ll admit that I’m not sure why it isn’t implemented.

Re: Modern C++ Won't Save Us

#107
The string_view issue has popped up even in relatively safe languages. Java's String class used to do something similar, where substring returned a String that referenced the original String object's internal array to avoid a copy. They gave up on it because too many people accidentally held a references to large strings and leaked memory that way.

Re: Modern C++ Won't Save Us

#108
post #103

A significant issue I have with C++ is that even if your code base is pure C++17, the standard library is a Frankenstein's monster of legacy and modern C++ mixed together that required many compromises to be made. A standard library that usefully showed off the full capabilities of C++17 in a clean way would have to jettison a fair amount of backward compatibility in modern C++ environments. I've noticed that more an…

I don't see the problem. You are free to use such a modern library (Google does, it's called absl). The good thing here is that the standard library doesn't require 'magic' to be implemented (unlike Swift where the standard library relies on hidden language hacks).

Sure it's possible to use a non-standard "standard library". But at that point you're already halfway to using a different language so why not consider switching from C++ to D / Rust / Go?

Re: Modern C++ Won't Save Us

#109
post #56
post #15

Question - How does one write microcontroller code (or other memory-mapped I/O code) using a memory-safe language?

Tradeoffs. Ada has a history on microcontrollers, and is old enough we can answer with some certainty. You may end up having to bypass bottlenecks caused by runtime checks... And that means unsafe code in a critical location. Performance or safety. At different parts of your code you may find yourself choosing.

Not really, once you are sure of your Ada code you may choose to disable all checks or selectively disable checks for your production code. Meaning you essentially have no penalty if you choose to go the performance route after significant testing

Re: Modern C++ Won't Save Us

#110
post #108
post #103

Earlier quoted context omitted.

I don't see the problem. You are free to use such a modern library (Google does, it's called absl). The good thing here is that the standard library doesn't require 'magic' to be implemented (unlike Swift where the standard library relies on hidden language hacks).

Sure it's possible to use a non-standard "standard library". But at that point you're already halfway to using a different language so why not consider switching from C++ to D / Rust / Go?

No, using a library is not halfway to using a different language.

Languages exist to allow you to define your own layers of abstractions. The language choice ideally reflects what abstractions are useful for your project.

Post reply on HN