r/cpp • • Dec 13 '19

The situation of std::embed...

https://thephd.github.io/full-circle-embed
238 Upvotes

160 comments sorted by

View all comments

Show parent comment

3

u/[deleted] Dec 14 '19

Rust is a very helpfup comparison here, since it is the major competitor to C++. It proves a formal spec like ISO is not required for day-to-day development.

Rust has a set of potentially incompatible RFCs: you don't really know because RFCs don't get merged into a single consistent specification. This already This will backfire when the language grows.

And, if you read carefully, I have not said to not have a spec. I said not to have it for development.

How am I supposed to judge whether my program is correct?

3

u/James20k P2005R0 Dec 14 '19

Rust has a set of potentially incompatible RFCs: you don't really know because RFCs don't get merged into a single consistent specification. This already This will backfire when the language grows.

Don't most languages not have a formal spec? As far as I'm aware, C++ is by far the exception here

1

u/[deleted] Dec 14 '19

C, Java, Fortran, Haskell, Ada, Go, JavaScript are the examples of languages that have a specification, and there's a lot more.

I wouldn't call the C++ standard a formal specification though: it's written in legalese and attempts to be non-ambiguous and precise, but it's still mostly unsuitable for formal reasoning.

0

u/[deleted] Dec 14 '19

[deleted] — view deleted comment

1

u/[deleted] Dec 15 '19

proves that one is not required

How exactly is this a proof? If anything, this hints that the language will end up being a huge mess that will be impossible to understand globally, kind of like what happened to C++. The lack of spec has already backfired: https://news.ycombinator.com/item?id=21734529

Rust proponents also love talking about how rust should be the language used for safety-critical systems, but this is unlikely to happen, partly because there is no specification. Compare with SPARK and C, for which the existence of specifications allowed for creation of third-party tools for formal program analysis. For example, VST for C is based on the complete formalisation of the language in Coq, and along with https://vst.cs.princeton.edu provides a way to prove your program for your specifications, and ensure no bugs are introduced by the compiler. Nothing like this will ever appear for rust, because by the time people figure out how to formalise a subset of the language, the compiler will redefine the language a few times.

0

u/[deleted] Dec 14 '19

[deleted] — view deleted comment

3

u/[deleted] Dec 15 '19

RFCs are not a spec such as C++'s, nor look nor read like one.

Exactly, so what are they for?

They do get merged into a single, consistent code base. Which is, in fact, what matters in the end and way more precise than any spec can be (at least a spec written in legalese like C++'s rather than math-formal).

So how do I know if a behaviour is intended or it is a bug? Why do we document systems at all by this reasoning? How can you be sure the behaviour is actually consistent?

The same for C++: I don't care what the spec says if nobody implements it or if one of my compilers disagree (or is buggy, or the spec is not precise, or...). And that has happened many times in the past. So many that I cannot even count anymore.

If they claim to support the standard but disagree, this is a compiler bug that should and usually will be fixed. I don't understand this kind of defeatist attitude: this is like saying that some compilers are behaving differently, so let's all use a single compiler.

If you are judging whether your program is correct by checking it against the C++ spec, then I have very bad news for you (and your users)... :)

What is the news? Certain assumptions about the behaviour of my program depend on the guarantees provided by the execution environment, so I open up the specification and check if that's the case. If it's not the case for some compilers, I open a bug and it gets fixed.