Conventions and static typing

"Martin v. Löwis" martin at v.loewis.de
Sat May 3 09:41:20 EDT 2003


ulkis wrote:
> After writing and
> executing a couple of tests, that idea was crushed, as I realized that
> static typing is as marginally useful and incomplete for error
> removal, as DTD:s are for validating the contents of an XML doc (an
> old pet peeve of mine).

I agree mostly. There are some common errors that with "static typing"
are detected by the compiler, in particular typos. For Python, pychecker
can detect a lot of these errors.

> Anyone who has used Visual Studio,
> JBuilder, Forte for Java, or any other reasonably modern Java or C++
> IDE, knows how comfortable it is to have a list of available
> parameters, members or other symbols, as well as documentation,
> popping up automatically or at a keypress when typing source code.
[...]
> The alternative, which is the only one I know of when it comes to
> Python, is to have the documentation handy. 

This is only because the Python IDEs are not that far advanced. A number
of these IDEs, in particular PythonWin, provide the very same features.
How? do I hear you ask. With guessing. PythonWin guesses right 
surprisingly often. I think even more can be done if somebody would put 
some effort into the IDEs.

> So what do you people think of this. Am I the only one that see this
> as a problem? Any suggestions for solutions?

Improving the tools would require hard work, but I think it would be 
worth it. Essentially, the tool needs to guess what a variable is likely 
assigned to. If it is a global variable, you often have some assignment 
early on, and perhaps a global statement somewhere; you rarely have 
cross-module assignments. For classes, you typically have the member
assignment in the class, and the object is typically called "self".
With such heuristics, I'm sure, a tool could be quite helpful.

For "life" objects, in the interactive mode, this already works
quite well.

> A nice feature is that they have conventions for
> exposing interface definitions that enable tools to interface to them
> without knowing about them in advance. 

Python is so powerful it that tools don't need conventions. Instead, 
they can learn a lot from introspection, and show doc strings to the 
users. There are a few docstring conventions, e.g. Guido wants all 
docstrings to have the signature completely in the first line, so that
IDEs can use that as a tooltip.

> I am not aware of any such
> conventions for Python, and introspection cannot (afaik) tell you much
> about the parameters since what you may have, at best, is a default
> value with a type, and in worst case **kwargs.

Tools do parse doc strings, and introspection helps them finding the 
precise names of the parameters. Displaying the parameter names to the 
user is often more helpful than displaying the parameter types.

Regards,
Martin





More information about the Python-list mailing list