python philosophical question - strong vs duck typing

Nathan Rice nathan.alexander.rice at
Tue Jan 3 13:28:51 EST 2012

On Tue, Jan 3, 2012 at 1:13 PM, Sean Wolfe <ether.joe at> wrote:
> Hello everybody, I'm a happy pythonista newly subscribed to the group.
> How is it going?
> I have a theoretical / philosophical question regarding strong vs duck
> typing in Python. Let's say we wanted to type strongly in Python and
> were willing to compromise our code to the extent necessary, eg not
> changing variable types or casting or whatever. Let's say there was a
> methodology in Python to declare variable types.

Do you think everyone who uses the code you write wants to deal with
your type decisions?

> The question is, given this possibility, would this get us closer to
> being able to compile down to a language like C or C++?

Declaring types would enable some additional optimizations, yes.  No,
it isn't worth it.

> What I am driving at is, if we are coding in python but looking for
> more performance, what if we had an option to 1) restrict ourselves
> somewhat by using strong typing to 2) make it easy to compile or
> convert down to C++ and thereby gain more performance.

Take a look at PyPy, with RPython.  That is the most future proof,
forward thinking way of doing what you want.

> It seems to be that accepting the restrictions of strong typing might
> be worth it in certain circumstances. Basically the option to use a
> strongly-typed Python as desired. Does this get us closer to being
> able to convert to Cpp? Does the Cython project have anything to do
> with this?

Declared typing is mostly annoying.  Implicit static typing is less
annoying, but still has issues.

Cython fills the same niche as PyPy's Rpython.  Use it if you have a
lot of C code you want to call, as you will get better performance
than a wrapper like SWIG.


More information about the Python-list mailing list