Hacker News new | past | comments | ask | show | jobs | submit login

Huh? If Ruby is not duck-typed, can you give me an example of a something that is? It seems like the textbook example. Here are two weird examples: 1. C++ templates and 2) C# variables declared dynamic (I don't know C#, could be wrong) Are we using the same definitions as each other?



Duck typing is more of a technique than a quality of a language. Any dynamically-typed language is going to end up having some code that does runtime type checking. Duck typing just means doing respond_to? instead of :kind_of? when doing so.

Ruby is certainly a language suitable for the duck typing technique. The term was originally used in reference to Python, and both languages have reasonably equivalent reflection abilities.


I think the point is that duck-typing in Ruby is less of a feature and more of an inevitability due to its dynamic RTTI nature.

Compare that to duck-typing in Go where it was a very deliberate design decision.


Duck typing generally refers exclusively to runtime type checking (i.e. dynamically-typed languages). What Go does is structural typing.


I disagree. C++ templates for instance are also duck-typed, but they act at compile time, not run time.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: