On May 7, 2013, at 10:57 AM, Daniel Fussell wrote:

> [1.1*]  I didn't know haskell could compile to multiple output forms; it 
> does make learning haskell a more appealing idea.  Isn't python able to 
> do the same thing?  I'd heard rumor that such was the case, but I'm so 
> busy maintaining someone else's perl I haven't had a chance to learn python.


I see three ways to answer this question:

1. Python programs can be "frozen" into a compiled binary so that it can run 
natively on a target OS. I've done this for Windows before. However, the binary 
is just a clever packaging of the Python interpreter with your code, still in 
Python form (well, probably byte code, which leads me to #2). So it's not 
really native executable code.

2. When the Python interpreter runs your code, by default it will generate a 
.pyc file next to your .py file that is compiled Python byte code. This is 
similar in concept to Java byte code, and this byte code is actually what the 
Python interpreter executes. Still not native executable code, but a little bit 
faster than interpreting Python source.

3. The PyPy interpreter actually does JIT compilation of your Python code into 
native machine code while it's running. This is not a translation into another 
language like C. PyPy translates Python byte code into native machine code. 
However, like most JITs, it only does this to the portions of your program that 
get executed a lot (the criteria are configurable). In my testing, certain kids 
of programs can get a 20x speedup from the PyPy JIT (e.g., most Project Euler 
solutions). However, lots of programs see no speedup at all (e.g., programs 
that are I/O bound).

I personally believe that the future of Python is PyPy.

A somewhat related note:

Another noteworthy example of a (potentially) really good toolchain is Google 
Go. Its toolchain only runs in cross-compile mode, so it's easy to support 
multiple target output binary formats (last I checked, only x86 and ARM were 
supported). And of course, Google Go compiles to native code as well, and yet 
there are also interactive shells for Go too (e.g., go-eval).

--Dave

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to