Dispatching For Dummies

OK, so I don't actually think I'm a dummy, but some of the pages here certainly make me feel like one. I have an eclectic background, but I've never come across "dispatching" explained in a way I can really understand.

After the recent success with coming to grips with RSS, I thought I'd ask here.

From reading some of the pages it sounds like messages are being "dispatched" to different objects, but people seem to be talking about implementation details and dark corners - it's hard to find a simple description. I thought messages were simply addressed to and delivered to methods, but there's obviously something I'm not getting.

Any takers? For reference I have started to read, but not generally understood:

Equally for reference, I do not program in Smalltalk, C++, Java or any other overtly OO language.

What do you program in? Haskell's PatternMatching is an example of multiple dispatch; one which is frequently resolvable at CompileTime.


Could this, should this, be turned into a simple, clear, single-purposed DocumentMode page explaining the concept?

Wouldn't DynamicDispatch be the right place for that? I started trying to rewrite it, but here's the problem: The concept of DynamicDispatch is really, really simple, because it's a very vague generalization of a feature that appears in many languages. However, the details and terminology of that feature differ vastly among the different languages, so it's hard to describe DynamicDispatch in a concrete way that will immediately click for every programmer. After you've seen the feature in a number of languages, the generalization will seem obvious once pointed out.

A very general description might be something like: "A means of selecting a function to call from among a candidate set of functions, based on the types and/or values of the arguments in the call. The candidate set can often be determined statically, based on the function name, although in some languages it can be based on both the function name, the number of arguments, and the statically-determinable types of the arguments. The types or values used for final selection of a call target must, in the general case, be determined at runtime, hence the selection is dynamic."

You'll note that you can't even characterize dynamic dispatch as being dependent on argument types, because some languages allow a method to be selected entirely or partially based on values, not types.

-- DanMuller


CategoryDummies


EditText of this page (last edited May 9, 2011) or FindPage with title or text search