3 ms·
I agree that using blocks/closures is a powerful and useful mechanism -- In fact I think that they are a great implementation technique for this method. What t
by evanmoran 18y ago
I agree that using blocks/closures is a powerful and useful mechanism -- In fact I think that they are a great implementation technique for this method.
What this comes down to for me is: what makes the best interface?
Specifically:
myArray.sum()
is much easier to read and use. In a world where we have to maintain our code much longer then we write it this simplicity is very valuable.
Secondly, it is important to note that since the array uses generics it is not necessary to check that the items are numbers, as any attempt to insert a non-number would have thrown an error.
So in summery I agree with you completely that array<variant>.sum should _not_ exist. But I hope you see my point that array<number>.sum _should_ exist. (If the code enforces the numbers to exist in the array there is no reason not to include the sum method!)