Inefficiency of __getattr__

jay.krell at cornell.edu jay.krell at cornell.edu
Wed Oct 4 07:24:55 EDT 2000


I've been a fan of static typing and C++ a while, but so far arguments based
on
    "You wrote seperate documentation anyway, right?" (JavaDoc, Python's
docstrings?..)
    "Your test cases fail quickly when you get the type wrong, right?"

stump me. I need to write more docs and test more (eh, well, there is
seperate QA at work..).
Maybe dynamic typing isn't so bad.
Dynamic typing also aids object code reuse, you know, like, no template
instantiation bloat, just one set of object code for each container. On the
other hand, the Visual C++ linker combines identical code (like, say,
std::vector<int,float,void*,long>) and the one time I looked at
link -verbose on some code that used STL a lot, this didn't even accomplish
much, because the STL was so heavily inlined.

But I still don't like
    to type lots of casts
    the perf of lots of casts in systems that check them at runtime
    Python's slow performance and/or the idea of rewriting working code in
another language to speed it up, when I could have written it in a language
with no perf problem in the first place. (Plus, people confuse Python and
other language's rapid speed of development with their libraries.)
    the idea that containers of small things, like ints or struct
Point{int,int}, are containers of small heap allocated things. I think VB
implements containers as containers of "variants", so it wins for containers
of very small things (int but not struct).

I do like the idea of "unreloaded overloads" that is overloads on type that
I are not implemented as one central typeswitch as I think is the only
option in Python.

I think Dylan has a good idea with optional/variable static type safey, the
more you declare, the more specialized the codegen. I think ML has a good
idea where the user doesn't declare many types but the compiler deduces most
of them in a static compilation phase. Template intensive C++ might approach
that, but I haven't seen it done.

 ..Jay

-----Original Message-----
From: Kragen Sitaker <kragen at dnaco.net>
Newsgroups: comp.lang.python
To: python-list at python.org <python-list at python.org>
Date: Wednesday, October 04, 2000 2:56 AM
Subject: Re: Inefficiency of __getattr__


>In article <8rep3p$e93$1 at nnrp1.deja.com>,  <lss at excosoft.se> wrote:
>...
>It's worse than that --- you need to understand what is expected of
>those attributes, semantically.  And Java interfaces don't give you
>that.
>...
>In both cases, you need automated unit tests with good coverage to
>verify even minimal conformance to the semantic requirements of the
>interface.  Such a set of tests will also tell you when you are passing
>the wrong number of arguments, or arguments of the wrong type.  You can
>typically run a few dozen to a few thousand individual tests per
>second, so the extra run time is minimal.
>...
>Whenever I see a decent library, in Python or any other language, it
>includes documentation of its interface that is sufficient to write
>code implementing the same interface.  I'm not convinced that Java's
>'interface' construct is a significant help in writing this
>documentation, although I have to admit I haven't written Java.






More information about the Python-list mailing list