Compiling vs interpreting [was Re: A certainl part of an if() structure never gets executed.]

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Jun 16 16:02:57 EDT 2013


On Sun, 16 Jun 2013 12:31:59 -0700, Mark Janssen wrote:

>>>> Whats the difference of "interpreting " to "compiling" ?
>>>
>>> OK, I give up!
>>
>> Actually, that's a more subtle question than most people think. Python,
>> for example, is a compiled language. (What did you think the "c" in
>> ".pyc" files stood for? and the compile() function>?)
> 
> Careful there.  This terminology is not agreed upon universally

Which is why I said it was a more subtle question than most people think. 
Most people think that there is One True Definition of compiling/
interpreting, usually based on an over-simplified model of program 
execution that was obsolete in the 1970s.

> (that
> is, within the realm of academia where the notion of mastery exists),

The notion of mastery exists in many places, not just academia.


> and unless you are citing an actual reference or publishing one
> yourself, then you may be adding more confusion than illumination. For
> example, I would say that it is an *interpreted language* that gets
> compiled at run-time.

Apart from the contradiction there -- if it is compiled, why do you 
insist on calling it interpreted? -- you would be wrong. Languages are 
neither interpreted nor compiled. Languages are abstract entities that 
describe what syntax is permitted, and what functionality is provided. It 
is only concrete implementations which are interpreted or compiled.

In the case of Python, we have:

CPython: compiled to byte-code for it's own virtual machine;

Jython: compiled to byte-code for the JRE;

IronPython: compiled to byte-code for the .Net runtime;

PyPy: JIT compiler that generates machine code;

Nuitka: static compiler that generates machine code;

etc. So, the answer to the question "Is Python compiled or interpreted?" 
is, "Yes."



[...]
>> And these days, for many types of hardware, even machine-code is often
>> interpreted by a virtual machine on a chip. And even languages which
>> compile to machine-code often use an intermediate platform-independent
>> form rather than targeting pure machine-code.
> 
> Do you have a reference for this?  What language?

https://en.wikipedia.org/wiki/Microcode



>> The line between compilers
>> and interpreters is quite fuzzy.
> 
> It shouldn't be.

Of course it should be, because that reflects reality.


> What is fuzzy is the definition of "interpreter",
> however.  The definition of compiler has only become fuzzy with the
> advent of the personal computer.

Incorrect. Lisp predates the PC, and it is a good example of a language 
with implementations which combine features of compile-to-machine-code 
and execute-high-level-code-at-run-time (i.e. both "compiler" and 
"interpreter" behaviour, at the same time). Lisp is nearly as old as 
Fortran.

Forth is another such language. It's not quite so old as Lisp, but it is 
especially interesting because Forth includes commands to switch from 
"compile mode" to "interpret mode" on the fly. So is it a compiler or an 
interpreter? Yes.


-- 
Steven



More information about the Python-list mailing list