Java operator overloading
- by nimcap
Not using operators makes my code obscure.
(aNumber / aNother) * count
is better than
aNumber.divideBy(aNother).times(count)
After 6 months of not writing a single comment I had to write a comment to the simple operation above. Usually I refactor until I don't need comment. And this made me realize that it is easier to read and perceive math symbols and numbers than their written forms.
For example
TWENTY_THOUSAND_THIRTEEN.plus(FORTY_TWO.times(TWO_HUNDERED_SIXTY_ONE))
is more obscure than
20013 + 42*261
So do you know a way to get rid of obscurity while not using operator overloading in Java?
Update: I did not think my exaggeration on comments would cause such trouble to me. I am admitting that I needed to write comment a couple of times in 6 months. But not more than 10 lines in total. Sorry for that.
Update 2: Another example:
budget.plus(bonusCoefficient.times(points))
is more obscure than
budget + bonusCoefficient * points
I have to stop and think on the first one, at first sight it looks like clutter of words, on the other hand, I get the meaning at first look for the second one, it is very clear and neat. I know this cannot be achieved in Java but I wanted to hear some ideas about my alternatives.