Hacker News
points by Krutonium 4 days ago | 0 comments
Maybe a slightly faster std::regex or whatever it's called; apparently it's horrendously slow for no benefit.
[–] forrestthewoods 4 days ago
No. The problem isn’t that std::regex is slow and badly designed. It’s that std::regex exists at all.

C++ is unique in that it defines a spec for STL but not implementation. The result is something that is both overspecified and underspecified.

Including batteries is fine. Including a spec for what the batteries should look like is such a profoundly bad idea that no other major language does it.

[–] klempner 4 days ago
I think this is misunderstanding the problem with std::regex -- the problem isn't so much that it provides a "spec for what the batteries should look like" but rather that it is naturally ABI entangled and so the bad first generation implementations are unfixable given that the committee refused to allow for an ABI break to fix this.

The real problem is the latter: C++ has always had a "you don't pay for what you don't use" as part of its core philosophy but it turns out that doesn't apply if the thing you don't use is ABI stability.

(and, failing an ABI break story, std::regex should have had an implementation that was more PIMPL and less template so it would have fewer ABI issues, possibly followed by a regex2 later that could get more of the compile time bits once implementations were more mature.)

[–] forrestthewoods 3 days ago
I think both are problematic.

I think even if C++ had a periodic ABI break that even a better std::regex spec is fundamentally wrong.

As someone who ships cross-platform I never ever want different platforms to have different implementations for things that are not actually platform specific. Having different implementations of std::string depending on if I’m on windows, Linux, Mac, iOS, Android, PlayStation, Xbox, or Nintendo is a profoundly terrible thing to do.

[–] dizzant 4 days ago
I'm sorry you don't like std::regex. That isn't a problem with C++'s specification practice.

C++'s separation of spec from implementation is clearly functional. There are several major open-source standard library implementations that compete on the basis of performance, ABI stability over versions, quality, etc.

C++'s core ethos is "only pay for what you use". std::regex does this. In my experience, the "problem" with std::regex is that it provides more features by default than most people want, and you pay for using those features. Specifically, std::regex respects the runtime locale. There are good reasons a standard library feature might do this (e.g. it simplifies the interface, it's broadly applicable, etc.), but it's obviously not going to give optimal performance. This is a necessary tradeoff for any standard library.

Locale handling requires dynamic memory allocation, virtual function dispatch, sometimes system calls. Locale handling also prevents some low-level optimizations based on the character encoding. If you need that kind of performance, std::regex probably isn't for you, go grab a non-standard library that suits your needs.

[–] forrestthewoods 4 days ago
locale is a great example of a concept that is catastrophically bad, provides zero value, and shouldn’t exist at all in the spec.

std::regex is so worthless that no one uses it. My codebase gives CI warnings when it’s used. so it’s not even really a problem. It is indicative of a larger problems.

> C++'s separation of spec from implementation is clearly functional.

Your bar of “clearly functional” is is not a compelling or meaningful bar. What a weird fallacy.

C++11 was pretty great and meaningfully modernized the language. The amount of useful good things in each following release got smaller and smaller. Maybe just one or two useful improvements in C++20. Almost nothing in C++23. And now C++26 has failed to pass. It’s grinding to a halt. The biggest recent features such as concepts and modules have been catastrophic failures.

Those failures aren’t all due to my specific complaint of “battery specs are a bad idea”. But “functional” is the lowest possible bar. And one could argue that as a whole isn’t being met.

[–] ameliaquining 4 days ago
I'm confused about what exactly you're arguing for. Is the idea that the standard library should be minimal and then each compiler should ship its own nonstandard "batteries" library?
[–] forrestthewoods 4 days ago
I think the language committee should provide a spec where required (OS filesystem, mutex, etc). And when it is not required they should simply provide a plain bog standard library.

There is absolutely no reason for std::deque to be a specification. The committee should either ship a committee library for std::deque or they should leave it to the community. They can provide a battery or they can not. Providing a spec for a battery that is both over and under specified is the absolute worst possible choice.

[–] ameliaquining 4 days ago
Do you also think the committee should ship a compiler? If not, what's the difference?
[–] tancop 4 days ago
Compilers are complex, platform specific and the architectures behind them can be wildly different. Maintaining a reference compiler would be a lot of work for no real benefit.

The standard library on the other hand is a library. It's almost always implemented as plain C++ without much platform specific code. ISO could take an existing free licensed implementation and declare it as the standard. Of course anyone is free to make their own competing one, it just has to always match the official library's behavior.

Writing a spec instead of code is just creating duplicate work and compatibility issues any time the spec is unclear.

[–] forrestthewoods 4 days ago
The difference is that I can trivially write a std::deque container that runs under any compiler that implements the C++ spec.

Why on earth would I want a different implementation of std::deque on each platform I use because the compiler team needed to provide one? It’s madness!

[–] imtringued 4 days ago
The standard library would just be C++ code that a compiler turns into machine code.

I remember a language where the core language types, including primitives and a bunch of keywords, were actually defined in the standard library and the compiler just special cased support for the types in the standard library for optimization purposes.

Your loaded question feels very silly from that perspective.

[–] stingraycharles 4 days ago
Ranges need work as well, there’s lot of opportunity to improve things there.
[–] ameliaquining 4 days ago
The primary reason this hasn't happened is that it'd break C++'s de facto stable ABI (even though officially there's no such thing). For a lot more context, see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p20... and https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p18....

Spoiler alert: The option described as "the sort of leadership failing that I pray we can avoid" is what ended up happening.

