Ryan Pavlik wrote:
>Yes, but it _was_ asserted that it was a language attribute of ruby,
>when you can practice it in other languages, which have no specific
>provisions, any mention of "duck typing", or common practice thereof.
>
>(Although, in JavaScript, and most prototype-based languages, you
>usually practice 'duck-typing' because that's the way things are.
>Pure prototype-OOP has no class, just an object that acts in a
>particular manner---in this case, you could probably consider it a
>feature of the language.)
>
>
Duck typing may not be a "feature" of Ruby, but it's definitely supported by
Ruby. It's also very well supported by Python, Perl, JavaScript, and
I'm sure
many other languages. The difference with Ruby is that Dave Thomas hangs
out here more and he's the one who said it originally.
Ruby does have some provisions that make it more supportive of duck typing,
though. For example, as I understand it, in Smalltalk (which I'm still
learning),
you define all your methods when you're building the program, and then all
that is fixed. You can't, for example, make an object of class Object
and then
write custom methods for that one object. So objects and types are more
dynamic in Ruby than in, say, Smalltalk, for example.
This, of course isn't exclusive to Ruby. As I recall, JavaScript allows you
to add methods to arbitrary classes or objects. But, as I said, Dave Thomas
hangs out here, which is why Ruby people talk about duck typing and
JavaScript people don't.
Cheers.
- Dan