News for hackers. Stuff that matters.
Re:Object Oriented Programming is Inherently Harmful by slowmovintarget on Sunday November 30, 2014 @01:51PM (#8677633)
Polymorphic dispatch is the specific reason for polymorphism in Object-Oriented Programming. It is more generically known as "dynamic dispatch": http://en.wikipedia.org/wiki/Dynamic_dispatch

You'll encounter the term in Bertrand Meyer's Object-Oriented Software Construction for example: http://www.goodreads.com/book/show/946106.Object_Oriented_So...

Re:Object Oriented Programming is Inherently Harmful by Dn_Ab on Sunday November 30, 2014 @02:24PM (#8677762)
Dynamic dispatch is a special case of predicate dispatch. In particular, captainmuon pointed out that:

>Pattern matching in functional languages solves this in a different way.

captainmuon wanted a more flexible way of dispatching on types similar to what can be done with Pattern matching (which is also a special case of predicate dispatch).

In the post I linked to above this example is given:

Basically, instead of basing the dispatch on an "is_a" check, you check whether a general predicate is valid on the argument. So, in imaginary syntax instead of writing

  int foo( int a, int b):
  if a > 0 
	return a
  else
	return b-a
you'd write:

  int foo ( gt_zero? a, int b): return a
  int foo ( int a, int b): return b