Compilation (was: the python name)

Peter J. Holzer hjp-python at hjp.at
Sun Jan 6 17:25:08 EST 2019


On 2019-01-06 15:09:40 -0500, Avi Gross wrote:
> [Can we ever change the subject line?]

Feel free.

> {REAL SUBJECT: degrees of compilation.}
> Peter wrote:
> 
> "... Hoever, this is the Python list and one of the advantages of
> Python is that we don't have to compile our code. So we need a
> different excuse for fencing on office chairs ;-). ..."
> 
> I understand what he means, but python does sometimes do a
> half-compilation to byte code if the compiled version does not exist
> or the file being read is newer.

This is compilation, but it isn't a separate phase. We don't invoke a
"python compiler" to produce an "executable" which we then "execute". We
invoke the interpreter on the source code, which compiles the source
code as needed (so in the literal sense it is a just in time compiler,
although this isn't what we usually mean by that term). 

And because this happens in principle every time we start a python
program (yes, there is a cache, but that is incidental) the compiler
must be fast and primitive and basically unnoticable.


> What is the purpose of compiling? Superficially, it is to catch
> serious errors.

I strongly disagree with this. The purpose of compiling is to translate
from one language into another. Typically, the source language is more
programmer-friendly, higher level and the target language is more
machine-friendly, lower level. But there are exceptions.

Finding errors is mostly a consequence of this function. If the compiler
cannot parse the source code or doesn't have enough information to
generate code in the target language, it cannot fulfill its function and
has to bail out.

There are programs with the primary purpose of finding errors: We call
these linters, static analysers, etc.

(From your other mails I guess that you almost certainly remember the
Unix distinction between cc and lint.)

Of course sometimes these are functions are conflated. Since an
optimizing compiler has to analyse variable usage anyway for efficient
register allocation it can also warn you about unused variables at
(almost) no extra cost. So it makes sense to put that warning into the
compiler (I'm less sure if it's a good idea to make this an error, as in
Go). Or the compiler might even get quite expensive checking
capabilities, as the authors think that programmers are more likely to
look at the output of the tool they have to use than to invoke a
separate, optional tool.

        hp

-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp at hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20190106/a3ad7dfe/attachment.sig>


More information about the Python-list mailing list