112 points · by ingve · 6y ago · 220 comments
The C++ standards committee can standardize a backwards-incompatible "new" C++ for all I care as long as they don't call it C++.
This x2. It's only C++ if you can optionally refactor random lines of code in a project written in compliance with C++98 using new features and still get a valid program.
Once you mess with the language in a way that your C++98 code is either not supported or requires rewrites or redesigns to comply with the new standard then quite obviously it is not C++ anymore.
Semver matters.
Java is in a similar situation, which is probably why they market the minor version.
So there is a path, but it has to take an upgrade-path into account for big legacy projects. In practice, moving to a new compiler can be a big project for companies with larger code bases. Sensible deprecation of features could (and in practice) is part of that.
Even though the standard is quite careful, in practice big C++ projects sometimes rely on non-conforming behavior of the specific compiler version they use. An example is the MSVC template support which allowed constructs that the standard didn't.
The committee does a lot of work to keep the standard compatible with c++ as it is used and this proposal seems to be a good example of them trimming out dead and bloated parts, without negatively impacting existing code.
The original proposal for that deprecation points out a lot of issues. Basically it boils down to the fact that many operations were badly specified, outright misleading, predate the c++ memory model or were artifacts of maintaining the parallel to const that volatile had in C at a large cost and without people actually using it, one example they could track down even noted how it did not behave the same way as primitives would.
Your example is a really poor one. The volatile keyword was only used to provide hints to the compiler on whether or not it could apply some optimizations. Omiting a volatile keyword is perfectly backward compatible, as is compiling code without support for volstile. Thus the only practical consequence of adding/removing random volatile keywords from your source code was how your build could (and not should) be optimized.
That's a far cry from, say, remove malloc().
In short time, is bad. The more time pass, is good.
The cost of STUPID C/C++/JS behavior is measured in the billons.
Is not the makers of this langs aware? Yes. They know how could be fixed? Sure. Then WHY is not fixed?
Because not considering time in the calculation (and how many MILLONS OF PEOPLE are affect). But today, are DECADES behind of 100% certainty of the cost of this mistakes, and proved beyond doubts that the langs that fixed them ARE better.
In the face of reality and facts, why resist so much?
---
The thing is HOW get out of this mess?
The big irony is that the JS world show how (but not commit with the proper force): Build transpilers. Make "Better C++" that transpile to "BAD C++". Make clear that everyone must move forward, but provide this as partial step.
Make auto converters. Fix damm stupidity like dangling IFs, (seriously some stuff is not brainer). Have a clear vision in how move forward.
And drop the ego. C/c++ not need to turn into Rust, but why believe it could not truly get better?
Now, in the case of C/C++ exist a big trouble in the case of being the "de facto" ABIs for the rest of the world. Apple have the same issue with swift -> ob-c with the case of nullability (which apis never return null even if in theory could?).
Them do annotations to the APIs. This could allow to mechanize the transformations and provide ABI translations that could be injected in the compiler.
For example:
ABI STEP 1 (annotate only):
fn evil():NullableString //Imply NullableString = Option(Str)
[safe(NullTerminatedString == Str)]
fn not_evil(): NullableString
Old code is assumed to be alike evil.ABI STEP 2 (rewrite):
fn ex_evil():Option<Str>
fn not_evil():Str
Then it could autotranslate the calls in demand at compile time, following transformations alike maps.Eventually, when the calls are converted this step is erased and the runtime penalty removed, then all become good.
Yes, but no.
When people design a language which they know is going to be incompatible, they tend to go all the way with it. If we're breaking it anyway then might as well do a better standard library interface than the stuff designed in the 90s and all that sort of thing, right? And that's good to have for new projects.
But there is a benefit in having something which makes the smallest possible compatibility-breaking change to fix the defect in the original. So you have a "new language" with a borrow checker, but the standard library functions all have the same names and the same purpose and time complexity as the C and C++ ones, which would allow people to run the existing code through a transpiler which for 80% of the lines can be translated directly to working code in the new language, and produces diagnostic errors for the other 20% that explain what needs to be changed.
Which removes 80% of the work from transitioning an existing codebase to the new language. And then more people do that.
Rust does not provide the facility to strategically obfuscate code at scale like C++-style function overloading does.
// C++
auto f() -> int32_t {
return 1;
}
// Rust
fn f() -> i32 {
return 1;
}Nevertheless, in Ethernet's case, while it changed backwards incompatibly at the beginning, since then, consumer Ethernet has been backwards compatible all the way from 1990's 10BASE-T (10Mbit) to the still-rare 10GBASE-T (10Gbit). In data centers you have faster variants that require different cables, for routers... but even there I believe the connections to individual servers typically use the old twisted pair.
Maybe that's what Python 3 should have done: don't remove stuff, but just make it discouraged and let a python3only" flag treat them as errors when ready.
What we got was kind of a mess. Because python2 is very often valid python3... But not always.
1. "New C++" would not just be a subset of the syntax of old C++.
2. ABI issues.
Nowadays I'm mildly annoyed if a project is on one of those "ancient" 3 but ≤3.6 Python versions and I can't use the nice features in 3.7+...
No, it is a mess and it was a failure.
It tooks more than 10 years to happen, and even so...Many tools will die with python2 and never be migrated.
If your codebase is not usable anymore because your language evolved. That's a failure.
I can still compile the C's from the 80's today if I want to. Same for Fortran, Same with C++.
Well, just FYI the "new" C++ is not the "old" C++ anymore. Languages "evolve". Try to compile an old program on the new compiler. The same is valid for other languages (C, fortran, perl).
> The C++ standards committee can standardize a backwards-incompatible "new" C++ for all I care as long as they don't call it C++.
They already do this. For C for example you have C89, C93, etc.
Same for C - that old library in C89? Still usable in modern projects.
Also:
> I think it also makes sense for C++ developers whose projects are relatively short-lived, e.g. some games.
There is a difference between games and engines - the games might be short lived, but most C++ engines are very long lived, going back decades (e.g. see how the recent Half-Life Alyx can trace its codebase back to Quake 1 or pretty much anything based on the Unreal Engine going back to the mid-90s - there are screenshots of UE1 running on what appears to be either Windows 3.1 or NT 3.51). Even when "engines" are being made "from scratch" this is often a marketing gimmick and the "from scratch" was just renaming the engine because it got a new rendering model and people can't tell the difference. EVEN when this isn't case, often new engines are based on existing code and/or libraries.
While true the engines are also staffed and can absolutely keep up with changes. They regularly are tasked with new toolchains, platforms, OSes, and APIs to leverage already. This would just be more of the same, and if you look at the goals of the paper: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p213...
That lines up pretty damn well to what game engines want as well.
> One of the main reasons to stick with C++ (and C) is that the investment you put in the code you're writing right now, no matter how fugly it is, will be there and keep working in the future.
I think you should read the actual paper instead. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p213...
The things they talk about actually abandoning are things like byte sizes other than 8-bits or source code in file systems that don’t support file extensions or nested directories.
Chances are any existing C++ codebase is already not compatible with such systems that they want to more formally deprecate/abandon in the first place.
> Our experience is that providing broad ABI-level stability for high-level constructs is a significant and permanent burden on their design. It becomes an impediment to evolution, which is one of our stated goals.
This does not name it, but doesn't this refers to all those discussions about changing internal representation of std::string, std::vector and so on?
This does sound pretty scary. Once you have separate classes for "C++23 std::string" and "older std::string", you can no longer link together files built with different versions.. and this means you lose a lot past compatibility.
True but this is already something that isn't really "supported" broadly. Some standard libraries work hard to keep that working, but others tend not to, and nobody knows if it's supposed to work reliably or not. And support for this binary compatibility also varies across platforms, like I don't think Microsoft bothers since you're supposed to always bundle a specific version of the runtime with your binary.
Single-version prebuilt libraries become more of a problem, but are those that widespread vs. source-based libraries?
But I think the broader point here that the paper is really pushing is for the committee to actually make a statement on things like this instead of their historically vague "it sort of works but we're not saying it will or indeed saying anything at all"
If the python 3 interpreter could still run python 2 code. If you could mix and match python 2 and 3 code on a per-module, per-file or even per file basis, then the transition could have been so much smoother.
- the languages were not that different, so no need to learn the new version
- python core devs gave 10 years to make the transition. Then extended it.
- it was possible to write code running on python 2 and 3
- python is very expressive, hence the code base have way less numbers of lines than in C++
- python cared only about one implementation, Cpython. The rest of the world needed to follow. Some didn't, like Jython and stackless, and the community didn't blink.
Despite all that, the transition was very painful.
This doesn't match reality. In reality, many Python projects have way more lines of code than equivalent C++ projects. Probably because of the 'expressiveness' you cite; you can't really showcase your love of coding and job security though artificial complexity without 'expressive' bells and whistles. (This is the idea that lead to languages like Go, I'm pretty sure.)
That said, C++ is plenty 'expressive' itself.
The to abandon backwards compatibility in C++ is to make a mockery even of the name of the language (see the "C" in there). If they want to create a new language they should call it something different. Willfully abandoning backwards compatibility and keeping the name is an abuse of one of the great brands in software.
Except slowly people will be writing parts of it in Rust, or they would be using libraries written in Rust (because availability), and then after a while people get annoyed of using more than one language and the whole project will be rewritten in Rust. Of course, at that point, a new language will be invented and Rust code will be looked at as rusty :)
And realistically I'm not entirely sure how you can add C++ interop to Rust without also ruining Rust. It's a hard problem to say the least.
Wishful thinking.
https://kennykerr.ca/2019/11/05/rust/
https://twitter.com/benwilliamson/status/1240113606374686721
Source?
John Carmack said in 2004 that "there are still bits of early Quake code in Half-Life 2" - https://github.com/ESWAT/john-carmack-plan-archive/blob/mast...
In all seriousness, Half-Life Alyx is based on Source 2 which itself is based on Source 1 which is based on GoldSrc which is based on Quake 1.
https://youtu.be/tISy7EJQPzI?t=2209
I remember watching another talk where they propose something similar for the language itself, but I can't find it at the moment.
Per Hyrum's law, someone will rely on any given behavior. So, if you choose backwards compatibility, it becomes harder for the committee to evolve the language over time.
The path of breaking changes can be made less painful, and does not, necessarily, invalidate all the code that is already written.
With that being said, the problem right now is not the decision of keeping backwards compatibility or not, but the fact that the standard should be explicit about it, so people know what to expect.
Such a solution is only possible if driven by the standard, otherwise it will never be fully available, just like the static analysis tooling varies by vendor.
Maybe you could do like Rust with their "Epoch" system that lets you interoperate code using various standards in order to migrate progressively without breaking backward compatibility. I suspect that it would be a lot harder to make it work for C++ however, mainly due to its extreme reliance on #includes (especially for anything using templates) and more common use of macros.
I'm not saying it's impossible but I suspect that it would fragment the ecosystem quite a bit. Removing "old features" tends to have massive side effects in a language like C++ with metaprograming, overloading, multiple inheritance, unlimited macro usage and complex symbol resolution rules.
So I think "why not just use Rust/D/Zig/Nim/Crystal" is warranted feedback for these proposals (and you could probably add Go, C#, Java and a few others).
However, there's an active (and in my understanding, decently received) proposal based on it for C++ that is called "epochs".
Much of this proposal would create insurmountable engineering problems for everything except the Google monorepo, or similar infrastructure at $1T companies building monoliths.
Historically, most innovation has happened outside of those environments.
Sabotaging the toolchains of smaller shops is not going to pan out well for the industry at large.
C++ 11, 14, 17, 20, and 23 are all binary compatible (modulo some possible oversights). There are many quality-of-life improvements that got voted out because then a binary compiled in C++11 wouldn't be compatible with one built in C++23 anymore.
As a simple example ([1] has many more): the only reason we have both std::scoped_lock and std::lock_guard is because changing the definition of the latter would have required re-compilation of existing code, so a new class had to be introduced.
ABI stability even overrides performance in committee decisions (see the std::regex example, but I also heard it affects the footprint of unique_ptr - edit: found it [2]).
tl;dr breaking source code compatibility seems way off if implementors don't even dare to break binary compatibility.
[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p202...
I'm currently working on a C++ project that has been taken out of cold storage and when the old rewrite question pops up the tech stacks considered for the job do not feature C++ at all. The main reason is that nowadays there are better tools and frameworks to implement non-performance critical parts of an application such as the GUI, which incidental takes over more than half the total lines of code, and the rest can be implemented easily with small support services developed in whichever tech stack you choose. Thus C++'s "jack of all trades" trait is no longer a major factor in the decision. Meanwhile the lack of a stable ABI starts to feature prominently as a reason not to adopt C++.
Introducing a new ABI in competition with the current ones (e.g. ia32 and x64) would be less destructive than officially abandoning those currently in use.
Seems like a terrible thing to break this late
And an older link:
https://www.auburnsounds.com/blog/2016-11-10_Running-D-witho...
These are some of the ones off the top of my head, there are more. So the fix in these cases is another name, and that has the problem of making the language needlessly more complicated and harder to learn.
Like networking support, serialization for ubiquitous formats like JSON, etc.
Sure as time passed, the non backward compatible C++ would add features not currently in scope for C++, but the radical redesign of the fundamental language is not what this proposal suggests.
Those two languages were created without consideration of backwards compatibility with C/C++ source code and were designed for the same job. It stands to reason that given no constraints of compatibility, you'd get something similar to those languages.
Now obviously, those languages do not have all the features of C++ nor the same design principles. But as soon as you have all the features of C++ with the same principles, you have something so close to C++, that it doesn't make sense to break backwards compatibility.
But: if it's a completely new language (no backward compatibility to C++) - why do we need this? Can't we just use one of those new languages that are already available (Rust, Zig, Odin, Nim, just to name a few).
Would backwards compatibility to "modern C++" make more sense than no backwards compatibility?
There are probably also strong non-rational components, e.g. C++ people would like to keep working on C++, leveraging their existing skills and status, rather than jump to another community.
(btw., since debate initiated, C++ standard attempts on garbage collection too - as well as on many powerful concepts incorporated into C# from here and there - and IL is compiled into machine code before execution, naturally, also making C# really had an intention of making a better but similar C/C++ without its crippling compatibility barriers towards improvements. C++ is more universal still - but considerably less than C - and it is all right, each have advantage here and there. You usually do not work on all use cases anyway! ;) No need to abandon backward compatibility with C++, abandoning will become a new language, we have quite a few already, it is done already!)
C++ compiles to native code via LLVM bitcode.
what if you actually do like templates and class-based OOP ?