Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] creating a pointcut for primitive



Andrew Elegante wrote:
Bruno,

Thanks for the response. I had originally planned to do what you were saying, that is convert x*y -> BigDecimal.multiply(x,y) but my boss thought it would be better to just round it out to 8 decimal places or so to get the necessary precision. We’re talking about numbers which are used in financial calculations so it’s very important that they be precise. It doesn’t really matter to me which way we do it but I’d like to be able to avoid having every programmer be responsible for determining whether the calculation is financial or not and doing the appropriate rounding or BigDecimal operations ergo my wish to use Aspects to make it always happen that way.

I’ll look into extending AspectJ that way (Eric pointed me to a compiler I can extend).


Indeed Eric is right, and abc is certainly the right tool to use if you want to use this kind of solution. However, as I said, there will be problems waiting at the corner.
In particular, I presume you may sometimes have operations of this form:
  double a ; (assigned somewhere)
  double b = 2*a ;
In this case, I'm quite sure your multiplication pointcut is going to have arguments typed int and double.
But if you did this, this would be another type:
  double b = 2.0*a;
You'll need to consider all the possible cases when you write your aspect.
In addition, once a number is assigned, it's already too late.
After this:
  double a = 2.0;
the value of "a" isn't really 2.00000000000000000000000000 (it is 2.0 with an error margin. It's the same problem as "33.33% is a third".) It's not just an aspect problem. It's the way it's represented in the class or in memory.

If you want the number that you type to be the number you mean, you'll need to use a proper decimal representation all the way through. If you really want to be able to write operations such as 2*b, it might be possible to use the polyglot side of abc to "autobox" your numbers into BigDecimals. This could be really interesing if you could even manage to have a pointcut model expressed in terms of multiplication symbol but acting on the boxed BigDecimals. (I must said I haven't thought it through...) (I would otherwise suggest to use something like perl, but loose-types have a few drawbacks, in fact a few more than just a few sometimes.)

Regarding the use of BigDecimals, even without having a new type of join point, I can see a good potential use for aspects for enforcing this 8-digit rounding policy without worrying about it when you write the calculations themselves (and it would be easier to change this policy to 10 digits later on if you needed).



Bruno.


Back to the top