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

Evan Klitzke evan at yelp.com
Thu Jun 21 01:33:06 EDT 2007


On 6/20/07, kaens <apatheticagnostic at gmail.com> wrote:
> On 6/20/07, Diez B. Roggisch <deets at nospam.web.de> wrote:
>
> > That is exactly the problem - there is no "some more" static typing.
> > There is static typing - or not. You can't have it "just a bit".
>
> Couldn't a language be made so that if you declared a variable like, say:
>
> string foo = "I'm a string"
>
> it would be a string, and always a string, and if you declared a variable like
>
> foo = "i'm a dynamic variable"
>
> it would be considered dynamic?
>
> This doesn't seem like it would be too hard to add in to a language
> that already had dynamic typing (But then again, I am inexperienced -
> although interested in - language design).
>
> It seems to me like this could be really useful, but I'm not aware of
> any language implementing something like this.

I think the main issue is that while you _could_ do that, the fact
that the language allows dynamic variables essentially precludes the
possibility of doing static checks for type issues (see Terry's post
for a better explanation of the issue). So you are by and large not
going to catch type errors until runtime anyway, and this is a feature
that Python already provides (if you try to mix different types in an
incompatible way you'll get a TypeError). I think that raising an
exception is the correct way to deal with type errors in this context.

So it's not that this issue is useless, but rather that it isn't
useful enough to warrant someone implementing it. If there was a good
implementation, and people really liked it and saw how great it was, I
don't think there's any fundamental opposition to its inclusion in the
language. But this hasn't happened yet.

-- 
Evan Klitzke <evan at yelp.com>



More information about the Python-list mailing list