20 April 2014

The Ruby Reflector

Topic

Duck Typing

  Source Favicon
Email

Duck Typing

In statically typed languages, runtime polymorphism is more difficult to achieve. Fortunately, with Ruby we can use duck typing .

We'll use our XML and JSON parsers again for this example, minus the inheritance: class XmlParser def parse puts 'An instance of the XmlParser class received the parse message' end end

class JsonParser def parse puts 'An instance of the JsonParser class received the parse message' end end

robots.thoughtbot.com Read
  Source Favicon
On The Majestic Sea Creature over 2 years ago.
Email
  Source Favicon
By serge of Complicated Simplicity almost 3 years ago.
Email

I'm being sarcastic here, of course I don't think that Duck Typing can substitute LSP. Have a look at behavioral conditions section in the wikipedia article for reasons. The fact that LSP is attracting attention right now can be pretty telling. I'm excited to witness it. Community is finally seeking for some grownup approaches, great! However, the question is: doesn't that get us closer to some limitations of our beloved highly dynamic language?

Rails code is rapidly …

complicated-simplicity.com Read