On Friday, 14 October 2022 at 18:29:10 UTC, Walter Bright wrote:
> [snip]
True that documentation often (always?) lies about what the code actually does. But the causes of this are usually because of programmer laziness and/or error in documenting it correctly.
But operating overloading for non-arithmetic purposes is deliberately doing the unexpected.
What is your opinion about R's custom infix binary operators? (ignoring that R is dynamically typed)
So for instance, you can make a function
`%foo%` <- function(x, y) { #does something }
and use it like x %foo% y
The surrounding %
lets the user know that anything could be happening in there. However, it doesn't have to just be some string, it could be anything. For instance, R comes with %*% built-in for matrix multiplication and a few others.
From D's perspective, it doesn't really make sense to use a string since we have UFCS and it is just as easy to use x.foo(y)
[in R you would have to do foo(x, y) if this feature didn't exist]. However, it is useful when it is some symbol that would otherwise have a longer name. Code that is full of X.matmul(Y)
is harder to read than X %*% Y
.