Re:Examples of Incorrect Abstractions in Other Languages
by karatestomp on Tuesday May 19, 2020 @07:56PM
(#23241771)
Sum and join mean different things. If sum didn't fail on chars I'd expect it instead to sum their binary values, which is a thing one occasionally actually does want to do, not to join/concatenate them. If it can't do that (or you have strings, as in this case, for which it makes less sense—the most sensible thing there would probably be to treat it as a byte array and do something with that, though any conceivable use of that probably breaks down with UTFs 8 or 16 instead of ascii) I'd want it to fail.
[ Parent
| on HN ]
Re:Examples of Incorrect Abstractions in Other Languages
by tom_mellior on Wednesday May 20, 2020 @02:27AM
(#23243873)
Sum is the iteration of +. + on strings is concatenation. If you expected otherwise from sum, it's your expectations that might be wrong. What even is a Python string's "binary value"? Also, Python has no chars.
Re:Examples of Incorrect Abstractions in Other Languages
by uryga on Wednesday May 20, 2020 @07:01AM
(#23245438)
so you'd expect this behavior?
sum("abc") =
sum(ord(c) for c in "abc") =
sum([97, 98, 99]) =
294
because wow, i... can't think of why you'd ever actually want that. (though it'd be perfectly natural for byte arrays)