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

OK, so I wasn't too far off in my (not-yet-Rust-programmer) interpretation of "duck typing is good (or at least more flexible)"?


Rust's approach is very much not "duck typing".


The koan doesn't disambiguate, though, does it? If you didn't know it was about Rust, what clues are there that it's talking about static typing?


I think you're right. I took the koan to mean that when designing any given widget the focus of the implementation should make as few contextual assumptions about the use of the widget as is it feasible to do.

There is an inverse relationship between the number of contextual assumptions made about a widget and the number of contexts the widget can operate in. Something with few contextual assumptions is typically referred to as "flexible."

Duck typing as a practice entails a focus on the capabilities of a given widget rather than the "role" (read: type) of that widget. Focus on capabilities = fewer contextual assumptions. Focus on role/type = more contextual assumptions. Thus duck typing can be thought of as one possible embodiment of the koan's intended perspective.

Of course, some detractors of static typing might take this to mean that static typing implies a focus on types which as I've just shown would imply more contextual assumptions and less flexibility. But as rust's traits show, one can keep the benefits of static typing without sacrificing flexibility so long as the focus of the overall design is still capability-centric rather than role/type-centric. But that's a different conversation :)




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

Search: