[Python-ideas] string codes & substring equality

Andrew Barnert abarnert at yahoo.com
Sun Dec 1 05:33:08 CET 2013


On Nov 30, 2013, at 15:48, Guido van Rossum <guido at python.org> wrote:

> 
> On Sat, Nov 30, 2013 at 3:42 PM, Andrew Barnert <abarnert at yahoo.com> wrote:
>> On Nov 28, 2013, at 22:49, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>> 
>>> spir wrote:
>>>> (But then, possibly, some would wonder why this new ord(s,i) is not a string method ;-)
>>> 
>>> For the same reason that the existing ord() function isn't
>>> a string method, whatever that is!
>> 
>> http://docs.python.org/2/faq/design.html#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list
>> 
>> The short version is: historical reasons, and no reason to change it compelling enough to be worth the costs in backward compat, bikeshedding, etc.
> 
> That FAQ entry does not do the real motivation justice. While OO "purists" may argue about it, to me it's obvious that in quite a few cases the function spelling is more readable than the method spelling. I found it more readable 23 years ago, and I still find it more readable today. So it's not historical reasons to me, even if not everybody agrees (obviously :-).

I kind of read it the other way around--making _too many_ things methods is the historical quirk, because at some point (probably after making str and tuple and so on into full types) you and the other core devs went a bit farther with the OO-style "everything should be a method if at all possible" than you would have earlier or later in history.

But I may have been assuming too much. A lot of other "multi-paradigm" languages went through a phase like that and have a historical legacy, like C++'s ridiculous string class and JavaScript's excess of Array methods. But Python does seen to have ended up with a lot fewer quirky choices than those languages. Still, I think the various index/find/count/etc. methods didn't all need to be methods.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131130/ae31ecf8/attachment.html>


More information about the Python-ideas mailing list