Thursday, August 30, 2007

Decimal syntax

On this topic, Danny Coward recently referred to a limited form of operator overloading specifically for BigDecimal. Good to know this is still in Sun's thinking.

I'm continuing to look for users and companies who are willing to back the requirement for decimal syntax in Java, regardless of whether this is via limited operator overloading or decimal-specific support, so if anyone is interested, I'm all ears.

4 comments:

Ophir Radnitz said...

I think it's a wonderful idea. BigDecimal are very common, especially so in business logic code. As it stands now, handling the most basic calculations on decimals involves technical details that obfuscates the code.

I'd love it if this business logic could be expressed in a clearer way (and more succinct as a side effect).

Could you please explain the difference between limited operator overloading and decimal-specific support? What is "limited" in this context? having to declare the classes that are allowed to participate?

For what other types would it make sense to apply operator overloading (Date/Collection)? What about applicative types wrapping numeric values (like Money for BigDecimal or Age for int)?

Glyn said...

These are great questions, but the limited overloading approach was suggested by Sun and I'm not sure precisely what form it would take and how broadly applicable it would be.

At the moment, I'm trying to make the case for a JSR, either by persuading Sun to lead it because of demand, e.g. from the financial sector, or by having IBM lead it, which involves finding the necessary funding internally.

The JSR Expert Group would address the above kinds of questions.

wilfred said...

A couple of years ago, I created a small framework that allowed you to express BigDecimal expressions in a more natural way. The framework took care of turning the expression in the regular BigDecimal arithmetic. One of the implementations generated byte code from the expressions.

I think with today's language features, there might be a way to make this even easier. I'll blog a bit about that in the near future. Meanwhile, the original entries are here:

http://blogs.sun.com/wilfred/date/20050721
http://blogs.sun.com/wilfred/date/20050722
http://bignumbers.sourceforge.net/

Glyn said...

Interesting approach. Thanks Wilfred.

Projects

OSGi (130) Virgo (59) Eclipse (10) Equinox (9) dm Server (8) Felix (4) WebSphere (3) Aries (2) GlassFish (2) JBoss (1) Newton (1) WebLogic (1)