python improvements (Was: Re: New Language)

Steven D. Arnold stevena at permanent.cc
Fri May 12 22:56:11 EDT 2000


Hi Martijn,

At 10:07 PM 5/12/2000 +0000, Martijn Faassen wrote:
>Steven D. Arnold <stevena at permanent.cc> wrote:
>[snip]
> > 1. I'd like an equivalent to perl's "use strict" pragma.  It's annoying to
> > have to be so paranoid about making a typo in a variable name.  I'd like
> > the compiler to be able to catch those errors for me.
>
>How exactly would this work? It would seem hard to make this work
>right in a dynamic language, but perhaps I'm missing some simple
>strategies. I'm not familiar enough with 'use strict' in Perl to know
>what Perl is doing in this respect.

In perl, `use strict' means that you must declare that a variable will be 
used in a function before you use it.  In python, the following error is 
possible:

def foo(bar):
     doh = bar * bar
     return duh + 5

With a strict pragma, it'd be more like this:

def strict foo(bar):
     declare doh
     doh = bar * bar
     return duh + 5

Since `duh' was never declared, you'd get a compile-time error.


>  It'd be nice to have a bit
>more compile-time checking, but Python's extremely dynamic, so this
>would seem very hard to do in the general case. Perhaps for
>local and variables it'd be possible, but attributes are tougher;
>we have __getattr__(), after all.

Yes.  The strict pragma would not affect class attributes, at least not as 
I'm describing it.  It would only affect variables directly used in the 
function.  A class could also use the strict pragma; such a thing would 
only affect variables used at the class scope.


> > 2. I'd like the ability to specify that a certain parameter or variable is
> > of a given type.
>[snip]
>
>Ooh, lots of us would! Join the types-SIG. :)

*grin*


>You seem to want DOC and ERR mostly.

Yes, though of course I also favor anything that improves performance with 
no significant sacrifices. ;-)


>There's also a counter force, let's call it RAD:
>
>RAD -- we want to develop our systems rapidly. We want interfaces that can
>        deal with lots of inputs, without having to think about it a lot.
>        Dynamic typing helps us set these up without hassle.

I agree with the poster who said that any such tools must be optional.  Any 
variable may be declared to be of a specific type or not.  In Objective-C, 
a variable of no particular type was declared as type `id'.  This was 
essentially a generic object pointer.

Thanks for the links, also. :-)


--
Steven D. Arnold          Que quiero sera           stevena at permanent.cc
"We choose to go to the moon in this decade and do the other things, not
because they are easy, but because they are hard."    -- John F. Kennedy





More information about the Python-list mailing list