Hacker News new | ask | show | jobs
by griffindy 5031 days ago
^ this ^ never understood why certain methods (or are they functions?) are not called on the objects. This is one of the reasons I love Ruby, everything is clearly an object.
1 comments

> ^ this ^ never understood why certain methods (or are they functions?) are not called on the objects.

Because they don't depend on a given class, they're protocols. There's no "master class" in which to put them, so they go in some sort of bastardized CLOS-like generic method instead.

With duck typing, that shouldn't matter. Lots of methods in the Python standard library take "file-like objects" that have read() methods and no common superclass, and that works fine without read being a top-level function.
There's no need for a super class to have a len() method. I don't get your reasoning here, Python is not a statically typed language.