Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'python.': 0.04; 'prototyping': 0.07; 'subject:code': 0.07; 'python': 0.08; 'rewritten': 0.09; 'c++': 0.12; 'received:209.85.210.174': 0.13; 'received:mail-iy0-f174.google.com': 0.13; 'around,': 0.16; 'code),': 0.16; 'docstring': 0.16; 'docstrings': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'optimizing': 0.16; 'wed,': 0.17; 'language': 0.17; 'wrote:': 0.18; 'prototype': 0.18; 'rewrite': 0.18; 'written': 0.20; 'later': 0.21; '(or': 0.22; "doesn't": 0.22; 'header:In-Reply- To:1': 0.22; 'correct,': 0.23; "python's": 0.24; 'otherwise,': 0.25; 'code': 0.25; 'function': 0.27; 'message- id:@mail.gmail.com': 0.28; 'anyway.': 0.29; 'nov': 0.29; 'pm,': 0.29; 'environment.': 0.30; 'subject:Writing': 0.30; 'chris': 0.30; 'usually': 0.31; 'version': 0.32; 'wondering': 0.32; 'idea': 0.32; 'sort': 0.33; 'to:addr:python-list': 0.34; 'but': 0.37; 'received:google.com': 0.37; "there's": 0.37; 'using': 0.38; 'received:209.85': 0.38; 'ways': 0.39; "i'd": 0.39; "it's": 0.40; 'received:209': 0.40; 'to:addr:python.org': 0.40; '2011': 0.61; 'matter': 0.61; 'your': 0.61; 'order': 0.62; 'production': 0.71; 'learned': 0.73; 'completely,': 0.84; 'parts,': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=XHoRWWgJDzOWqL2RMZHsYfiNj57iWlrSaOJmYRVA4HA=; b=r1YyzYlADF6+tgR7xKkzhcY4YHXRsRHFpQhc0RNkEUq/dMK9B5C2A6y4xPwGFFm4LD kcstRkAGjC5e40AE8kOagkxz6NeR0j66nUiku8IHN+ti1S5e+/WIX04QGLWJCxzKs5w7 tqA3Oi1LxmQLdAZ+hch8mVrORpG3gkt4Cmktc= MIME-Version: 1.0 In-Reply-To: <63e78437-c76b-4a9e-9a62-bfea8d078208@v5g2000yqn.googlegroups.com> References: <63e78437-c76b-4a9e-9a62-bfea8d078208@v5g2000yqn.googlegroups.com> Date: Wed, 23 Nov 2011 17:45:07 +1100 Subject: Re: Writing code to be optimizable From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1322030709 news.xs4all.nl 6882 [2001:888:2000:d::a6]:51797 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16096 On Wed, Nov 23, 2011 at 4:19 PM, snorble 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