Python becoming less Lisp-like

Steven Bethard steven.bethard at gmail.com
Tue Mar 15 15:51:07 CET 2005


Torsten Bronger wrote:
> paul at boddie.org.uk (Paul Boddie) writes:
>>
>>Well, I've been using Python for almost ten years, and I've
>>managed to deliberately ignore descriptors and metaclasses quite
>>successfully. I get the impression that descriptors in particular
>>are a detail of the low-level implementation that get a
>>disproportionate level of coverage because of the "hack value"
>>they can provide (albeit with seemingly inappropriate application
>>to certain problem areas).
> 
> I have exactly the same impression, but for me it's the reason why I
> feel uncomfortable with them.  For example, I fear that a skilled
> package writer could create a module with surprising behaviour by
> using the magic of these constructs.  I don't know Python well
> enough to get more specific, but flexibility almost always make
> confusing situations for non-hackers possible.
> 
> I know that such magic is inavoidable with dynamic languages, but
> descriptors will be used almost exclusively for properties, and
> therefore I think it would have been better to hard-wire properties
> in the interpreter rather than pollute the language with this sort
> of proto-properties (aka descriptors).

Certainly descriptors in the "wrong hands" could lead to confusing, 
unreadable code.  But Python is a "we're all adults here" language, and 
so we have to trust other coders to be responsible.  There are some very 
reasonable uses for descriptors which I don't believe are really 
confusing, for example the lazy property recipe:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/363602

While writing too many descriptors is a code smell, the functionality is 
there as an implementation detail of new-style classes, and I'm quite 
happy that Python trusts me enough to expose this detail for when I need it.

STeVe



More information about the Python-list mailing list