When Python outruns C++ ...

Anders J. Munch andersjm at inbound.dk
Wed Apr 2 16:27:45 EST 2003


"Dave Benjamin" <ramen at lackingtalent.com> wrote:
> In article <b6ckjr$903$1 at panix2.panix.com>, Roy Smith wrote:
> > The bottom line is exactly what Mike said: in interpreted languages,
> > the more you can push down into the libraries and interpreter core,
> > the better off you are most of the time.  And profiling helps too :-)
>
> This has been my experience as well. It is a very gratifying discovery,
> IMHO, because it encourages a less-is-more style of programming where you
> say what you mean, and little else.

The downside is that sometimes code is contorted to fit whatever has a
fast high-level implementation in the current interpreter, instead of
adapting to the nature of the problem.

For a Python example, see the Decorate-Sort-Undecorate pattern.  In
C++ the straightforward and fast solution is to use a suitable
comparison predicate.  In Python you can do the same, but that's slow,
and you are left with a choice between clarity and speed.

That coding style tends to adapt to performance accidents of the
implementation, happens in all interpreted languages.  It's a
particular problem in TIMTOWTDI languages where chosing a way then
becomes a micro-optimisation instead of a clue to the program's
structure.

- Anders







More information about the Python-list mailing list