News for hackers. Stuff that matters.
Re:Examples of Incorrect Abstractions in Other Languages by dragonwriter on Wednesday May 20, 2020 @11:03AM (#23247701)
> If I'm writing a library that needs to handle user-provided data agnostic of type and I want to do a sum operation, now I have to add checks all over the place for whatever special cases python has.

No, you don't, because: (1) if your idea of a sum is just reducing with “+”, you use functools.reduce; and (2) if your idea of sum is a mathematical sum, you use the very slight shortcut of the sum() built-in function, which is (barring things like the runtime type checking) equivalent in result to:

  def sum(iterable, start=0): 
    return functools.reduce(lambda x,y: x+y, iterable, start)

There are no comments on this comment yet.