Static typing
Aahz
aahz at pythoncraft.com
Fri Jul 25 18:41:15 EDT 2003
In article <mailman.1059169958.20638.python-list at python.org>,
Shane Hathaway <shane at zope.com> wrote:
>
>Well, here's a pattern I've been trying out for this purpose: use assert
>statements at the top of the function.
>
>def foo(bar, baz):
> assert isinstance(bar, int)
> assert isinstance(baz, str)
>
>I'm quite happy with the pattern, although there are a couple of
>negative points that I can think of:
>
>- It's a bit verbose, although that verbosity enables you to perform
>bounds checking and operate with other type systems like Zope's interfaces.
>
>- You can't specify the type of the return values this way.
You skipped the crucial negative: it breaks Python's name-based
polymorphism. If someone creates a class that works just like a string
but doesn't derive from the str class, your program breaks for no good
reason.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
This is Python. We don't care much about theory, except where it intersects
with useful practice. --Aahz
More information about the Python-list
mailing list