Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

Chris Angelico rosuav at gmail.com
Sat Apr 5 00:49:47 EDT 2014


On Sat, Apr 5, 2014 at 3:31 PM, Mark H Harris <harrismh777 at gmail.com> wrote:
>    Its has always seemed to me that Java or C++ would be better suited to
> creating python. I wonder will C always be the standard canonical PSF python
> interpreter base language? Has the C python community considered making the
> standard base language Java or C++ ?

Java you know about (Jython); what's the advantage of C++ over C? A
Python interpreter needs to do broadly this:

1) Parse a text file into an abstract syntax tree
2) Compile the AST into bytecode
3) Execute the bytecode:
3a) Manage object lifetimes and garbage collection
3b) Perform lower-level calls
3c) Efficiently handle namespaces etc

Java has an advantage over C in that 3a can be done by the JVM. (At
least, I believe that's how Jython does it; a Python object is backed
by a Java object, and every Python object that references another
Python object is backed by a corresponding reference to the
corresponding Java object, so the JVM knows about all object
lifetimes.) C++ doesn't have that, at least not normally (and I've
never really liked most C++ garbage collectors - maybe there's a good
one that I've not yet met), so all you'd really gain is 3b, in that
you could conveniently pass jobs down to a lower-level C++ library.
(Java also gains this advantage - or maybe disadvantage, as you can
easily interface to other Java code but not so easily to C code.) Most
programming languages make it easy to talk to C code, ergo most
libraries are written for C interfaces, ergo most programming
languages don't need C++. The only case I can think of is Google's V8
interpreter (ECMAScript), which uses C++ bindings to handle scoping;
it's nice and easy as long as you embed V8 in a C++ program, and not
so easy if you're going back and forth between the two languages; at
that point, it basically reverts to a C-like interface, so there's no
advantage.

ChrisA



More information about the Python-list mailing list