Re:Examples of Incorrect Abstractions in Other Languages
by tom_mellior on Wednesday May 20, 2020 @02:24AM
(#23243857)
If that check is there anyway, and the preferred path is known, I would think that the great increase in complexity would look something like this:
if trying_to_sum_strings(args):
- complain_bitterly()
+ separator.join(args)
Re:Examples of Incorrect Abstractions in Other Languages
by edflsafoiewq on Wednesday May 20, 2020 @04:13AM
(#23244512)
Like I said, the current check for trying_to_sum_strings is just that start is a string. So if you would do this you would actually make sum less consistent, since sum([x], ''), which should logically be '' + x, would become ''.join([x]), which not the same (think of an example with __radd__).
Re:Examples of Incorrect Abstractions in Other Languages
by tom_mellior on Wednesday May 20, 2020 @04:34AM
(#23244639)
I don't follow. In your example, if x is a string, there is no problem since '' + x is just x. If x is not a string, the new path would not trigger, so the behavior would be as before.
EDIT: OK, I think if the example is sum([some_string, some_not_string], '') then there is a possibility that some_string + some_not_string might be a valid expression computing a value while ''.join([some_string, some_not_string]) would complain that some_not_string is not a string.
> isn’t it already inspecting the type of the list elements
Actually it only checks if the type of start (the initial accumulator value) is a string. If the accumulator becomes a string later on, it's happy to sum strings.