Types, Cython, program readability

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sun Mar 16 10:32:13 EDT 2008


It seems the development of Cython is going very well, quite
differently from the dead-looking Pyrex. Hopefully Cython will become
more user-friendly too (Pyrex is far from being user-friendly for
Windows users, it doesn't even contain a compiler, I think. The
ShedSkin Windows installer contains an old but working MinGW, and this
is positive). It seems Cython is going to become an efficient and
general purpose language after all, with optional static typing (its
purpose: mostly for speed), and it may even gain some kind of macros
soon. So it may even end replacing Python itself in some situations
where running efficiency is important, and where Psyco can't be used
or isn't enough.


Apparently unrelated: few days ago I was translating a 200-lines long
program from Python to D (D is mostly statically typed, like C++,
Java) for personal use. That Python program was without unit tests,
comments, docstrings, documentation, etc. So finding the types of all
the variables required some time. So I have fed the whole program to
ShedSkin, and in 20 seconds on my old PC it has produced a Python
program with full type annotations (as comments on each line of code),
that later I have translated quickly to D.

In such "blind" situations (that are often enough in some scripts I
find around) I think a statically typed program (without type
inference) can be more readable than a Python program, because even if
the programmer is super-lazy types must be present (otherwise the
program doesn't compile), and with the variable names they give me
some information that's absent (well, it's less easy to extract.
ShedSkin is often able to extract it) from the Python code.

The (little) point of this post: sometimes (when the programmer is
quite lazy) statically typed code is more "readable" than Python code.

Bye,
bearophile



More information about the Python-list mailing list