In article <3f23ae06$0$21093$626a54ce at news.free.fr>, "Bruno Desthuilliers"
Michael Muller wrote:
Interface documentation may be obtained in others ways (docstring for
Yes, and that's the way that I do it now. But the problem with this is
that it's "non-binding": it doesn't impose any programmatic constraints.
Because of this:

- it's hard to enforce automatically (if you want to make sure that all
programmers in your team are using the prescribed argument definition
conventions, you have to parse all the docstrings)

- there is no global standard (I might use "name: type info" in my
docstring, you might use "type name")

- it is hard to guarantee that the documentation is in sync with the code
(if you change the type expectations of a function, you can do so without
changing the documented expectations)

- it makes type errors less obvious (you end up getting an attribute
error when you perform an operation on the value instead of a type error
when you initially abuse the interface) Although, I must say that this is
surprisingly less of a problem in Python than one might expect.
And I'm not sure static typing would optimize anything, but not being a
Python (nor anything else) guru, I would not bet my hand on this... my 2
In and of itself, static typing does not optimize anything. In fact, it
could slow things down because you suddenly have to do typechecks all over
the place.

Static typing can be /used/ for optimizations because it allows for
optimized forms of attribute access - without it you must do dynamic name
resolution at runtime.

For example, if you want to resolve a method name, you currently have to
look up the method name in the object and its classes. With static
typing, since you know the type of the object at compile time, you can
just reference it in a "vtable" (a virtual function table) associated with
the object.

In short, static typing brings us one step closer to "python compiled to
machine code".

Remove the spam and filter components to get my e-mail address.

Search Discussions

Discussion Posts


Follow ups

Related Discussions



site design / logo © 2022 Grokbase