Musings about Python syntax

Jim Althoff jima at aspectdv.com
Mon Oct 25 18:11:44 EDT 1999


At 05:02 PM 10/19/99 -0400, Guido van Rossum wrote:
>Jim Althoff <jima at aspectdv.com> writes:
>
>> At 07:03 PM 10/19/99 +0200, Fredrik Lundh wrote:
>> >hey, what makes you think len(obj) is less object-
>> >oriented than obj.len() ?  it's just syntax, you know.
>> 
>> But it IS less consistent syntax with not much advantage
>> ("del" is a different story).  So it would be very nice if
>> I could write aList.len() if I prefer that to len(aList).
>
>I think of len() and other builtin functions as a special operators,
>like + or ~ or not.  Using len(x) tells the reader more than using
>x.len() -- len(x) is guaranteed to return an int and enforces that x
>is a sequence; x.len() on the other hand cannot make such a guarantee:
>
>class MyObject:
>   def len(self): return "Spanish Inquisition"

Good points, certainly.  I guess my two-cents worth would be
this: I think that over the next few years there will be many
converts to Python coming from the Java camp.  Such converts
will expect to find functionality by seeing what methods are
associated with an object/class of interest.  I think it would be good
to err on the side of supporting a method over a function unless
there is a very compelling reason for the contrary.  I think this
goes beyond the concern of making it as easy as possible
to convert Java programmers to Python.  I think the same thing
applies to CP4E.  I don't know of any formal studies to support
this but it seems to me that it should be easier to learn a
programming language if one could as much as is reasonable
discover new functionality piece by piece through some simple
pattern such as "find an object/class of interest and look at
its methods to get a feel for its capabilities."   Happily, much
of Python fits this mold already.  For me, the more the better --
although I wouldn't want to trade myList[index] for 
myList.getItem(index).   ;-)

Jim



>
>--Guido van Rossum (home page: http://www.python.org/~guido/)
>
>-- 
>http://www.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list