TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Duck Wrapping

45 pointsby jayferdabout 12 years ago

5 comments

tikhonjabout 12 years ago
This is why I think a type system--at least one like Haskell's or OCaml's--isn't just a way to catch certain bugs. It's more of a different <i>basis</i> for programming: your program grows from the types rather than vice versa. Confusing behavior like this simply couldn't arise. And in the cases it <i>could</i> it <i>wouldn't</i>--it simply doesn't fit with the philosophy.<p>So the difference is not that the type system would catch this sort of behavior or even that it would prevent it--the difference is that it wouldn't arise in the first place. Sure, this is more a difference of perspective than of actual behavior or features, but I think it's incredibly important nonetheless.<p>Thinking about types in this different way is actually quite a deep topic; I should write a blog post about it for that blog I keep on meaning to start :P. One day. At the very least, writing it all down would help me get my own thoughts in order.
评论 #5549880 未加载
评论 #5551241 未加载
评论 #5550227 未加载
noelwelshabout 12 years ago
Funnily enough I just blogged on exactly the same issue: <a href="http://www.noelwelsh.com/programming/2013/04/13/less-wat-in-javascripts-future-please/" rel="nofollow">http://www.noelwelsh.com/programming/2013/04/13/less-wat-in-...</a><p>Couldn't agree more that this is bad practice!
mmahemoffabout 12 years ago
Just to relate this to known concepts, this is basically Type Coercion, aka Implicit Type Conversion, at library level. Or it can be framed as method overloading with some magic to neutralize the parameters.<p><a href="http://en.wikipedia.org/wiki/Type_conversion#Implicit_type_conversion" rel="nofollow">http://en.wikipedia.org/wiki/Type_conversion#Implicit_type_c...</a><p>I don't think magic like this is out of place with JS; that's the zen of the language. Similarly for Ruby. Whereas in Java or Python, it <i>would</i> be out of place. Now you might use that as an argument against JS, but that's a separate debate.
merynabout 12 years ago
From the post:<p>"This is annoying at the level of Arrays, but gets more difficult with more complex types, and function interactions. The recent brouhaha around the Promise/A+ highlights one such example: It is difficult to return a Promise of a Promise as a value from onFulfilled because then duck-wraps the return value as described in the Promise Resolution Procedure"<p>Could anyone share a pointer to this brouhaha around the Promise/A+ [spec, I assume]?
评论 #5550367 未加载
eterpstraabout 12 years ago
Articles like this make me realize just how much I still have to learn about javascript - or perhaps programming in general. :P