Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16096

Re: Writing code to be optimizable

References <63e78437-c76b-4a9e-9a62-bfea8d078208@v5g2000yqn.googlegroups.com>
Date 2011-11-23 17:45 +1100
Subject Re: Writing code to be optimizable
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2961.1322030709.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Nov 23, 2011 at 4:19 PM, snorble <snorble@hotmail.com> wrote:
> Sometimes I want to prototype a program in Python, with the idea of
> optimizing it later by rewriting parts of it in C or Cython. But I
> usually find that in order to rewrite the slow parts, I end up writing
> those parts very much like C or C++ anyway, and I end up wondering
> what is the point of using Python in such a project.

There's a few ways to prototype. If you use Python as the language of
your specs documents (or pseudo-Python, perhaps) - consider the entire
Python implementation as ephemeral, and use it to verify that your
specifications are correct, but not for any sort of performance - then
it doesn't matter that you've rewritten it completely, nor that you've
written C code in Python. You would have been writing C code in
English otherwise, anyway.

If you're not sure which parts you're prototyping (ie will rewrite in
C/C++) and which parts you're writing properly (ie will keep the
Python version as the production code), I'd still recommend using all
of Python's best features... but keep your function docstrings
comprehensive. When you rewrite it in C, you're able to take advantage
of what you learned first time around, but otherwise it's just
strictly reimplementing the docstring in a different environment.

Chris Angelico

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Writing code to be optimizable snorble <snorble@hotmail.com> - 2011-11-22 21:19 -0800
  Re: Writing code to be optimizable Chris Angelico <rosuav@gmail.com> - 2011-11-23 17:45 +1100
  Re: Writing code to be optimizable Stefan Behnel <stefan_ml@behnel.de> - 2011-11-23 08:37 +0100
  Re: Writing code to be optimizable Roy Smith <roy@panix.com> - 2011-11-23 08:31 -0500

csiph-web