Spec and API review for {Int,Long,Double}SummaryStatistics
Mike Duigou
mike.duigou at oracle.com
Fri Mar 29 12:44:53 PDT 2013
On Mar 29 2013, at 11:01 , Kevin Bourrillion wrote:
> 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?
Maybe it isn't. The goal was presumably to avoid requiring people to routinely check for the exception to apply a default.
> I believe no one will ever curse your name for throwing the exception.
Worrying about the curses of Java programmers is something which does keep me up at night. You must also work on libraries....
> 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)
I'm definitely not an expert in this area.
> Final nit: what's the consistent rule for when exactly this "get" prefix is used?
It's generally used to retrieve state with little or no computation or conversion required to produce the result. "as" or "to" imply conversion. Unadorned names usually imply more computation. Across the JDK it's easy to find counter examples to every rule unfortunately.
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/lambda-libs-spec-experts/attachments/20130329/9a20d361/attachment.html
More information about the lambda-libs-spec-experts
mailing list