Well, at some point, you have the choice to either:
- explore & exploit all the nitty-gritty details and possible combinations offered by a given language, which is a very large space plenty of impractical ways of coding
- limit yourself to a subset of all possibles, by sticking to your own good practices (generally built from your own experience + the community’s)
And the K.I.S.S. approach (which I often remind to apply to myself) is common implementation of the latter.
Here, the example you are suggesting is problematic in that it’s very subjective in nature and goes beyond the purpose of multiple dispatch - rationale that I tried to convey through the semantic analysis - and wouldn’t be used by anyone for any practical purpose (other than to make a point, sorry to say that).
You’ll notice that everything you code is in a given context (in the common meaning, not the “programming” context): a script, a game, a physics problem, an IT infrastructure architecture, a mathematical operation, a web app, etc. In each of that, this is the context that gives meaning to a function (btw, this is not for not reason that the topic of context is hot topic in LLMs).
More generally - and more philosophically - I’d even argue that there is no such thing as a context-free word sens (and thus function).
As I understand it, your logic is that, considering that a function can be dispatched to any method, why not do it? (this type of questioning is generally a good approach when one wants to explore new possibilities)
But instead, I proposed that, given the premises under which the multiple dispatch capability has been thought of, pondered, & implemented (module, then function, then method), it’s better to use this tool that way, namely, considering that a function has an objective meaning only in a given context, and may be implemented by one or multiple methods.
Dropping context (in the sense of what’s defining the purpose of a function - not a method) is totally allowed by Julia syntax and you’re totally free to choose this approach.
But this is at your own risk, by making things much harder to reason about for big codebases, getting confused, and possibly leading to unexpected behaviors, such as the one shown in your initial example.
But to still, trying to go in the direction of the example you’re proposing, I’d say that this would still somewhat work if you implement the function most_interesting_operation
with a custom method using your own custom type. I other words, by avoiding type piracy.
In that case, the context would be something like SubjectiveView
(which would be the package name first defining the function and possibly some methods), and each new package creator could implement his own most_interesting_operation
method of SubjectiveView
using his VeryPrecious
custom type. In a word: by avoiding type piracy.
So the TL;DR is:
“type piracy” is litteraly litteraly what it means: it’s the hacking of a function’s purpose / intent, and can lead to troubles.