check out my new blog at gmarik.info/blog

Thursday, December 21, 2006

Duck typing makes sense!

I'm reading "Programming Ruby" 2 edition, and there's a paragraph about Duck Typing, which says
You don't need to check type of your arguments
And checking objects against supported operations is just enough.

In Java, to ensure argument(object) supports certain method it's required(generally) to check ones type. But in case we just need to make sure object supports 1 single method (operation)why'd we need to check its type, which also ensures object has other methods( seems like extra info we're not interested).

So scope benefits of Duck Typing!

Duck typing allows us be as granular as possible, ensuring objects capable doing things...

And we can always check the type of course!
Yeah, duck typing makes sense!

0 Comments:

Post a Comment

<< Home