On 2/28/06, Terry Reedy <tjreedy at udel.edu> wrote: > > "Greg Ewing" <greg.ewing at canterbury.ac.nz> wrote in message > news:44052636.9090709 at canterbury.ac.nz... > > And you don't think there are many different > > types of iterables? You might as well argue > > that we don't need len() because it "only > > applies to sequences". > > Since you mention it..., many people *have* asked on c.l.p why len() is a > builtin function rather than a method of sequences (and other collections) > (as .len, not .__len__). Some have suggested that it should be the latter. > The answers justifying the status quo have been twofold. > > 1. Before 2.2, not all builtin sequence types had methods (str and tuple), > so they could not have a .len method. (This begs the question of why not, > but that is moot now.) Well, up until 2.2 you didn't have new-style classes which have a common base class. And if you wanted to do the length compilation only when requested, you needed a method. But now with object, we could add extra smarts to __getattr__ or __getattribute__ so that if ``spam.len`` is requested it calls ``spam.__next__()`` for you, basically a poor-man's property. Or, if ``spam.len`` is defined, return that. But moving over to more attributes for how we access basic interfaces seems great to me. -Brett
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4