top | item 26358207

(no title)

mbauman | 5 years ago

I actually find it far more linguistic, that is, more akin to natural languages.

In my view, it's not multiple dispatch per se that is the bigger departure from traditional OOP, it's the fact that methods are no longer contained in the classes. Julia draws a separation between data (structs: the nouns) and behaviors (functions: the verbs). Traditional OOP never really made sense to me; why should each class define and own its own methods? It feels far more sensible to me to just have global behaviors that are well defined. Those verbs can sometimes apply to _anything_ (leaning on more rudimentary operations that you need to define; duck-typing), and sometimes they require you to explicitly define your behavior, and sometimes you just want to add an additional optimization that's available in your particular situation.

Once you have that mental model down, multiple dispatch is just how Julia chooses which method to call... and it's really not much different from single-dispatch.

discuss

order

snicker7|5 years ago

> why should each class define and own its own methods?

State mutations. That's it. By ensuring that your data can only be mutated by a your API, it can never get "corrupted".

mbauman|5 years ago

Sure, there is a subset of behaviors for which this style makes sense, but it's just as well supported by simply defining your own functions alongside the struct.