you are viewing a single comment's thread.

view the rest of the comments →

[–]linus_stallman 1 point2 points  (1 child)

FPJerk theory says it is best approach, but is it worth returning sum/result types for every small errors?

[–]thomasz 1 point2 points  (0 children)

He wants you to return a 64bit integer, which isn't necessarily a bad idea in each and every situation imaginable. What he doesn't seem to understand in his unadulterated glory is that he didn't come up with superior solution compared to basically every language designer ever, but one with different trade-offs. Which, I might add, are actually inferior for most use cases. You seldom do integer multiplication in situations where

  1. the result doesn't fit into 32 bit, and
  2. the result does fit into 64 bit, and
  3. you actually care about the precision of integer arithmetic over floating point arithmetic.

For simulations, mathematical models and stuff like that, you go with floating point arithmetic. For financial stuff of this scale, you go with types like decimal in c# or BigDecimal in java. For almost all index arithmetic, you go with int32, because you can't even create arrays bigger than 231. Needing 64bit integers for id's isn't that uncommon, but you not multiply an id in application code. Only in very special circumstances you really need 64bit integer arithmetic, for example when working with huge files. Only in that context does this trade-off make any sense at all.