Is this a good idea or a waste of time?
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Thu Aug 24 16:08:59 EDT 2006
In <1156449402.022781.292840 at p79g2000cwp.googlegroups.com>, asincero
wrote:
> def foo(a, b, c, d):
> assert type(a) == str
> assert type(b) == str
> assert type(c) == int
> assert type(d) == bool
> # rest of function follows
>
> This is something I miss from working with more stricter languages like
> C++, where the compiler will tell you if a parameter is the wrong type.
> If anything, I think it goes a long way towards the code being more
> self documenting. Or is this a waste of time and not really "the
> Python way"?
Not really the Python way I'd say. What if `c` is of type `long` for
instance? Your code would stop with an assertion error for a value that
should work. Strict type checking prevents "duck typing" which is a quite
fundamental concept in Python.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list