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

Type Inference only works nicely if your have static and strong types. Heterogenous data structures are non-trivial in such a language, duck typing doesn't work anymore etc.

In other words people do use these features, they use these features a lot and that is not a problem. You are just using an overly trivial example in which you make assumptions without considering all the consequences.




"""Heterogenous data structures are non-trivial in such a language"""

Why would they be? You just need a common parent type, like object, or something like Objective-C's "id" type, to indicate that a structure/method can accept any type.

So:

a = 1 # int

b = "foo" # string

c = Cat() # cat object

d = Singer() #singer object

you could have a built-in, say list, structure:

mylist = [a, b, c]; mylist.append(d)

or

myadt = CustomDataType()

myadt.add(c); myadt.add(d);

"""duck typing doesn't work anymore etc."""

Wikipedia: "duck typing is a style of dynamic typing in which an object's current set of methods and properties determines the valid semantics, rather than its inheritance from a particular class or implementation of a specific interface".

So, why would duck typing not work? Duck typing is about the ability to call methods on any type that implements them. It's irrelevant if the type is static, not? Say:

foreach item in myadt: item.sound()

Cat and Singer could be from totally different objects hierarchies, and the compiler/language would know that both implement "sound()" and let you call it.

If an object on myadt doesn't implement sound() you get a runtime error.

"""You are just using an overly trivial example in which you make assumptions without considering all the consequences."""

Emm, the whole point of my comment was in me EXPLICITLY ASKING for possible consequences. Which you kinda missed, judging by this statement.




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

Search: