Dreaming of new generation IDE

Paul Rubin no.email at nospam.invalid
Wed Feb 3 15:42:52 CET 2010


Jean-Michel Pichavant <jeanmichel at sequans.com> writes:
> class.method(string name, int count):
> """Return the cap'tain's age.
>
>    name: a string giving the name of the cap'tain daughter
>    count: an int giving the number of fingers left in the cap'tain
> right hand
> """
>
> In python, attributes/parameters have no type (but you know that). By
> specifying them in the method signature, you're just duplicating the
> information hold in the docstring.

It's not enough to just document (except as an aid to remembering) since
the compiler and runtime don't enforce the documentation.  You have to
use static typing or write tests, to flag all the call sites if you
change the signature.  One nice trick with static types is if you change
what the method does (even if its type signature doesn't change), you
can rename the method:

   class.method2(string name, int count):  # change 'method' to 'method2'

and recompile your codebase.  Every place in the code that called
'method' now gets a compile time "undefined method" error that you can
examine to see if you need to update it.  This is something you can't
catch with unit tests because the call sites can be in distant modules.



More information about the Python-list mailing list