[PATCH] A compromise on case - another suggestion

Amit Patel amitp at Xenon.Stanford.EDU
Sat May 27 18:34:23 EDT 2000


 Will Ware <wware at world.std.com> wrote:
| Simon Brunning (sbrunning at trisystems.co.uk) wrote:
| > [regarding Nick M's proposal for error messages]
| > I envision this being enabled by default, to help newbies like
| > myself. Expert users should be able to disable the check via a
| > command line option if they wish.
| 
| Is there any performance hit to the clearer error messages? I would think
| (not having studied the patch) that, for code with no errors in it, the
| penalty would be only for testing the error, not for how it would be
| processed if it did happen. If that's right, there's no incremental
| performance cost for the improved error messages. Assuming experts don't
| have such brittle egos as to find the extra information offensive, it'd
| make sense to enable them all the time.
| 
| If it's correct at all, the no-additional-performance-hit reasoning should
| also apply to people who want to hook in fancier near-miss-detection
| functions (swapping letters, leaving a letter out, etc). Python could
| be the world's first dyslexia-friendly programming language. Cool.

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.

For NameError and AttributeError, misspellings, case changes, missing
'_', and forgetting 'self.' should be checked.  For indentation,
Python could check if a ':' was missing on the previous line, or if
there were any suspicious tabs involved.  For IndexError, it'd be
helpful to have some suggestions -- such as knowing what the range
was.  Instead of:

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

How about:

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

Instead of:

     >>> 1357109358*6183
     Traceback (innermost last):
        File "<stdin>", line 1, in ?
     OverflowError: integer multiplication

How about:

     >>> 1357109358*6183
     Traceback (innermost last):
        File "<stdin>", line 1, in ?
     OverflowError: integer multiplication of 1357109358 and 6183
        exceeds sys.maxint (2147483647)

A little extra computer time in analyzing errors would help save a lot
of human time.


   - Amit
-- 
--
Amit J Patel, Computer Science Department, Stanford University
http://www-cs-students.stanford.edu/~amitp/



More information about the Python-list mailing list