News for hackers. Stuff that matters.
Re:OOP practiced backwards is "POO" by limmeau on Saturday December 11, 2010 @05:46AM (#1994613)
So you're checking if it implements an intersection of single-method ducktypes. Now if only there was a way to reify that intersection and give it a name...
Re:OOP practiced backwards is "POO" by steveklabnik on Saturday December 11, 2010 @10:54AM (#1995012)
... but this isn't done very often, and is generally considered a Bad Idea, so let's not encourage it with a special language construct.
Re:OOP practiced backwards is "POO" by limmeau on Saturday December 11, 2010 @02:14PM (#1995439)
What exactly is the bad idea here? Having more than one method in a duck-type?
Re:OOP practiced backwards is "POO" by steveklabnik on Saturday December 11, 2010 @02:36PM (#1995482)
is_a? and respond_to? are code smells.
Re:OOP practiced backwards is "POO" by limmeau on Saturday December 11, 2010 @04:40PM (#1995719)
Yes, I agree. I wasn't actually suggesting to sprinkle instanceof-checks throughout the code.

What I was trying to get to: if you accept the existence of single-method ducktypes (like "things that have a walk() method" oder "things that have a quack() method"), then by intersecting these concepts, you arrive at things just like interfaces, whether you call them interfaces or not. If you want the pond system to work with your two-legged bird-sound robot, you perform the same mental steps as when implementing an interface. Hence, ducktypes could be seen as interfaces without an instanceof-operation.