Advice from Jeff (Was Re: Is there "let binding" in Python?)
tjreedy at udel.edu
Mon Sep 15 17:12:46 CEST 2003
"Don Bruder" <dakidd at sonic.net> wrote in message
news:o0d9b.21665$dk4.674856 at typhoon.sonic.net...
> In article <mailman.1063592122.17998.python-list at python.org>,
> Jeff Epler <jepler at unpythonic.net> wrote:
> > Not an answer, but advice: when writing programs in Python,
>> write Python programs.
> Gawd, but that's profound! And on several levels... No... I'm
> But I'm also smiling.
Jeff's advice is perhaps too terse for someone not already familiar
with it. Does the following seem more helpful?
If you are writing a Python program to either learn Python or
accomplish a computing task, you will probably be happier and more
successful (in the middle to long run) if you write idiomatic Python
rather than 'literal translations' in the style of some other langauge
and *its* idioms.
The OP is not the first to more or less ask 'how do I literally
translate this foreign idiom' (which the poster may not even see as a
language-specific idiom) rather than 'how do I accomplish the same
function'. This questions usually garner the advice given above.
> > If it's your task to translate some Scheme (or any other
> > language) into Python as literally as possible, my heart goes out
> How miserable do you expect me to be translating from
> Python to C/C++ as literally as possible?
In respect to the basic data/object model, Python is more similar to
Lisp than C++. In respect to syntax, the opposite is true.
By default, Python code is generic -- it runs with any object with the
needed interface. So, unless a block is explicitly specialized to one
type with a preceeding assert or conditional, the literally 'as
literal as possible' translation to C++ is to template code. Are you
doing this, or specializing the C++ code by declaring variables and
function parameters to a particular type?
Terry J. Reedy
More information about the Python-list