[–] imtringued 4 days ago
I'm pretty sure that it is too late for C++ to break the "stable ABI" they already have.

It's not too late to introduce an actual stable ABI though. However, it's not too late to do that in Rust either so I don't see the point in a language specific ABI in the future anyway.

[–] charcircuit 4 days ago
Who cares about the ABI when the current ABI has a bunch of bad issues with it. For any backwards compatibility thing there is always AI that can rewrite old code.
[–] bluGill 4 days ago
ABI isn't just what rewriting code. Even if you rewrite the code, you still have to test it, certify it, and so on. Because C++ has an ABI, I mix code that is already built with new code and only recertify my new code.

It is a huge pain, and quite honestly, most of the reasons I have to maintain ABI are political and thus not up for a technical discussion, but I still have to do it.

[–] charcircuit 4 days ago
You can make linking against different abi not allowed. And all the stuff you are complaining about can be handled in <24h by an AI agent (swarm).

It's just bureaucracy preventing it, not the actual work needed by people.

[–] NekkoDroid 4 days ago
The compiler vendors care. It is also the reason why C++ never actually had a GC, even if the standard had it specified (and removed it with C++23).
[–] failbuffer 4 days ago
As an avid non-C++ programmer, can I suggest doing something about the build/module system? I shouldn't have to learn a separate language (CMake) and figure out the right include files to pull in a library.

I mean, I mainly say this to joke because it's probably unfixable at this point, but whenever I mess with it, I'm struck by how hard/opaque C++ makes this problem compared to most other languages.

[–] weitendorf 4 days ago
Like most things in C++, everybody who uses it professionally has already solved this in one way or another in a way that works for them.

So this is only a painful problem for people who don't use C++ very much, and whatever centralized, official solution to builds would probably not really get adopted by most C++ shops.

Because of that, even if it were solved, it's likely that it would only solve the problems that people who don't use C++ very much, or who don't invest in build tooling, want fixed. Which is basically what Make was originally.

IMO it's best to think of C++ as a language only. Because of Microsoft/Sun/the web/etc and the desire to win over developers' business, a lot of newer languages are designed to be batteries-included with official first party tools that are supposed to be the canonical way to solve that particular class of problems. Those languages are essentially products or brands that are part of their benefactors' grand designs for specific business or career outcomes.

C++ by contrast has multiple competing implementations for basically anything you can think of, and isn't someone's "business" the way most other languages are, so there's no reason to make the out-of-the-box DX better or standardize the tooling. Nobody has any reason to want you to write C++ instead of something else.

[–] jjmarr 4 days ago
There is no standard build/module system or way of dependency management. Unfortunately, this is because there's no standard compiler with standardized flags so C++ would also have to standardize compiler behaviour too.

Large FAANGs that would be incentivized to change it don't care because they have their own in-house C++ build systems like bazel (Google) or buck2 (Meta) that are far faster than cmake (distributed compilation and caching) but require huge teams to maintain. Unfortunately, this distributed compilation and caching layer is something that many other languages don't have since their build systems are made for single devs building locally.

Also the dependencies can be added in a myriad of ways. Your build system can download them, your meta-build dependency manager can find them (Conan), your Linux distro can provide them (system libraries), or maybe you just download an object file from a website + some headers and are told to figure it out yourself (many commercial packages like cuda or steam).

[–] 4k0hz 4 days ago
The (lack of any) build system is actually nice for flexibility. You can lay out files however you want, link together random object files without extra work, use your own weird dependency tracking, etc. Obviously it's not super easy to get started with compared to Rust et al. but choosing C++ in the first place implies some need for industrial grade features or unusual setup.
[–] hdjrudni 4 days ago
Sure, but JS has a myriad of choices too and yet we mostly agree on node_modules, package.json and npm (the repo). Big companies or weirdos are free to swap any of those with something else if they want but the little guys have something standardish if they don't want to inflict too much pain upon themselves.
[–] rerdavies 3 days ago
Personally, I find node_modules and package.json completely terrifying. A solution teetering on the brink of a catastrophic implosion. I have a moderate sized project that pulls in several hundred dependencies and dependencies of dependencies, any one of which could contain a supply chain attack when I upgrade my dependencies. Which I must do. Upgrading is not an option; but it's only a matter of time before I get hit.
[–] bluGill 4 days ago
As a C++ programmer. No, you cannot!

C++ is used for large, very, very, very, very complex problems. Language-specific build systems always like to assume all the world is their language. But not all my world is C++, just 99% and that last 1% is all kinds of weird, screwy things that require a very complex build system. CMake is up to the task, in part because CMake is used for building more than C++ and so they've thought a little bit about the issues I have.

Anyone who says CMake and C++ are complex languages is utterly completely wrong. Sure, by comparison to something better designed, they're a little more complex, but we're only talking a little bit. Meanwhile, I have tens of millions of lines of code to deal with. My real complexity isn't the language, it's my code and that is far greater than all these little complaints people have about the language complexity.

[–] GuB-42 4 days ago
The lack of a universally accepted "good" build/module system like npm, mvn, cargo, etc... has the side effect of limiting the tendency of relying on way too many dependencies, and also limits supply chain attacks.

I mean, it is a real problem, it is making life hard on developers for no good reason, but sometimes, artificial friction can work against some anti-patterns. Similar in spirit to "chaos engineering".

[–] ameliaquining 4 days ago
It's probably possible to improve things here, but it's likely best done as a separate open source project.
[–] failbuffer 4 days ago
I like how this post got upvoted by people who share my frustration and then downvoted by fans trying to cope for a build/packaging experience from the last century.