6 ms·
As a long time user of C++, I want to propose a question: do we think C++ will ever reach a point where it is significantly ergonomic and safe enough to use (in
by ratmeadow 1y ago
As a long time user of C++, I want to propose a question: do we think C++ will ever reach a point where it is significantly ergonomic and safe enough to use (in comparison to e.g. Python or Rust) via adding new features?
I've used C++ for so long and I'm a good way into thinking that the language is just over. It missed its mark because of backwards compatibility with fundamental language flaws. I think we can continue to add features - which are usually decent ideas given the context, kudos to the authors for the effort - but the language will decline faster than it can be fixed. Furthermore, the language seems to be continually becoming harder to implement, support, and write due to the constant feature addition and increase in semantic interconnectivity. To me it's almost mostly a theoretical exercise to add features at this point: practically we end up with oddly specced features which mostly work but are fundamentally crippled because they need to dodge an encyclopedia of edge cases. The committee are really letting the vision of a good C++ down by refusing to break backwards compatibility to fix core problems. I'm talking fundamental types, implicit conversions, initialisation, preprocessor, undefined / ill-formed NDR behaviour. The C++ I'm passionate about is dead without some big changes I don't think the community can/will handle.
- bluGill 1y agoThat doesn't matter - it cost a billion dollars to write the current project I work on. There is no way I can ask for that much to rewrite it all in whatever. Thus we are stuck on c++ which was the best choice 15 years ago. Anything that makes new code easier to write is great help. sure we are looking at options - but rust and c++ don't interoperate well (c api is too limiting). D was looking interesting for a while but I'm not sure how it fits (d supports c++ abi)
- AnimalMuppet 1y ago60 million dollars a year in development for 15 years? What are you working on?
- goalieca 1y agoThere are many large projects with ~1000 engineers will end up costing more than that.
- paulddraper 1y agoChrome doesn’t fit those figures exactly but is close.
- Yoric 1y ago...and some components are being rewritten in Rust, if I recall.
- steveklabnik 1y agoYep: https://news.ycombinator.com/item?id=45140641 https://news.ycombinator.com/item?id=45140641
- bluGill 1y agoSome small parts are. After several decades those small parts will add up but for now rust is almost nothing overall.
- foobar10000 1y agoMany large financial operations - HFT such as Hudson River Trading or Optiver or IMC or Citadel, or the big C++ systems in the banks - 200-400 developers working on an ecosystem of components can easily clear that.
- pjmlp 1y agoEasy to reach these numbers. Many developers never do the math of what their salaries actually cost. We in consulting are deeply aware of the impact mapping hours and days into money, plus license and support costs, and infrastructure. Hence why I dislike all those "I rewrote X into Y", great and how many thousands did that fun endeavour cost to the employer?
- bluGill 1y ago
- tialaramex 1y agoThere's an evolutionary process at work, so it's not really about that rewrite decision, it arguably made sense fifteen years ago to pick C++ - yeah C++ will still exist in say 2040 just like COBOL still exists today and I don't trust anybody arguing otherwise. But whether investing in C++ still makes sense is a different question. That might influence career decisions, and what new projects should do even though a choice fifteen years ago was correct, and it also impacts how to manage your existing project. We do these night walks out in the Forest. 2-4 hours in the countryside, when it's still pleasantly warm but no sun. Owls, bats, insects and occasionally horses or deer that were not expecting humans - no sudden moves because horses or deer can easily kill you by mistake if startled. Without much light it's hard to be sure whether you're on a trail and if you've reached the fork you expected or just a place where there's a tree in the way. So, it's not rare to realise we've made a mistake. Now, if you realise after 5 minutes you can "just" backtrack. It's nowhere near as easy in darkness, but it's possible and arguably preferable. However it is also possible to realise after say an hour. You thought you'd be in a clearing, on a ridge, but you're a mile away approaching a river crossing. Oops. It is usually not correct to retrace your steps in this case, you need a new plan taking into account what you know now about your position.
- quotemstr 1y ago> As a long time user of C++, I want to propose a question: do we think C++ will ever reach a point where it is significantly ergonomic and safe enough to use (in comparison to e.g. Python or Rust) via adding new features? Memory safety semantics aside (needed and will be disruptive, even if done gradually) --- You could get 80% of the way to ergonomic parity via a 1:1 re-syntaxing, just like Reason (new syntax for OCaml) and Elixer (new syntax for Erlang). C++ has good bones but bad defaults. Why shouldn't things be const by default? Why can't we do destructuring in more places? Why is it so annoying to define local functions? Why do we have approximately three zillion ways of initializing a variable? You can address a lot of the pain points by making an alternative, clean-looking "modern" syntax that, because it's actually the same language as C++, would have perfect interoperability.
- dwattttt 1y agoIt's an interesting proposal. A new grammar which can express everything (legal) that C++ can, can be automatically translated, but can avoid being ambiguous (https://stackoverflow.com/a/794083 https://stackoverflow.com/a/794083). You'd have an existing language with a new syntax; it can perfectly interact with existing C++ code, but you could make those suggested changes, and could also express things in the new syntax that couldn't be done in the old one. EDIT: taking an example elsewhere in this thread; taking an address of an uninitialised variable and passing it to a function. Today the compiler can't (without inter-procedure analysis) tell whether this is a use of uninitialised data, or whether it's only going to write/initialise the variable. A new syntax could allow you to express that distinction.
- aw1621107 1y ago> You can address a lot of the pain points by making an alternative, clean-looking "modern" syntax that, because it's actually the same language as C++, would have perfect interoperability. Sounds like Herb Sutter's cpp2/cppfront: https://github.com/hsutter/cppfront https://github.com/hsutter/cppfront
- deleted 1y ago[deleted]
- CoastalCoder 1y agoOn the bright side, any sufficiently motivated team can fork the language to try out ideas like yours. Perhaps a better language could even get some traction without major corporate sponsorship. I think (?) rust and zig are examples of that.
- aw1621107 1y ago> Perhaps a better language could even get some traction without major corporate sponsorship. I think (?) rust and zig are examples of that. Rust might not count depending on whether you count Mozilla's sponsorship a major corporate sponsorship.
- ghosty141 1y agoAbsolutely spot on in my opinion. Also things often just don’t compose well. For example if you have a nested class that you want to use in an unordered_set in its parent class then you just can’t do it because you can’t put the std::hash specialization anywhere legal. It’s just two parts of the language which are totally valid on their own but don’t work together. Stuff like this is such a common problem in c++ that it drives me nuts
- Kranar 1y ago>For example if you have a nested class that you want to use in an unordered_set in its parent class then you just can’t do it because you can’t put the std::hash specialization anywhere legal. This is not true. From within your parent class you use an explicit hashing callable, and then from outside of the parent class you can go back to using the default std::hash. The result looks like this: struct Foo { struct Bar {}; struct BarHasher { std::size_t operator ()(const Bar&) const noexcept; }; std::unordered_set<Bar, BarHasher> bar_set; }; namespace std { template<> struct hash<Foo::Bar> { std::size_t operator()(const Foo::Bar& b) const noexcept { return Foo::BarHasher()(b); } }; } The std::hash specialization at the end is legal and allows other users of Foo::Bar to use std::unordered_set<Foo::Bar> without needing the explicit BarHasher.
- jb1991 1y agoThe example you mentioned here suffers from a design program, not a language problem.
- saghm 1y ago> do we think C++ will ever reach a point where it is significantly ergonomic and safe enough to use (in comparison to e.g. Python or Rust) via adding new features? This is an interesting perspective to me, because my view as someone who's been using Rust since close to 1.0 and hasn't done much more than dabbled in C++ over the years is basically the opposite. My (admittedly limited) understanding is that this has never really been a goal of the committee, because if someone is willing to sacrifice backwards compatibility, they could presumably just switch to using one of those other languages at that point. Arguably the main selling point of C++ today is the fact that there's a massive set of existing codebases out there (both libraries that someone might want to use and applications that might still be worked on), and for the majority of them, being rewritten would be at best a huge effort and more realistically not something going to be seriously considered. If the safety and ergonomics of C++ are a concern, I guess I'm not sure why someone would pick it over another language for a newly-started codebase. In terms of safety, Rust is an option that exists today without needing C++ to change. Ergonomics are a bit less clear-cut, but I'd argue that most of the significant divergences in ergonomics between languages are pretty subjective, and it's not obvious to me that there's a significant enough gap in between Rust's and C++'s respective choices that warrant a new language that's not compatible with C++ but is far enough from Rust for someone to refuse to use it on the basis ergonomics alone. It seems to me like "close enough to C++ to attract the people who don't want to use Rust but far enough from Rust to justify breaking C++'s backwards compatibility" is just too narrow a niche for it to be worth it for C++ to go after.
- ratmeadow 1y agoIt's true that without backwards compatibility concerns, Rust looks like a great alternative. However I think C++ still has some things going for it which may make it a useful option, assuming the core issues were fixed. C++ gives ultimate control over memory and low level things (think pointers, manual stack vs heap, inline assembly). It has good compatibility with C ABIs. It's very general purpose and permissive. And there are many programmers with C++ (or C) knowledge out there already. Further, I think C++ started on its current feature path before Rust really got a big foothold. Consider C++ has been around a really long time, plenty long enough to fix core features. Finally I reckon the whole backwards compatibility thing is a bit weird because if the code is so ancient and unchangable, why does it need the latest features? Like you desprately need implicit long-to-int conversion but also coroutines?? And for regular non-ancient code, we already try to avoid the problematic parts of C++, so fixing/removing/changing them wouldn't be so bad. IMO it's a far overdone obsession with backwards compatibility. Of course without a significant overhaul to the language you'd probably say "screw it" and start from scratch with something nicer like Rust.
- isaacremuant 1y agoVery little signal to noise in your post. It's widely used and you can do so effectively if you need it as know what you're doing.
- kachapopopow 1y agoI just don't see a reason to use c++ anymore when rust does quite literally, everything better. For prototyping, hacking, firmware and native interfacing though? c++ any time of the day.
- TuxSH 1y ago> quite literally, everything better Like retained mode GUIs, games, intrusive containers or anything that can't be trivially represented by a tree of unique_/shared_ptr?
- kachapopopow 1y agokinda don't get me wrong c++ is useful, however, rust is a platform language and should be used as such, like c++, but much further than that. modern games are almost never made in a native language, but rather on a language on top of it, be it squirle, lua, blueprints, c#, wasm, javascript, state trees, binary trees, decision trees...
- jibal 1y agoNo one got you wrong ... you claimed that you couldn't see any reason to continue to use C++. That was a lie.
- jb1991 1y agoWriting cross-platform code between CPU and GPU, a very common occurrence, is certainly one reason to use C++.
- kachapopopow 1y agogpu-rs (hopefully) will do it better including all the sub-projects around it.
- halfcat 1y ago> rust does quite literally, everything better > (hopefully) will do it better So, not quite literally everything
- anon-3988 1y agoBased on Hyrum's Law (since they preserve backward compatibility), any line of "modern" C++ code is also basically just C code. There's no way around this. I don't think there will ever be a point where C++ is so safe and rigid that it feels comfortable to write in without thinking of the 100s different ways the languages screws you over. They love to say C++ is for everyone but it is clearly not. Only wizards and nerds burdened by sunk cost fallacy is willingly writing these modern C++ code. I personally just use C++ as a "nicer" C.
- wffurr 1y ago>> The committee are really letting the vision of a good C++ down by refusing to break backwards compatibility to fix core problems IIUC this is what Profiles are. It’s an opt in source file method to ban certain misfeatures and require certain other safe features.
- Kranar 1y agoSafety profiles don't exist and there are so many issues with them that it's unlikely they will ever get added to the language. For example, you mention how it's a method applied to a source file, but C++ doesn't have the concept of a source file, it only knows about translation units. But then the problem becomes where exactly do you opt-in to this feature? If you do it in a header file then this can result in a function being compiled with the safety profile turned on in one translation unit and then that exact same function is compiled without that safety profile in another translation unit... which ironically results in one of the most dangerous possible outcomes in C++, the so-called ODR violation. If you don't allow safety-profiles to be turned on in header files, then you've now excluded a significant amount of code in the form of templates, constexpr and inline functions.
- wffurr 1y agoThere's a new attempt at safety profiles. I'm not enough of an expert or read in enough on this proposal to answer your detailed questions, but there's a lot of words by Sutter and Stroustrop on the proposals: Stroustrop, 2023 presentation: https://open-std.org/JTC1/SC22/WG21/docs/papers/2023/p2816r0.pdf https://open-std.org/JTC1/SC22/WG21/docs/papers/2023/p2816r0... Sutter, 2025 committee paper: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3081r1.pdf https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p30... Sutter, 2024 blog post: https://herbsutter.com/2024/03/11/safety-in-context/ https://herbsutter.com/2024/03/11/safety-in-context/
- jandrewrogers 1y agoThe saving grace of C++ is that 80% of my complaints are really about the standard library rather than the language itself. I can replace the standard library with something else more consistent and modern without regard for legacy compatibility, and many people do. Most of the rest of my complaints could be addressed by jettisoning backward compatibility and switching to more sensible defaults. I realize this will never happen. C++ still has some unique strengths, particularly around metaprogramming compared to other popular systems languages. It also is pretty good at allowing you to build safe and efficient abstractions around some ugly edge cases that are unavoidable in systems programming. Languages like Rust are a bit too restrictive to handle some of these cases gracefully.
- Kranar 1y agoThere is a version of C++ that adds complete memory safety to the language by adding features to the language in a way that preserves complete backwards compatibility with existing C++ source code. That version of C++ is called Circle/Safe C++, it represents a monumental amount of effort that was written by a single individual, and it's a complete disgrace that the C++ committee has informally shut the door on that individual: https://safecpp.org/draft.html https://safecpp.org/draft.html
- LoganDark 1y ago> it's a complete disgrace that the C++ committee has informally shut the door on that individual What do you mean?
- Kranar 1y agoThe committee very politely showed him the door.
- LoganDark 1y agoYes, I got that much, but I'm curious to see what happened. Do you have any links about it?
- aw1621107 1y agoThe interpretation is probably up for some debate especially since meeting details are not public, but some relevant links are: - The P3390R0 Safe C++ proposal and the related vote in the 2024-11 Wrocław meeting: https://github.com/cplusplus/papers/issues/2045 https://github.com/cplusplus/papers/issues/2045 - The adoption of the paper P3466 R1 (Re)affirm design principles for future C++ evolution at the same meeting, which contains language which can be interpreted as preemptively foreclosing a Safe C++-style approach: https://github.com/cplusplus/papers/issues/2121 https://github.com/cplusplus/papers/issues/2121
- 1y ago
- benreesman 1y agoI dramatically prefer modern C++ to either of Python or Rust in domains where it's a toss up. It's really nice these days. Like any language that lasts (including Python and Rust) you subset it over time: you end up with linters and sanitizers and static analyzers and LSP servers, you have a build. But setting up a build is a one-time cost and maintaining a build is a fact of life, even JavaScript is often/usually the output of a build. And with the build done right? Maybe you dont want C++ if youre both moving fast and doing safety or security critical stuff (as in, browser, sshd, avionics critical) but you shouldnt be moving fast on avoinics software to begin with. And for stuff outside of that "even one buffer overflow is too many" Venn? C++ doesn't segfault more than either of those after its cleared clang-tidy and ASAN. Python linking shoddy native stuff crashes way more.
- galangalalgol 1y agoI agree that python is often painful to get right. But asan really, doesn't help you unless you have tests that cover the path with the mistake it would catch. Safe rust doesn't segfault ever. Unsafe rust is still easier to get right for me than c, but mostly because c targets weird architectures with weird rules. Rust is also easier for me to develop fast in than either python or c++. For c++ that is because fragmented package management and build systems, and syntax that lets me express things I don't want to, like a race condition. Python slows me down because the duck typing can't help me reason about my design like static explicitly converted types can.
- jjmarr 1y ago> Safe rust doesn't segfault ever. https://github.com/Speykious/cve-rs https://github.com/Speykious/cve-rs > That is why cve-rs uses #![deny(unsafe_code)] in the entire codebase. There is not a single block of unsafe code (except for some tests) in this project. > cve-rs implements the following bugs in safe Rust: * Use after free * Buffer overflow * Segmentation fault
- quamserena 1y agoRust’s borrow checker has been mathematically verified to be always sound.[0] These are edge case implementation bugs that user code is unlikely to touch. I have never had a soundness hole/segfault from safe Rust, and I am not aware of any code in the wild which stumbled into one of these soundness holes either. The main bug is [1], which is very contrived lifetime shenanigans that wouldn't appear in real code. Some bugs [2] are miscompilations coming from the LLVM side. If implemented perfectly, all safe Rust code would be sound, but of course all programs have bugs. The important part is that 99.9% of safe Rust code is sound. [0] https://hal.science/hal-01633165v2/document https://hal.science/hal-01633165v2/document [1] https://github.com/rust-lang/rust/issues/25860 https://github.com/rust-lang/rust/issues/25860 [2] https://github.com/rust-lang/rust/issues/107975 https://github.com/rust-lang/rust/issues/107975
- socalgal2 1y agoI think it's like 50/50. There's been proposals for various things like --perfectly-safe-subset-only (making that up). But there's so much to fix and so much arguing about whether it should actually be fixed or not. I would personally like a safe (and fast) subset that doesn't require me to be vigilant but catches every thing I could do wrong to the same level as rust. Then, like rust, you could remove that flag for a few low-level parts that for some reason need to be "unsafe" (maybe because they call into the OS). There was a good talk from the WebKit team about stuff they did to get more safety. https://www.youtube.com/watch?v=RLw13wLM5Ko https://www.youtube.com/watch?v=RLw13wLM5Ko Some of it was AST level checks. IIRC, they have a pre-commit check that there is no pointer math being used. They went over how to change code with pointer math into safe code with zero change in performance. A similar one was Ref usage checking where they could effectively see a ref counted object was being passed to as a raw pointer to a function that might free the ref and then still used in the calling function. They could detect that with an AST based checker. That said, I have no idea how they (the C++ committee) are going to fix all the issues. --no-undefined-behavior would be a start. Can they get rid of the perf bombs with std::move? Why do I have to remember that shit?
- almostgotcaught 1y ago> I've used C++ for so long and I'm a good way into thinking that the language is just over "no one goes there anymore it's too crowded"
- jb1991 1y agoI have to disagree, I find the language quite elegant if you primarily use modern features. It continues to improve with every new standardization. The old style of writing C++ should indeed die.
- pjmlp 1y agoPython isn't for people that care about performance, and Rust has still lots of work to do to provide any GUI, game engine or GPU framework as ergonomic as C++. Backwards compatibility is what keeps C and C++ relevant, for better or worse. All major languages value backwards compatibility to certain extent. Python was lucky that after Python 2 to Python 3 mess, being the AI scripting language, has turned things around.
- leoh 1y agoReally? I have found the UX stuff with egui to be super ergonomic. It's not "native", though. Trying to do macOS UX with it, I have found, generally sucks (curious if anyone knows of any good libraries). Then again C++ probably sucks for native macOS too. So I really don't think Rust is far off.
- pjmlp 1y agoYes really, because it is nothing like Qt, in IDE integration, tools for designers, or ecosystem from 3rd parties components. C++ sucks for macOS, because it was never a first party language, unless using it via Objective-C++. The only role of C++ in macOS is for drivers, LLVM and being the Metal Shader Language (C++14 with extensions).
- ladyanita22 1y agoAren't apps, core system components et al built in C++? That was my impression.
- pjmlp 1y agoObjective-C, the main difference to NeXTSTEP is that DriverKit changed from Objective-C into C++ with IO Kit, that uses Embedded C++ in a COM like approach. In an homage to NeXTSTEP, the userspace version of IO Kit is named DriverKit. There are some frameworks that might use C++ in their implementations, like Core Audio, however they are exposed to userspace as C APIs and Objective-C frameworks. Hence why Apple nowadays mostly cares about LLVM, clang is good enough for their limited uses of C++. https://developer.apple.com/xcode/cpp/ https://developer.apple.com/xcode/cpp/ https://cppreference.com/w/cpp/compiler_support.html https://cppreference.com/w/cpp/compiler_support.html
- tialaramex 1y agoThe crucial difference isn't technology, as others have described Rust's technology is actually an option for C++ though NIH means the committee will prefer anything else. The real difference is cultural. The difference in API shapes in their respective standard libraries is because of culture not technology. Easy to see example: In C++ the two fundamental sort functions are named sort and stable_sort. In Rust those same two sorts are named sort_unstable and sort, a subtle but crucial safer choice. Or compare C++ vector::pop_back against Rust Vec::pop