Musings about Python syntax

William Tanksley wtanksle at hawking.armored.net
Tue Oct 19 09:39:12 EDT 1999


On Tue, 19 Oct 1999 16:25:19 GMT, steve_allison at my-deja.com wrote:
>Hello all,

>I've been working through the Python tutorial, and a have a few queries
>about the syntax of Python.  Python seems to me to basically be a very
>nicely constructed language, but I have been wondering about a few
>(seeming) syntactic anomalies:

>i) if Python is as object orientated as is claimed, why are things like
>len() not member functions of list/tuples ?

Because of the type/class split, really.  It's a flaw of which we plan to
be soon rid.

Someone else poionted out that member functions versus unqualified
function calls are not a valid way to distinguish OO from non-OO.  This is
true in general, but Python is a little different -- your judgement, as
tainted as it is by OO-propaganda, happens to be correct in this one case.

For an example of a language for which your rule doesn't hold (for very
good reasons), look at Dylan.

>ii) similarly, why is 'del' operator like, and not a member function of
>those types that support it ?  having an 'append' method, but a 'del'
>operator seems peculiar.

That's easy.  'del' operates on the variable, not the object contained in
it.  You can del ANY variable, regardless of whether the object it's
holding implements a __del__ method.  It results in the variable becoming
undefined and the object which it contained having its reference counter
decremented.  If it so happened that the variable was the ONLY thing which
referred to the object, the object will then delete itself -- but that's
not the job of the del keyword.

>Are these historical artefacts, or is the language designed liek tis
>for a reason ?

Yes.  :)

>this scheme ?  I have mostly really liked what I've seen of Python so
>far, but niggles like these are really annoying me!

I hope this helps.  Good luck.

>Steve

-- 
-William "Billy" Tanksley




More information about the Python-list mailing list