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

So you basically put type information in the names. That's typing in a sense.


I see where you're going but thats not really what we're doing with that ... @user.posts actually returns an array of posts and @user.posts.first returns an actual Post object.

You could also change @user.posts to be @user.contributions, for example, and that would hide the fact that contributions was just an array of Post objects.


No, he puts typing in the interface, and that's indeed typing in a sense, called duck-typing.


I think we are talking about different things. Duck-typing doesn't help in depicting what the return type of a function is when looking at the function signature only. You need to look at the function implementation (the actual duck) to tell what the return type is.


My point I guess was that with proper abstractions and duck typing you really don't have to care about the type. I only notice something isn't a duck when I try to use it like a duck and it fails - which is surprisingly infrequent.


It becomes difficult to tell it's a duck when reading code, which was the original complaint. Duck type works when you actually try calling it.




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

Search: