Well, I’m glad I've struck a nerve there :) I agree that signalling an exception isn’t wrong, it’s just annoying because you have to do the check manually each time. I think I like #sum:ifEmpty:. When you look through the methods in Collection you’ll see #sum, #sum: and #sum:ifEmpty together in one place and it will be clear how to use them.
> On 01 Dec 2015, at 12:52, Sven Van Caekenberghe <[email protected]> wrote: > > >> On 01 Dec 2015, at 12:45, Stephan Eggermont <[email protected]> wrote: >> >> On 01-12-15 11:46, Sven Van Caekenberghe wrote: >>> The basic question for me is, what should >>> >>> #() sum >>> >>> return. Right now, it is an error, I would very much like that for this >>> common case the result would be 0. There is a lot of power (easy of use) in >>> a unary selector, we should not destroy that with semantics that force a >>> test before using it. >> >> I like the error, it aligns with most of our collection protocol. > > I hate the error, a lot ;-) +1 > >> It shows the need for #sum:ifEmpty: though > > Yes, as long as #() sum == 0 +100 That allows for nice Smalltalk like “myNumbers sum isZero …”. > > I want the simplest case to be simple, having a non-0 default is a special > case IMHO > >> Stephan >> >> >> > >
