Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

... 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.


What exactly is the bad idea here? Having more than one method in a duck-type?


is_a? and respond_to? are code smells.


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: