PEP 3107 and stronger typing (note: probably a newbie question)

Paul Rubin http
Wed Jul 4 16:22:12 EDT 2007


John Nagle <nagle at animats.com> writes:
>      This has been tried.  Original K&R C had non-enforced static typing.
> All "struct" pointers were equivalent.  It wasn't pretty.
> 
>      It takes strict programmer discipline to make non-enforced static
> typing work.  I've seen it work in an aerospace company, but the Python
> crowd probably doesn't want that level of engineering discipline.

I think even enforced static types wouldn't cure what I see as the
looseness in Python.  There is not enough composability of small
snippets of code.  For example, the "for" statement clobbers its index
variable and then leaks it to the outside of the loop.  That may be
more of a culprit than dynamic types.  Perl and C++ both fix this with
syntax like

    for (my $i in ...) ...               (perl)  or
    for (int i = 0; i < n; i++) ...      (C++, Java)

making a temporary scope for the index variable.  Python even leaks
the index variable of list comprehensions (I've mostly stopped using
them because of this), though that's a recognized wart and is due to
be fixed.

Python would be helped a lot by some way to introduce temporary
scopes.  We had some discussion of this recently, concluding that
there should be a compiler warning message if a variable in a
temporary scope shadows one from a surrounding scope.



More information about the Python-list mailing list