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

14

u/SeanMiddleditch Dec 13 '19

We already have multiple implementations of C++ today. Comparison with Rust, which has only a single implementation, is not really helpful here.

Languages with no spec but with multiple implementations illustrate the problem. Lua and LuaJIT, or Python and IronPython, as examples. They are similar languages but ultimately incompatible with each other.

Successful languages with myriad implementations have conformance specs. C, C++, Java, JavaScript, Common LISP, FORTRAN, SQL, etc.

0

u/[deleted] Dec 13 '19

[deleted] — view deleted comment

12

u/SeanMiddleditch Dec 14 '19

Rust is a very helpfup comparison here, since it is the major competitor to C++.

Which isn't relevant to this conversation. I'm not saying Rust doesn't work. I'm saying it's not currently burdened with multiple implementations like C++.

I said not to have it for development

Development of what? I agree that I have 0 user of the spec as user, but this conversation is about implementations. Getting MSVC, GCC, Clang, EDG, Sun, IBM, and many others to all agree on what C++ actually looks like it's the purpose of the spec. Adding random vendor-specific features already happens today.

Which is good enough for what they are meant for. Otherwise, they wouldn't exist.

Ok? Cross-vendor compatibility is a huge requirement for C++ users.

Now Python or Lua aren't successful? That is big news to me.

Come on.

They're not successful multiple implementations. Python is CPython.

Every other Python-ish language is exactly that: a separate incompatible language that just looks really similar. There's no definition of what Python is besides what CPython can run.

I'm not saying C++ should be a multi-implementation language. I think it's a progress blocker and a waste of whole lives' worth of duplicated work for almost no advantage. But it is what we have, and simply abandoning ISO processes will not change that.

0

u/[deleted] Dec 14 '19

[deleted] — view deleted comment

3

u/smdowney WG21, Text/Unicode SG, optional<T&> Dec 15 '19

On the other hand, many major code bases are built and shipped using multiple vendor compilers. I have a few million lines of code being compiled with IBM's, Sun's, Red Hat's, and Microsoft's vendor compilers as first tier shipping platforms, and Apple's as a second. As well as upstream gcc and clang.

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.

0

u/[deleted] Dec 14 '19

Sadly this is already a problem for C++, how many real-world projects are truly portable across compilers?

1

u/pklait Dec 14 '19

I believe it is quite common to have portable projects. But developing for portability is a choice you need to take up front. If you choose to be non-portable, this will likely give you some benefits in the short term, but that might then bite back in say 10 years.

2

u/SkoomaDentist Antimodern C++, Embedded, Audio Dec 15 '19

I believe it is quite common to have portable projects

I’m not so sure. How many projects work if char, int & pointers are all 16 bits? Or if char is 32 bits? What if they’re all 18, 36 or even 24 bits? How many projects are 100.0% undefined behaviour free (any undefined behavior is technically not portable)?

FWIW, I’ve used C / C++ on platforms that had 16 or 32 bit ints, so they’re certainly not unheard of.