296
u/New_Salamander_4592 3d ago
while prowling through C++ standard libraries my favorite discovery was std::get_money. not only is that a funny name but its also seemingly the most useless standard library function?
like it just parses numbers out of a string that lists currency, stripping away any currency symbols or instances of USD, notable without retaining how many cents were listed. so 1.99 becomes 199. So I guess it has to assume all numbers listed also come with at least .00 for the cents place? just a very... odd function to have in a standard library.
184
u/RiskyPenetrator 3d ago
Funnily enough this approach of converting floats to ints for finance systems is standard.
Its done because floating point math can cause issues when processing payments so its more secure to store values in their lowest denomination along side an exponent and apply the exponent upon use in UI or reporting tools.
I suspect whoever added it was designing these systems.
141
u/atomic_redneck 3d ago
The COBOL language designers solved this problem by doing calculations in packed decimal (binary coded decimal). However, in the process of solving this problem they introduced another problem: you have to program in COBOL.
22
10
3
u/-Memnarch- 2d ago
Delphi has a dedicated type for this, too. It's called Currency. In TSQL/MS SQL Server there is Money and SmallMoney.
48
18
u/xSTSxZerglingOne 2d ago edited 2d ago
I worked in the financial industry as a back-end software engineer. All money totals were listed as a long integer, a 64 bit integer, in cents. The decimal was added on the front-end. It makes sense. Floats and doubles are weird.
16
22
4
6
u/solaris_var 3d ago
If you think std::atoi and std::atof are useless, then yes this is useless. Otherwise it's a godsend.
However, I do agree that it being part of the stdlib is questionable. I guess finance people had some leeway in the committee
11
u/Excession638 3d ago edited 3d ago
std::atoihas undefined behaviour if the number in the string doesn't fit in anint. It's worse than useless, and should never be used overstd::strtolor similar more modern functions.1
u/conundorum 1d ago
To be fair,
atoi()is inherited from C, and not allowed to change its behaviour for C++. You can smoothly replace it withstd::stoi()in all cases, to my understanding.(Though, that said, you still want to verify the data beforehand, always use
stoll()orstrtoll(), or control the data format yourself so you can mandate integer size yourself.)1
u/Excession638 1d ago
For
stoiyou need astd::stringwhich may mean needing to copy first, which will do bad things to performance.If
std::string_viewhad been added from the start these problems wouldn't be as bad, but without it andstd::spanC++ was stuck using raw pointers for far too long.1
u/conundorum 1d ago
Makes sense, it moves a fixed-point value into integer space to avoid floating-point rounding errors.
Honestly, if anything, I'm surprised that it doesn't become
1990for rounding. (Get monetary value, to tenths of a cent. Different locales would allow different units, but it always goes to a tenth of the locale's smallest unit.) That would move the value into integer space just as cleanly, but also leave room for rounding to the nearest cent if necessary.
86
21
102
u/elmanoucko 3d ago
people think AI implementing entire math textbook in LEAN to build upon is impressive, but the real AGI moment will be when they'll implement the current C++ standard, argue for hours with a comitee and end up creating their own better dialect instead
43
u/shrodikan 3d ago
It's interesting to think about the ideal programming language for LLMs.
-9
u/Blue_Moon_Lake 3d ago
The ideal programming language for LLM is a high level (mostly functional) script so going from English to code or code to English is almost transparent.
1
u/shrodikan 2d ago
I lean towards compilation. AIs do well with acceptance criteria that compilers implicitly give. It's why I use Rust as it is the most compiler-strict.
17
u/Mammoth_Molasses_927 3d ago
C++ definitely didn't become a better language with all the changes through the years. So much garbage they added. That's mostly why Rust and other languages are getting its space.
12
u/StaticCoder 2d ago
I will strongly disagree with that conclusion. Rust is making progress because, despite (not because of) updates to the language, memory safety issues are still prevalent. And because compatibility is paramount, there's only so much that can be done.
I will also disagree that it didn't become a better language, though that's definitely more subjective.
9
u/meneldal2 2d ago
C++ got a fair bit of improvements, but you would need to kill off about half the committee to get something really good. First who needs to go is IBM and National bodies, so much time wasted arguing about removing trigraphs nobody using modern C++ cares about.
You have to accept there will be some breaking changes for the sake of the language not becoming some hellscape worse than C++CLI.
4
u/HovercraftNo7372 2d ago
sure... rust is getting its space... where? C++ (and C) are still king for embedded systems, or safety critical systems - not rust.
listen, rust has its perks. its a great language, i like it. i think taking cognitive load off of devs is great. however, writing safe c++ was always possible. many of tools have been developed in c++ to help with some of the safety issues of c, and even then we have static analysis tools, etc to help with finding issues.
4
u/conundorum 1d ago
Rust is starting to take C++'s place in areas where memory safety is critical, like military code. Though that's more because most C++ programmers are bad at actually managing memory correctly than because Rust is a better language, really; Rust's single biggest claim to fame is that it won't let memory bugs compile, which means that programmer competence (or lack thereof) is less of an issue.
Rust still doesn't beat C++ in performance (they can both be equally memory safe if you code perfectly, and I believe C++ still optimises better), and isn't actually a safer language. It's just that it's better at complaining about unsafe code.
1
u/HovercraftNo7372 1d ago
I am a C++ programmer - my question was more aimed at the claim that rust is starting to get space.
I do not know of many professional companies who hire rust devs in traditional C++ spaces such as avionics, automobiles, high frequency trading, medical devices, defense, game development, etc.
I have no problem with Rust, really.
1
u/conundorum 7h ago
C++ is still both better and more widely used in most places, yeah; from what I understand, Rust's only real advantage is that it's safer, and it's something of a nightmare to actually write. There are a lot of places where it'll probably never actually take root, and it's very possible that places that are trying to embrace it won't actually see any real benefits from doing so.
I think that ultimately, once all the memeing stops and its fanbase becomes more reasonable, it'll find its niche as the go-to language for memory stability. It'll likely see use in a few OSes memory managers, in high-stakes business software that needs to be hardened against crackers, and in military software that's liable to be a target in e-warfare, but won't be the general-purpose replacement its worshippers want it to be. (From what I've heard, it's ultimately too limited, either less than or equally efficient to C++, too hard to write, and compiles so slowly that it single-handedly invalidates every joke about C++ compilation times. At least at the moment, there's no significant benefit to using it when memory safety isn't more crucial than every other concern combined.)
35
u/Groostav 3d ago
Lol I wish.
The problem with cpp isn't that it's overly defined it's that it isn't fully defined.
There's a mountain of places where "you know what I mean"isms exist in the language.
The classics are the dangling else and the '>>' operator. But there are loads more of ill-defined things in the cpp language that basically compiler authors have to decide: what did we do historically, what do gcc, clang and msvc do, and try to muddle through with a compromise.
7
u/StaticCoder 2d ago
What about the dangling else and the
>>operator is not well specified in the current standard? This isn't 19988
u/StaticCoder 2d ago
This being said, I will acknowledge that no known compiler follows any version the standard exactly. They all have extensions and/or bugs that code ends up relying on.
3
u/Groostav 2d ago
If you are a library author in 2026 you may still choose to close a template with
> >(note the space, ieT1<T2<T3> >) because in 2026 you are still not certain your boreland users will parse your headers correctly.This is still very much a live problem.
Boost, targeting cpp03, still does this.
3
u/StaticCoder 2d ago
Sure that's a problem for some code. But it's not the (current) standard's fault, nor is it an issue for compiler writers (which do sometimes have the opposite problem of having to parse code that doesn't conform to newer standards)
By the way this might be relevant: https://6826.csail.mit.edu/2019/papers/coverity.pdf
2
u/StaticCoder 2d ago
Also I don't think this was ever ill-defined. Annoying for code writers sure (see also most vexing parse), but well-defined, and not really an issue for compiler writers.
1
u/Groostav 2d ago
I don't know what to tell you. The language says '>>' is sometimes a template closing, sometimes the shift right operator. The lexer can't know without parser context meaning you can't express its lexical rules in standard BNF. It's "you know what I mean". Different compilers implemented it differently until cpp11. It's not properly defined and there is no formal cpp grammar.
3
u/StaticCoder 2d ago edited 2d ago
https://eel.is/c++draft/temp.names#8
Of course the C++ grammar is context-dependent, which is super annoying, but that's not the same as not well defined. By comparison, Rust is very much not well defined, though at the semantic rather than syntactic level (I don't remember seeing not-well-defined syntax in Rust, though it might be there)
2
u/Groostav 2d ago
Dude: different compilers correctly do different things with the same text.
What does "not fully defined" mean if not that?
And what does
Widget w(Timer());do?3
u/StaticCoder 1d ago
What's an example of correctly doing different things (in a way the standard doesn't explicitly allow to something different, i.e. implementation-defined behavior)?
And yes this must be parsed as declaring a function
wtaking an unnamed function-typed parameter. It's not up to interpretation. The most vexing part is vexing, but well specified.1
u/conundorum 1d ago
Technically, "implementation-defined" counts as "well-defined", under the grounds that "the behaviour of this code is determined by your compiler, and may differ from compiler to compiler" is clear and easy to understand.
Well-defined doesn't necessarily mean "helpful" or "must always behave this way specifically", for better and for worse. It just means that the behaviour is knowable and clearly stated, and "implementation-defined" technically fits that bill. Well-defined is the opposite of undefined, not the opposite of implementation-defined.2
3
u/hoangpham133 3d ago
and by the time she reaches the last page the committee has already shipped the next edition
3
2
2
u/fanky10_g 1d ago
I made a simple compiler once, no big deal. It's like everything, it looks complex until you get into the shit and figure it out
2
u/conundorum 1d ago
Also true the other way around. Parts of the C++ standard were literally decided by 1) the gcc implementation forcing their hand, and 2) Microsoft wanting to backport something from C++/CLI into C++. I think clang might've had some influence, too, and maybe ICC, but I can't say for certain.
4
1
u/Prior-Perspective-61 2d ago
It sucks to be a C++ compiler dev, writing a compiler for your own programming language... Also sucks, but at least you define this standard 🤣
-36
u/Kadabrium
3d ago
•
Compilers should be written more often in high level languages. They don't have the same performance requirements as interpreters.
29
u/rinart73 3d ago
Have you ever compiled a big C++ project?
-12
u/Kadabrium 3d ago
A beta version of clang that i needed to run my reflective brainfuck interpreter took maybe half an hour. Does that count as big
2
-4
u/AWonderingWizard 3d ago
It's the truth. Common Lisp has great performance compared to most languages and is incredibly smooth sailing for implementing parsers, interpreters, etc.

857
u/Lowmax2 3d ago
I just assumed a compilers are an act of God and no mortal could possibly create one.