2 ms·
if (customer_should_get_charged_00001()) { account += 0.00001; } It wasn't my example to start, but I'll roll with it. The bug, of course, is that
by tedunangst 17y ago
if (customer_should_get_charged_00001()) {
account += 0.00001;
}
It wasn't my example to start, but I'll roll with it. The bug, of course, is that we're adding and not subtracting.
The more obvious example where somebody has 0.01 dollars and it gets put in a cents variable, turning into 0.0001 dollars, is also easily solvable with the C++ type system.
- eru 17y agoFor a serious accounting package, I would wrap up all money calculations, in such a way that you can't get away from double ledger accounting. So no money would ever be lost or created and all the flows are traceable.
- tedunangst 17y agoAgain, I don't see how that's anywhere near difficult in C++. This discussion doesn't seem to be going anywhere, especially since there was never a real bug to start with. I'm just annoyed that every time someone even mentions a (fictional!) bug, the problem is "using C++".
- eru 17y agoOh, sorry. I just replied to your comment doubting the use of type systems. I did not want to make a statement about C++. I guess you could make C++ dance, if you tried and were smart enough.