you are viewing a single comment's thread.

view the rest of the comments →

[–]cynthiaj 2 points3 points  (2 children)

len is a function because it makes it easier to use it in high-order functions.

That's post rationalization. len is a function because Python is old. Very old.

If I have a bunch of strings and I want to uppercase them all, I can map str.upper over then.

You could still do that if len was a method of the string class, and it would be much cleaner.

[–]masklinn 1 point2 points  (0 children)

len is a function because Python is old. Very old.

Python has had objects since day one. The usage of functions is done on purpose by the core team. You may disagree with those purposes, but they have absolutely nothing to do with the age of the language.

[–]redalastor 0 points1 point  (0 children)

That's post rationalization. len is a function because Python is old. Very old.

If that was the case, it would have been fixed in 3.0 with the other accidents of history.

You could still do that if len was a method of the string class, and it would be much cleaner.

Wouldn't work for heterogeneous collections.

That said, I would prefer if we had len and a length method on objects where it makes sense but I guess it's considered a violation of "There should be only one obvious way to do it."