Mark Thornton wrote :
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.