News for hackers. Stuff that matters.
Re:Ruby 2.0.0 Released by _ZeD_ on Monday February 25, 2013 @12:14AM (#5277418)
In java the arrays objects expose a public int attribute called .length. The strings also expose a .length attribute, but it's a method. If, for some reason, you need to know how many elements are in enum, you need to call NameOfTheEnum.values().length. If you have a Collection (a Map, a List...), you need to call .size(). ...

Yeah. You are right about the fact that a possible "convention" would be to call .len, not .__len__ but you are forgetting 20+ years of backward compatibility.

I don't know when len() was introduced, and I'm not sure it's initial implementation was a simple "return object.__len__()" (or an equivalent...). What I know is that an explicit len function helped to hide the eventually different implementation details, and allowed the developers of the containers go crazy with attributes.

Moreover, with a len(obj) function and a obj.len() "public" method, you have two ways to do it.

Re:Ruby 2.0.0 Released by philwelch on Monday February 25, 2013 @02:19AM (#5277750)
I'm not sure why Python has to be backwards compatible with Java, given that Python is a totally different language released four years before Java.