Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40175

Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <msarro@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'interpreter': 0.04; 'subject:Python': 0.05; 'compiler': 0.05; 'debug': 0.05; 'debugging': 0.05; '(so': 0.07; 'c++,': 0.07; 'dynamically': 0.07; 'executable': 0.07; 'executed': 0.07; 'interpreted': 0.07; 'interpreter.': 0.07; 'python': 0.09; '(without': 0.09; 'executes': 0.09; 'here?': 0.09; 'portable': 0.09; 'subject:Why': 0.09; 'subject:create': 0.09; 'that).': 0.09; 'tracing': 0.09; 'troubleshoot': 0.09; 'windows,': 0.09; 'cc:addr :python-list': 0.10; 'language,': 0.11; 'language': 0.14; 'do,': 0.15; 'weird': 0.15; '(there': 0.16; 'appreciated!': 0.16; 'c++.': 0.16; 'cc:name:python list': 0.16; 'compile,': 0.16; 'compilers': 0.16; "computer's": 0.16; 'example)': 0.16; 'googled': 0.16; 'hardware.': 0.16; 'hex': 0.16; 'jobs.': 0.16; 'longer.': 0.16; 'necessity.': 0.16; 'osx': 0.16; 'perl.': 0.16; 'subject: \n ': 0.16; 'write.': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'tend': 0.17; 'thu,': 0.17; 'creates': 0.18; 'memory': 0.18; 'feb': 0.19; 'variable': 0.20; 'email addr:gmail.com&gt;': 0.20; 'written': 0.20; 'sort': 0.21; 'trying': 0.21; 'java': 0.21; 'exceptions': 0.22; 'gcc': 0.22; 'machine.': 0.22; "i'd": 0.22; 'cc:2**0': 0.23; 'programming': 0.23; 'elements': 0.23; 'device': 0.24; 'specifically': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'wrote': 0.26; 'compiled': 0.27; 'guess': 0.27; 'language.': 0.27; '(we': 0.27; 'message-id:@mail.gmail.com': 0.27; 'run': 0.28; 'cpu': 0.29; 'fast.': 0.29; 'mid': 0.29; 'perl': 0.29; 'subject:like': 0.29; 'url:mailman': 0.29; 'skip:& 10': 0.29; 'source': 0.29; "i'm": 0.29; 'code': 0.31; 'point': 0.31; 'url:python': 0.32; 'running': 0.32; 'url:listinfo': 0.32; 'int': 0.33; 'programming,': 0.33; 'purposes,': 0.33; 'handle': 0.33; 'languages': 0.33; 'skip:& 20': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'architecture': 0.34; 'wrong': 0.34; 'faster': 0.35; 'follows:': 0.35; 'said,': 0.35; 'so,': 0.35; 'doing': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'add': 0.36; 'really': 0.36; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'operating': 0.36; 'possible': 0.37; 'editor': 0.37; 'does': 0.37; 'level': 0.37; 'why': 0.37; 'ones': 0.37; 'systems,': 0.37; 'virtual': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'mean': 0.38; 'some': 0.38; 'solve': 0.62; 'between': 0.63; 'capable': 0.63; 'different': 0.63; 'love': 0.63; 'more': 0.63; 'direct': 0.69; 'benefit': 0.70; 'hand': 0.82; 'low': 0.83; '(your': 0.84; '2013': 0.84; 'around,': 0.84; 'compiles': 0.84; 'level"': 0.84; 'pain': 0.84; 'dennis': 0.91; 'reasoning': 0.91; 'remember,': 0.93; 'ultimate': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=upBj48eh3oI/G3iA3FgfrB59ebuHIwOyXYjyQyca4cw=; b=Igo8H2P3kgzyhmi/e9Yn+0fpwy7yuQ7/P4utmkLVnQIc2Q+1hPcsYm8viKhWSvIYJ0 y7cCb0rfNPa/OejqFTLn98kpx8IWJcCrZ5fTDq8aD3ziIjiJjtsv2/qOrO7TwyCbTDug KE+yFP8CKREDQKrNyxoJUH0o4TTqgBAw6JH4ER5VTwMc4e58wCa+788iLtG4iS5UOGvO GUHDW4DYlqsCGFlIflxxFL7QkB1fKGNyW7vWisOwIdPI57brOfdl8GsiAkXMu1mqVYCn yTIY5b2XNC5YrK/xEhe7ArNe3iCJm60RJcZCR2vvMvKXTlcU++gmnFn0G5/JumkXmZab 5WTg==
MIME-Version 1.0
X-Received by 10.68.237.165 with SMTP id vd5mr11270627pbc.52.1362084601097; Thu, 28 Feb 2013 12:50:01 -0800 (PST)
In-Reply-To <b428fdef-a577-45c0-b37c-60bde74e3ae1@googlegroups.com>
References <b428fdef-a577-45c0-b37c-60bde74e3ae1@googlegroups.com>
Date Thu, 28 Feb 2013 15:50:00 -0500
Subject Re: Why is it impossible to create a compiler than can compile Python to machinecode like C?
From Matty Sarro <msarro@gmail.com>
To kramer65 <kramerh@gmail.com>
Content-Type multipart/alternative; boundary=047d7b338f1fcd799704d6cf08bd
Cc Python list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2675.1362084610.2939.python-list@python.org> (permalink)
Lines 173
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1362084610 news.xs4all.nl 6939 [2001:888:2000:d::a6]:41982
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:40175

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

