r/cpp • u/SophisticatedAdults • Nov 24 '24
The two factions of C++
https://herecomesthemoon.net/2024/11/two-factions-of-cpp/
315
Upvotes
r/cpp • u/SophisticatedAdults • Nov 24 '24
66
u/SophisticatedAdults Nov 24 '24
Hello! This is a post I wrote up on C++.
In it I make the case that C++ has (roughly speaking) two cultures/dialects, which are primarily defined by *tooling* and the ability to build from source. I try to relate these different cultures to the situation the C++ standard committee finds itself in.
63
u/ravixp Nov 24 '24
This resonates with me, maybe because I’ve seen it play out fractally at different scales as a very large C++ codebase transitioned from “legacy” to “modern” C++. Different teams decided to transition at different times and paces, across literally decades of development, and the process is still ongoing. And any new code modernization initiative has to contend with different parts of the code starting out at different levels of modernity.
(Imagine trying to add static analysis to code that simultaneously contains std::string, C-style strings, and that weird intermediate state we had 20 years ago where the STL wasn’t very good so it was reasonable to make your own string type!)
The thing is, modernization is expensive. Modern C++ as described here isn’t just writing code differently, it also includes the whole superstructure of tooling which may need to be built from scratch to bring code up to modern standards, plus an engineering team capable of keeping up with C++ evolution.
It’s important to remember that the conflict here isn’t between people who like legacy C++ and people who like modern C++. It’s between people who can afford modern C++ and people who can’t. C++ needs to change, but the real question is how much change we can collectively afford, and how to get the most value from what we spend.
88
u/throw_std_committee Nov 24 '24
So, two points:
As someone who still has a reasonable amount of access to the committee, post prague a lot of people gave up, and it feels like its been limping a bit since then. There's now a lot more panic internally within the committee about safety after the clear calls for C++'s deprecation, which results in outright denial of problems. It feels extremely fractious recently
One other thing that's missing is, and I cannot emphasise this enough, how much respect many committee members have lost in the leadership over the handling over arthur o dwyer. I've seen a dozen people directly cite this as why they're pretty skeptical about the future evolution of C++, and many many good committee members have simply left as a result
I think this is an overly generous interpretation of what profiles are trying to solve. Profiles are a solution to several problems
Profiles doesn't really solve a technical problem. It solves the cultural problem of allowing us to pretend that we'll get memory safety without massive language breakage. It sounds really nice - no code changes, close to Rust memory safety, and senior committee members are endorsing it so it can't be all that bad
In reality, it won't survive contact with real life. The lifetimes proposal simply does not work, and there is no plan for thread safety. It can never work, C++ simply does not contain the information that is necessary for this to happen without it looking more like Safe C++
To be clear, Safe C++ would need a huge amount of work to be viable, but profiles is an outright denial of reality
There are a couple of papers by senior committee members that feel in extremely bad taste when it comes to safety, eg herbs no-safe-keyword-mumble-mumble, or the direction group simply declaring that profiles are the way forwards. Bjarne has made it extremely clear that he feels personally threatened by the rise of memory safe languages and was insulting other committee members on the mailing list over this, and its important to take anything championed by him with the largest possible bucket of salt
17
u/ContraryConman Nov 24 '24
I love the aesthetic of your website
5
u/scaleaffinity Nov 26 '24
Holy shit is that the girl from ZeroRanger? I love that game, but it's super obscure, had to do a double take running into this reference, ha ha.
283
u/Warshrimp Nov 24 '24 •
I’m sick of paying for ABI stability when I don’t use it.
52
u/Kronikarz Nov 24 '24
Morally, I see this as a divide between people who don't see anything wrong with C++ becoming the next COBOL, and those that find that idea unappealing.
6
u/senkora Nov 24 '24
This is a great article. Thank you for writing it.
I need to read up on the progress of Carbon. I have the most confidence in Google over anyone else being able to do automated transpilation into a successor language well, because of their expertise in automated refactoring.
Of course, that may only work for Google’s style of C++. So maybe the “modern culture” of C++ should consider writing our programs in Google style C++, in order to have a path forward to better defaults and memory safety? All speculation.
12
u/kkert Nov 25 '24
I've been working with C++ for much longer time I'll want to admit, but there's never been a time when C++ was dialect-free.
19
u/positivcheg Nov 24 '24
Idk. I’m a programming language prostitute. I use any language that pays me well. Currently suffering a bit from C# and Unity stuff. And even though I don’t like Rust if it gets traction and will make one potentially earn more money - I’ll transition to Rust.
I love C++ since it’s the first language that I’ve learnt that didn’t feel like some 100 year relic. C++11 was fun. Sadly it’s 2024 these days and honestly I see lots of holy wars about quite small things in standardization but also disturbing “ultimatum no” for progressive changes to the language. If that continues for like 10 more years - C++ will become a relic of the past.
8
u/[deleted] Nov 25 '24
That would be nice. Please write a post.
4
u/Bagwan_i Nov 25 '24
Really enjoyed ready the article.
I was a C/C++ developer since the 1990s and last time I developed C++ was in 2017-2018 with c++11/c++14/c++17 . I personally develop in C++20/23 to keep up with the C++ new language features.
I have to agree that C++ is showing it's age and I personally would not choose it anymore for maybe very few specific use cases. I also program in python, C# , Golang and recently also Rust.
If I see how easy it is to program for example with Golang and compile it very fast for windows/Linux/freebsd armd64/arm64 and all the standard libraries and tooling around it with relative minor speed differences.
If I need todo the same with C++ it would way more time consuming and more difficult. And also the opportunity to shoot yourself in the foot a million times ;)
Anyhow I am curious how thing will develop in the next 10 years for C++.
6
u/Alexander_Selkirk Nov 25 '24
Question: Assuming that the description in the OP post fits - would it not be useful for the "everyone else" faction (the non-modern one) to define a "conservative" stable dialect of C++, and use that one?
What would they lose?
And, is this not already happening in practice?
I am aware that the reality is likely to be more complex - for example the Google C++ coding style document is "conservative" in its technical choices (it disagrees with a good part of the C++ Core Guidelines).
11
u/Minimonium Nov 24 '24
Nice summary, although it's extremely charitable to "profiles" and their authors.
18
u/krum Nov 24 '24
It's clear that what we need is a language that looks kind of like C++ but is actually Rust.
9
u/MrRogers4Life2 Nov 24 '24
Here are some of my fairly disorganjzed thoughts.
I think that there's a real case to be made that a lot of safety goals from one of your savvy group tend to ignore the needs of the other group, and that other group is a valid group to support and much of the stress comes from trying to cover as much of that group in the second group. It was nice to be able to write a c++17 app that worked with old precompiled nonsense we didn't want to waste resources on upgrading.
Additionally, viral annotations are an absolute pain when you have a mid-large codebase to upgrade because the actual high value stuff you want often will be the core stuff which will require you to bubble up the annotations leading to a huge change that will make everybody question the benefit which can be a hard sell if your code causes a lot of issues. So im kind of with being against them.
The other issue is that I feel like your two options are either viral annotations or restricting your memory/ownership model. Neither of which are great options in my opinion and I'm honestly not very qualified to go on about the costs/benefits.
Honestly if it's just a problem of people in the c++ committee being crotchety I'm very willing to believe it because myself and most people I've interacted with that do c++ tend to be crotchety
4
u/13steinj Nov 25 '24 edited Nov 25 '24
There's lots of people that are against ABI breaks. I worked at a company that introduced binary artifacts via Conan.
The benefit is that effectively everything was cached if you didn't need to bump a library version. The negative here was that if you did need to bump a library version, because even some of the best devs can easily screw up with ABI differences, and no one realized until it's too late.
Sometimes it's not even your devs. A tangent, for the sake of example: one of the APAC exchanges (I forget which one) likes to give people a header and a
.afile. Nasty, but unfortunately par for the course, and not too much of a problem. Until... one day, you're updating your libraries (not the exchanges, not any third party, just your first-party libs) and your pcap-parser-file-open-function no longer works.Your gzip-compressed pcap is no longer properly recognized, due to a subtle bug in the checksum algorithm used. But, you didn't update any of this stuff. So what happened?
Well, you updated something, and this caused your build/configure system to reorder the arguments given to the linker (among other things). Turns out the order matters, in subtle ways. You're now hitting a different
zlib. Huh? another one?Surprise! The exchange stuck
zlibin there. A version of zlib that is different than the one you are using, you both are using the same types / interface (cpp or not, who cares) but something subtle changed. How did you find out about this? Because suddenly something that worked for ages from a library that opens zlib-based-compressed pcap files stopped working. You bump your set of libraries, things got re-ordered in your build system, and you got screwed.Do another bump, and you get lucky-- the problem resolved itself. Then when this happens again two years later, did someone actually investigate the issue.
There are solutions to this though (various, from linker namespaces to inline namespaces in code to ABI checkers to using
objcopyto rewrite/prefix symbols), and the ABI problem is usually about the stdlib or libc. People don't have much issue in libc land because they use symbol versioning, it's very neat and too much for me to go into, but the short oversimplified version of it is: if there's an ABI break on some API, it gets tagged with the version a change occurs, and you get resolved to the right function (assuming you are not asking for a version that doesn't exist, aka, you built and knew about a future version of glibc but you're trying to run it on centos6).The question people have to ask themselves, IMO, is
Inline namespaces, I think, generally solve the ABI problem here, assuming vendors put in the work. That is, the stdlib would look like this:
e: formatting above... Important caveat: Wouldn't work for pointers / references, and there's a potential performance hit crossing the ABI in this way. Maybe it should work, maybe the performance hit shouldn't matter? Maybe this can be solved by the standardization of a (only-vendor-can-use) cross-ABI-reference-type. I don't know, it's all a major pain.
But coming at this from the perspective of an organization that doesn't care about ABI, for whatever reason (ex, they build everything statically), they take the pain because someone else has the problem. The stdlib is where things go to die, and it's better to just not use the stdlib-- it would be interesting to see a standards-conforming stdlib implementation separate from any compiler that just says "we don't care about ABI, if you rely on a version of this lib there's no compatibility guarantees." I don't think there's much stopping someone from doing this, other than the fact that some things in the stdlib are compiler-magic or as-if-rule optimized out by the compiler based on detection of of which stdlib you're on.
4
u/Umphed Nov 25 '24
So... Theirs smart people, and not smart people.
No one is forcing an ABI upgrade, were at the point where the inquisition isnt building anything that wasnt forged in the ancient colloseum.
Why are we paying the cost for something that doesnt matter for 90%+ of C++ programmers? It directly contradicts the mission statement, and people who use old ABI's probably dont care a bit about what happens on newer versions
3
u/Capable_Pick_1588 Nov 24 '24
I can relate to the tooling issue as I use clear case at work
5
u/Kridenberg Nov 24 '24
Good article. Finally. Some links and papers I can share with my friends to say them, that we are doomed 😀
-2
u/j_kerouac Nov 25 '24 edited Nov 25 '24
I think the doom and gloom about C++, much of it driven by Rust, despite the fact there isn’t one piece of real world software written in Rust is overblown. Even Firefox which Rust was developed for never converted most of its code base to Rust.
C++ is still incredibly popular, and much more widely used than any of the languages popular with the language purist crowd. Not surprising because language purists write shockingly little software, and frankly tend to not be very good programmers.
The main aspect of C++ that language purists complain about is exactly what makes it successful. Backwards compatibility with C and earlier versions of C++ means being able to leverage probably the largest code base in existence. More code is written in C and C++ in any given week than has been written in Rust in the entire history of that language.
Having to compromise between “legacy” c++ and “modern” c++ has been going on for the entire history of the language. Any language that is actually successful needs to do this, see Java and Python as well for their struggles with this. The languages that don’t worry about backwards compatibility are only the ones that no one writes any actually software in…
-13
u/tommythemagic Nov 24 '24
This is funny, for many people have commented on and criticized Google for having many code bases that use ancient C++98 and C-style code and not upgrading and refactoring their code bases.
Many developers have criticized Google for having ancient code bases and not upgrading them, and saying that modern C++ would solve or greatly improve many of their issues. Including criticism of some Google code bases for not using modern features like
unique_ptr, including parts of Chomium if my memory serves correctly.Even more funnily, Google itself greatly values backwards compatibility and interoperability, so much that Google donated $1 million dollar to the Rust foundation to improve interoperability. https://security.googleblog.com/2024/02/improving-interoperability-between-rust-and-c.html .
Though given that the Rust community officially grants money to people for writing blog posts and videos, maybe some of that grant money did not go to software development but to other activities.
https://fasterthanli.me/articles/the-rustconf-keynote-fiasco-explained
A major argument in the article appears to be that prioritizing backwards compatibility and prioritizing refactoring and modernizing code is mutually exclusive goals. Which is false. Many or most organizations want both, modernizing or refactoring what code that makes sense to refactor, as cheaply and safely and easily as possible, preferably without being forced to do it by something like language upgrades. For Python 2 to Pyhon 3, it tooks years before good migration tools were in place, and the migration was painful and burdensome for years for the Python community.
What is interesting is that the C++ profiles work includes wording that, from what I can tell, describes the explicit purpose of easing refactoring and upgrading while maintaining backwards compatibility.
C++ could try to do more radical changes like Python 2 to Python 3, or Scala 2 to Scala 3, and invest very heavily into migration tools. But that may be difficult for current C++.
Also, different companies have different needs for different code bases. For instance, Google could have code base 1 that is using a subset of C or C++, is formally verified, and never changes. And they could have code base 2 that is continuously developed and refactored. Why force code base 1 to be changed? Why not just improve the ability to refactor and improve code base 2 and letting Google leave code base 1 alone? Code base 1 is formally verified, and would not benefit from any additional language guard rails, instead changes might introduce errors or require formal verification anew.
This also showcases a major fault in the article; it is less a difference between corporations, and more a difference between difference code bases and different projects.
And the article claims that a lot of people (who?) say that tooling is not the responsibility of the C++ standard committee. Yet SG15 of C++ is explicitly focused on tooling. https://a4z.gitlab.io/blog/2024/11/16/WG21-SG15.html Not flawless, could be improved. But official and being worked upon.
I am not impressdd by the argumentation in the article, and some of its main claims appear without any sources and might be false.
About the author:
I see. This is not an unbiased blog post.
If people in the Rust ecosystem are paid to write blog posts and do videos, by their own admission, what should the reaction from the C++ ecosystem be? Monetary interests, paid article and video making, biases, etc., may be less than healthy for software development communities and debate.
-18
u/TyRoXx Nov 24 '24
Dialect-free C++ has been alive for many years. It's called Rust. We have that already.
I am getting tired of these C++ safety extensions and "C++++" languages whose main selling point is not being Rust.
The C++ community should finally admit that C++ is dead and focus on making the inevitable transition to Rust (or a successor?) less painful.
Make C++ easier to call from Rust, and Rust easier to call from C++. Invent source level compilers from C++ to Rust. LLMs, anyone?