[squeak-dev] Collection>>sum implementation
Colin Putney
cputney at wiresong.ca
Tue Aug 12 14:59:53 UTC 2008
On 12-Aug-08, at 2:30 AM, Tony Garnock-Jones wrote:
> Yes, an error is currently signalled. Which makes the general case:
>
> aCollection ifEmpty: [0] ifNotEmpty: [aCollection sum].
>
> .. which, to me, is a bad code smell. Then again, I've been an FPer
> for a long while.
It's a code smell from an OO perspective too.
This is a bit like the #join: debate that comes up every now and then
when a Ruby/Python/Perl ex-pat asks how it is that we don't have a
method for joining an array of strings into a single string. The short
answer is that it's because #join: only makes sense when all the
elements of a collection are strings, and therefore, it's bad design.
This is similar. I'd say the best way to improve #sum would be to
delete it.
Ok, compatibility is an issue, breaking existing code would be bad
etc. So leave it as is and point anyone who complains to
#inject:into:. If that's really too verbose, then what's really needed
is a more specific class that understands what this collection of
numbers represents.
Colin
More information about the Squeak-dev
mailing list
|