Re: operator overloading
- From: Wojtek <nowhere@xxxxx>
- Date: Tue, 13 May 2008 20:23:16 GMT
Mark Thornton wrote :
Wojtek wrote:Patricia Shanahan wrote :The challenge I presented earlier in this thread is a *very* simple
example of a mathematical formula:
"Consider calculating the sum of the first n terms of an arithmetic
series, given its first term, a1, and common difference, d.
http://en.wikipedia.org/wiki/Arithmetic_progression#Sum_.28arithmetic_series.29
Infix arithmetic operator version: (n * (2*a1 + (n-1)*d))/2."
Can you produce a descriptive method name form of this expression that
is as obviously equivalent to the original formula?
Ok, this appears to be used as a utility method, therefore I would make it static with the method returning the result of the formulae calculation. The class could be named MyMath. So:
BigInteger seriesSum = MyMath.getProgressionSeriesSum( startTerm, termLimit, difference);
I think you have missed the point. It is just a fragment of code and we don't want to turn every such fragment into a method of its own. It is also on the very simple end of mathematical expressions.
Also to Patricia,
The series sum is a pure math operation, and would not need operator overloading.
And yes, I WOULD create a library with these types of calls. It makes using them in multiple places consistent. I would encase it even for a single use as it makes cleaner code at the point of usage.
What the formula is like in the method is up to the author. Black box testing should prove that the formula implementation is correct. If you do not have trust in the author, then extend the library class and override the method with your own implementation.
But that is always the risk in using someone elses library for everything from high math formula to common string operations. The assumption is that it works until proven false. If you are using the library for mission critical use (life critical, million dollar critical) then you would perform extensive testing before it was trusted.
Maybe I am missing the point with this series sum formula. It just seems obvious to me to encase it in a method, prove it, then just use it.
And how it relates to operator overloading mistifies me.
--
Wojtek :-)
.
- Follow-Ups:
- Re: operator overloading
- From: Lew
- Re: operator overloading
- From: Mark Thornton
- Re: operator overloading
- References:
- operator overloading
- From: josh
- Re: operator overloading
- From: Wojtek
- Re: operator overloading
- From: Wojtek
- Re: operator overloading
- From: Mark Thornton
- operator overloading
- Prev by Date: Re: handling resize events with JScrollPane
- Next by Date: instruction java
- Previous by thread: Re: operator overloading
- Next by thread: Re: operator overloading
- Index(es):
Relevant Pages
|