design question: no new attributes

Paul Boddie paul at boddie.org.uk
Thu Mar 1 10:04:59 EST 2007


On 28 Feb, 15:39, "Diez B. Roggisch" <d... at nospam.web.de> wrote:
> > However I will observe that
> > - entire languages are structured on the premise that dynamic
> > attribute creation can be hazardous
>
> Yup, and you are free to use one of them. And as an additional benefit, they
> will be more performant because you then can optimize the code further.

I think that's something many people miss: it can be desirable to
declare the range of attributes on instances "up front" for
optimisation purposes (in various languages other than Python), but
the advantages of not risking the occasional AttributeError shouldn't
be too readily discarded either. I'm not sure where the different
tools stand on this front, but second-guessing invalid accesses to
attributes is a completely different level to just identifying dodgy
accesses to globals or locals, along with dubious imports and "bad
practice" programming styles consisting of one or more of those more
detectable things.

Paul




More information about the Python-list mailing list