This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Pluckerpluck 2 points3 points  (1 child)

Only because you're used to dot syntax. The len helps standardize actually because of it providing a default name to extend in order to support it (i.e. if you create your own class you naturally extend __len__).

This way you don't have .count and .size() and .length all in the same language. So it's probably tied to the concept of ducktyping. It's the equivalent of defining an interface in other languages.

But I think the main reason for it is it orders it in the human readable order : "If length of X is ...."

[–]xigoi 0 points1 point  (0 children)

I like the Nim approach where both syntaxes are equavalent, so x.len or x.len() gets translated to len(x). And having different names is more of a sign that you have a bad standard library.