Python is an interpreted language, not a compiled language. This is
actually a good thing! What it means is that there is a "scripting engine"
(we just call it the interpreter) that actually executes everything for
you. That means that any operating system that has an interpreter written
for it is capable of running the exact same code (there are lots of
exceptions to this, but in general it is true). It makes code much more
portable. Also, it makes it easy to troubleshoot (compiled programs are a
pain in the butt unless you add additional debugging elements to them).

A compiled program on the other hand must be specifically compiled for the
destination architecture (so if you're trying to write an OSX executable on
windows, you need a compiler capable of doing that). So doing any sort of
cross platform development can take significantly longer. Plus then, as I
said, debugging will require additional debug tracing elements to be added
to the code you write. The benefit though is that compilers can optimize
code for you when they compile, and the compiled code will tend to run
faster since you're not dealing with an interpreter between you and the
machine.

Now, there are places where this line is blurred. For instance perl is an
interpreted language, but capable of running EXTREMELY fast. Python is a
little slower, but significantly easier to read and write than perl. You
also have some weird ones like JAVA which actually have a virtual machine,
and "half compile" source code into java "bytecode." This is then executed
by the virtual machine.

I guess the ultimate point is that they're all designed for different
purposes, and to solve different problems. Python was intended to make
fast-to-write, easily understandable, easily portable code which can be
executed on any system which has the Python interpreter. It's not really
intended for things which require lower level access to hardware. It's what
we call a "high level" programming language.

C (your example) was intended for very low level programming, things like
operating systems, device drivers, networking stacks, where the speed of a
compiled executable and direct access to hardware was a necessity. That's
what Dennis Ritchie wrote it for. We call it a "mid level" programming
language, or a "low level" programming language depending on who you talk
to. I'd have to say mid level because low level would be writing in
assembly or playing with a hex editor :)

Different tools for different jobs.

HTH.

-Matty


On Thu, Feb 28, 2013 at 3:25 PM, kramer65 <kramerh@gmail.com> wrote:

> Hello,
>
> I'm using Python for a while now and I love it. There is just one thing I
> cannot understand. There are compilers for languages like C and C++. why is
> it impossible to create a compiler that can compile Python code to
> machinecode?
>
> My reasoning is as follows:
> When GCC compiles a program written in C++, it simply takes that code and
> decides what instructions that would mean for the computer's hardware. What
> does the CPU need to do, what does the memory need to remember, etc. etc.
> If you can create this machinecode from C++, then I would suspect that it
> should also be possible to do this (without a C-step in between) for
> programs written in Python.
>
> Where is my reasoning wrong here? Is that because Python is dynamically
> typed? Does machinecode always need to know whether a variable is an int or
> a float? And if so, can't you build a compiler which creates machinecode
> that can handle both ints and floats in case of doubt? Or is it actually
> possible to do, but so much work that nobody does it?
>
> I googled around, and I *think* it is because of the dynamic typing, but I
> really don't understand why this would be an issue..
>
> Any insights on this would be highly appreciated!
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Why is it impossible to create a compiler than can compile Python to machinecode like C? kramer65 <kramerh@gmail.com> - 2013-02-28 12:25 -0800
  Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Matty Sarro <msarro@gmail.com> - 2013-02-28 15:50 -0500
    Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-01 02:55 +0000
  Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Stefan Behnel <stefan_ml@behnel.de> - 2013-02-28 22:03 +0100
    Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-01 03:47 +0000
      Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? alex23 <wuwei23@gmail.com> - 2013-02-28 20:31 -0800
      Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Stefan Behnel <stefan_ml@behnel.de> - 2013-03-01 08:48 +0100
        Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-02 01:49 +0000
  Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Chris Angelico <rosuav@gmail.com> - 2013-03-01 08:10 +1100
  Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Stefan Behnel <stefan_ml@behnel.de> - 2013-02-28 22:17 +0100
  Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Dave Angel <davea@davea.name> - 2013-02-28 16:18 -0500
  Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Modulok <modulok@gmail.com> - 2013-02-28 14:19 -0700
  Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Jonas Geiregat <jonas@geiregat.org> - 2013-02-28 22:33 +0100
  Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Nobody <nobody@nowhere.com> - 2013-02-28 22:01 +0000
  Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Terry Reedy <tjreedy@udel.edu> - 2013-02-28 17:06 -0500
  Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-28 21:09 -0500
  Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-01 04:27 +0000
  Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? alex23 <wuwei23@gmail.com> - 2013-02-28 20:38 -0800
  Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? 88888 Dihedral <dihedral88888@googlemail.com> - 2013-02-28 22:21 -0800
  Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Grant Edwards <invalid@invalid.invalid> - 2013-03-04 16:36 +0000
    Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? CM <cmpython@gmail.com> - 2013-03-04 14:55 -0800
      Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? 88888 Dihedral <dihedral88888@googlemail.com> - 2013-03-04 15:12 -0800
      Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Terry Reedy <tjreedy@udel.edu> - 2013-03-04 19:31 -0500
      Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Chris Angelico <rosuav@gmail.com> - 2013-03-05 11:33 +1100
      Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Benjamin Kaplan <benjamin.kaplan@case.edu> - 2013-03-04 16:27 -0800
    Re: Why is it impossible to create a compiler than can compile Python to machinecode like C? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-05 01:35 +0000

csiph-web