[Issue 8755] Change the order of reduce arguments
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Oct 4 12:32:37 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8755
--- Comment #3 from bearophile_hugs at eml.cc 2012-10-04 12:26:41 PDT ---
(In reply to comment #2)
> Why is it any different to sort being "a < b" by default? Should we require
> that sort is always sort!"a < b"?
It's different because it's widely accepted that "just sorting" a sequence
returns it ordered from the min value. In Python, Haskell, Ruby and several
other languages "just sort" has such definite meaning.
But I don't know of any language where reduce/fold has a default function that
sums.
When people not expert of D look at code like this, they understand its
meaning:
auto data = [3, 2, 1];
data.sort();
writeln(data.sum());
But when they see this, they can't know/see what this reduce is doing:
auto data = [3, 2, 1];
writeln(data.reduce());
Summing items of an iterable is a very common operation, and having a
specialized function (as in Python, Haskell, and other languages, even in
Fortran) with a short clear name as sum() is good.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list