I haven’t been able to find the origins of why the Scala std lib chose to wrap Java’s BigDecimal, rather than enrich its API with extra methods as was done with Java’s String class?
While Scala’s BigDecimal wrapper now carries around a MathContext
, this can’t be the original reason. Git archeology reveals that BigDecimal was already wrapped, and then MathContext was grafted on.
At first glance, the decision to wrap seems unfortunate; it adds memory overhead and reduces compatibility, eg with JDBC. Hence, I’m trying to understand if there was a reason I’ve missed…
If we were starting out now, I’d advocate for:
- Use Java’s BigDecimal bare
- Add extension methods to make the API more convenient
- Include extension operations that take a
MathContext
implicitly