Spec and API review for {Int,Long,Double}SummaryStatistics

Kevin Bourrillion kevinb at google.com
Fri Mar 29 11:01:49 PDT 2013


On Thu, Mar 28, 2013 at 6:37 PM, Mike Duigou <mike.duigou at oracle.com> wrote:

> I've responded to the survey feedback and updated the implementations with
> additional Javadoc.
>
> One comment which was not addressed was whether getAverage() should throw
> a zero division ArithmeticException if no values had been recorded. I
> believe the current default of returning 0.0 is reasonable and it is
> convenient to not have to check the catch the exception. It's also in line
> with the defaults we provide for sum, sumOfSquares, min, and max.


I think I've said this before, but I believe this is extremely wrong.  sum
and sumOfSquares have a well-defined and obvious identity.  min, max and
average are entirely meaningless when applied to zero values.  What would
you think of a language where 1 / 0 returned 0?  How can we claim this is
any different?  I believe no one will ever curse your name for throwing the
exception.

Also, while I'm here...

Exposing sumOfSquares() does not permit users to safely calculate variance,
which I believe makes it fairly useless and even dangerous:

"The failure of Cauchy's fundamental inequality is another important
example of the breakdown of traditional algebra in the presence of floating
point arithmetic...Novice programmers who calculate the standard deviation
of some observations by using the textbook formula [formula for the
standard deviation in terms of the sum of squares] often find themselves
taking the square root of a negative number!"  (Knuth AoCP vol 2, section
4.2.2)

Final nit: what's the consistent rule for when exactly this "get" prefix is
used?

-- 
Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb at google.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/lambda-libs-spec-experts/attachments/20130329/5136b97b/attachment.html 


More information about the lambda-libs-spec-experts mailing list