A late-night rant about OOP and parametric dispatch
devblog.avdi.org
A late-night rant about OOP and parametric dispatch
1–10 of 33 posts
Re: A late-night rant about OOP and parametric dispatch
#2Re: A late-night rant about OOP and parametric dispatch
#3Re: A late-night rant about OOP and parametric dispatch
#4Re: A late-night rant about OOP and parametric dispatch
#5I think object based is better. Why? Because I can take the object and introspect the methods. Any number of functions can take in an XML object, but there are very few methods that the XML object needs to have. In my repl if I do:
my_xml.methods - Object.new.methods
I get a list of what I'm expected to do with this object. If I do something along the lines of: functions.collect { |f| f.first_argument_can_be? XML }
Then I'm pulling in not just the normal functions, but also anything that consumes _any_ instance of the XML instance, including domain specific ones.Now, you could argue that all method-like functions should be namespaced to their own module, but now humans have to be trusted to not define these functions outside of that module and they have to be trusted to not define anything else in the module. For what purpose?
Re: A late-night rant about OOP and parametric dispatch
#6If all you're doing is calling methods on objects with no supertypes or private members, then yeah, you could accomplish the same thing by convention. But once you start layering on more functionality in your object system, the number of way you code encode this functionality starts to explode. Everybody ends up doing things their own way, and there's no consistency or compatibility. Sound familiar? It should because it's C.
Re: A late-night rant about OOP and parametric dispatch
#7The issue to me is one of name spacing. Where is the XML#to_s defined? Certainly not in one very large to_s function that takes in large swaths of various types. Of course it should be namespaced around XML, the only issue is whether it's module based or object based. I think object based is better. Why? Because I can take the object and introspect the methods. Any number of functions can take in an XML object, but t…
Re: A late-night rant about OOP and parametric dispatch
#8This seems weird to post here. It's clear he's working out some ideas, but hasn't gotten them clear enough in his head to take out of context and discuss in a place like HN.
Re: A late-night rant about OOP and parametric dispatch
#9 dog
bark
softly
loudly
run
fast
slow
cat
meow
purr
run
Let's call this the coordinate-system of your API (I've extended it a little hopefully to make it clearer). It's a small coordinate-system because it doesn't take any strings, but whatever. 'loudly' only makes sense in the context of 'bark', and 'bark' only makes sense on the context of 'dog'. That list of nodes is a coordinate that identifies a unique position in the API. (Note that in this API, actually just "loudly" should be enough to call the right code, but that won't be true in general.)To be formal you can pick out the code by saying `(do dog bark loudly)`, where `do` is a reduction that concatenates and executes the code at each node. (With a little constraining you could say `(do-special loudly)`)
OOP just calls these API coordinates by special impressive-sounding names. The top level "objects" and the second level "methods" and the third level "method arguments", and imposes all kinds of finicky constraints (some of which are even useful). Languages differ wildly with these constraints: Java doesn't let you have a unique instance method (well, not without either reflection or bytecode manipulation, anyway), but Ruby does (lovingly called "monkey-patching"). And it's quite rigid in it's current form, with a fixed noun/verb/adverb structure.
At the end of the day all that detail obscures the simple truth that your code defines a coordinate system and an invocation is a single coordinate. There's a lot more to be said about this, of course! But I hope it helps/inspires.
Re: A late-night rant about OOP and parametric dispatch
#10The issue to me is one of name spacing. Where is the XML#to_s defined? Certainly not in one very large to_s function that takes in large swaths of various types. Of course it should be namespaced around XML, the only issue is whether it's module based or object based. I think object based is better. Why? Because I can take the object and introspect the methods. Any number of functions can take in an XML object, but t…
Either as a protocol so you could do to_string(this_xml)
Or as a function within the module so you could do XML.to_string(this_xml)
If you use the module function defintion you can import it into your scope via import XML
then you can write to_string(this_xml) as if it were a protocol.