Closed bakkot closed 5 months ago
I would be surprised if users find that surprising, since that’s kind of the point of the method. sumExact imo begs the question of why + isn’t exact.
sumExact imo begs the question of why + isn’t exact.
Well, yes, that's a good question for users to ask, if they're summing a big list of numbers. I think drawing attention to that distinction is possibly valuable.
If it needs drawing attention to, then that either means nobody’s noticing the difference or that nobody’s confused, no?
I think it maybe needs drawing attention to because people might be confused.
I guess people may also ask why only sumExact
, no productExact
?
Further naming bikeshed: given that this takes an iterable instead of being variadic, should this be sumExact
or sumExactFrom
?
"From" isn't a universal convention when something takes an iterable, so I don't think that's strictly necessary.
@ljharb It may not be universal, but it still makes a strong implication, which can be helpful. I like sumExactFrom
despite the verbosity.
Closing: in plenary we decided on sumPrecise
.
I know this has already been decided, but I'm going to throw in my 2-cents dislike towards the name "sumExact()".
For the vast majority of places where this function will be used, the exactness of the summing algorithm won't be an important factor. The fact that it follows a more precise algorithm feels more like a detail that belongs in the documentation, as something extra you can learn about if you want to dig in detail - it's not something that needs to be called out every time the function gets used.
If we followed this kind of naming everywhere, we'd end up with function names like these:
// The sorting algorithm for .sort() is implementation specific
array.implementationSpecificSort();
// .flatMap() is faster than doing just .map().flat(),
array.fastFlatMap();
// Object.keys() doesn't pick inherited keys or symbol keys.
Object.ownStringKeys()
// etc
In the end, it's not a huge deal to me, it just feels unfortunate to be calling out what is typically an insignificant detail every time I use the function.
Maybe Iterator.sumPrecise
to explicitly indicate the type of the input?
The type of the input is an iterable, not an iterator.
Also, the object that holds the method usually implies the output, not the input. Array.from, for example.
Number.sum
then :-)
The namespace that holds the functions which do computations on Numbers is Math. It's definitely not going to go anywhere other than on Math.
Given that this proposal now requires exact summation, is
Math.sum
still the right name? In some sense yes, but it may be surprising to users thatMath.sum(a, b, c)
gives a different answer (and is potentially slower) thana + b + c
.Maybe
Math.sumExact
?