[PATCH] A compromise on case - another suggestion

Andrew Dalke dalke at acm.org
Sat May 27 22:32:11 EDT 2000


Amit Patel wrote:
>That'd be quite useful for me.  I've often wondered why compilers and
>interpreters don't spend enough time on error messages.  Once there's
>an error, you aren't worried about computer efficiency -- instead, I
>would think you'd want to spend computer time to help the human spend
>less time debugging.


The problem is, some 'errors' aren't errors.  You gave an example:

>How about:
>
>     >>> ['a', 'b', 'c'][5]
>     Traceback (innermost last):
>        File "<stdin>", line 1, in ?
>     IndexError: list index 5 out of range [0..3)


The IndexError check is also used to signify the end of the list, as in:

  words = ['a', 'b', 'c', 'd', 'e']
  for word in words:
     print word

The 'words' list will see an attempt to index position 5 and raise
the IndexError exception, which is caught inside of the 'for' construct.
Since the list doesn't know the context, it will go through the effort
of getting its length and making the more complicated exception.  This
can be an inner loop where there are efficiency concerns.

BTW, the failure goes from O(1) to O(N) because it has to check
every available value.  I don't know internals well enough to know
if getattr() is also affected by the patch - it shouldn't be.  That
would leave an O(1) test available.

Nick's implementation does require that people use __methods__ and
__members__ to list all of the available attributes accessed via
__getattr__()s.  I don't think those two special attributes are well
known.

There are cases where __methods__ and __members__ cannot be used
to get a list of all attributes.  Generalized wrappers, like XML-RPC
and win32 COM objects, are the obvious examples.

Extending the work, there are other types of mistakes people make than
upper/lower case.  There's extra/unneeded _under_scores_, swapped
dipthongs ("their", "thier"), and some way to say "that attribute is
really a private variable" by looking at the initial two '__'s.

Still, after two years of Python and 18 years (gasp!) of programming,
this feature isn't something I'm interested in having.

To add reminescientory flame repressent, I still remember the first
program I wrote - at least in concept:

10 PRINT "HELLO"
20 GOTO 10
30 END

However, I read the manual first, and read that the END statement wasn't
required, so I only did the first two lines.  The first "real" program I
remember writing was to find gcd/lcm of two numbers.  I think it was
menu driven as well, making it my first UI as well.  :)

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list