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

Duck typing. A Python object doesn't have to have a specific type, just the attribute(s) you want. You'll find a lot of "hasattr(obj, x)" throughout any large Python code base. It's nice to not have to worry about creating single-method/single-attribute interfaces and dot them all over the place.



Good point. But how can you know the types statically (at development-time) without defining interfaces?


You could specify that your method takes an object which has method XYZ accepting an int as its parameter and returning another int -- a kind of "anonymous" interface, I guess. Personally I don't like this kind of stuff because there's no guarantee that two objects with a convert method do the same thing when that method is called.




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

Search: