-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Duck-typing (a la Python) works by the premise that the user knows the type of the operands and no coercion happens. Weak typing (a la Perl and Raku) works by the premise that the user knows how the operation treats its operands and no overload happens. Mixing the two principles makes code fragile, yet still there are operators in the core (mainly the numeric operators) that mix the two approaches.
A question on IRC highlighted that an operation like (0..10) + 1 can return 1..11. The problem with this is that it contradicts the concept of "numeric addition" - neither the way the operands are treated, nor the return value fits that picture. Actually, it's really easy to bust it: (0..10) + (1..1) is suddenly 12, even though the intuition is pretty similar to (0..10) + 1. It's hard to reason about this kind of code.
Taking a look at the docs, there aren't excessively many (documented) "hybrids". Range has the 4 basic arithmetic operations (not ** though, interestingly...), Date and DateTime have + and - overloaded, and that's about it for the immediately apparent operations. I can't see a strong reason why it has to be like this, and it actually makes code harder to reason about in any nontrivial situation, because of the conflict of the two typing paradigms.