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

This is factually incorrect, interface{} allows polymorphism. Maybe you are unaware of how interface{} works but if you want to call a method on it you just do this:

    func myFunc(a interface{}) {
        a.(interface{ f() }).f()
    }
This works for any type "a" which has a method "f" with the correct signature, and this is what I meant when I said “except it requires casting”. The fact that you can’t do this with + is merely a consequence of the fact that + is just the __add__ method in Python, and in Golang + is not a method. The fact that Golang matches method signatures whereas Python only matches method names is not really a substantial difference in my eyes.

I don’t think there’s a strong case to be made here that interface{} is substantially different from Any in Python, again, except for the required cast. And I think we all agree that neither Python nor Golang support generics. (Python supports metaprogramming, and you can implement something similar to generics with metaprogramming, but I don’t consider that to mean that Python supports generics. Type checkers retrofitted onto Python also support generics, but I don’t really consider those to be core Python yet.)



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

Search: