Python and C++

Hi guys,

I feel somewhat tentative asking this question but I'll bury my pride and just ask it anyway.

So I should know this by now and I think I may but I just want affirmation.

So obviously C and C++ are compiled and linked by a C++ or C toolset, this toolset such as MSVC creates an executable file and now this executable can be run. The only catch is the code may need to be compiled and assembled again on another machine especially such as if the instruction sets of processors differ( ARM and x86-64) or of course if using different operating systems.

But with a language like Python, when you create a Python application, the Python interpreter doesn't create an executable, so the python application can only be used with python itself, for example when you want to run a Python3 program you will do something like this
Python3 helloWorld.py

Here I am guessing Python3 is the executable(program) and Python3 takes an argument of the script you want to run. So helloWorld.py will be interpreted and thus run by the Python3 exe.

Am I right by thinking this?

Thanks
Last edited on
Yes, that's correct.
Thanks Helios.

I'm guessing it's similar for other languages such as Java?

Also curious to know if there is any other high level languages that create direct executables like C and C++.
More correctly, the distinction between compilation and interpretation is a matter of implementation. Nothing prevents anyone from writing a C++ interpreter, or a Python compiler, although some languages are more amenable than others to having a REPL-style interactive console like Python does.

To answer your question, though, Java is JIT compiled rather than AOT compiled like C++. The development-time compiler generates a file in JVM bytecode. This is similar to what happens when you compile a .py file to .pyc. Unlike Python, however, when you load a .jar file into the JVM, rather than interpreting the VM instructions directly like Python's VM does, the runtime produces machine code that can run directly on the hardware. The JIT is why Java programs were always famous for taking a long time to start. Computers have gotten a lot faster since 1995, when it appeared, but JIT compilation is still slower than just loading machine code to memory, and it still produces worse code than AOT compilation.

There's plenty of languages that are capable of being AOT compiled to machine code. Fortran, Common Lisp, and Haskell are a few examples that come to mind, although not the only ones by a long shot. Also, what a lot of new programming language implementations do is, instead of investing a lot of time into developing a full compiler, with all the inherent problems that entails, they just develop a transpiler to C, and then simply hand its output to GCC or (increasingly frequently) Clang.
helios wrote:
develop a transpiler to C

Wasn't that something like the original C++ "compiler" by Bjarne Stroustrup, Cfront?
Yes, back when it was C with classes.
Topic archived. No new replies allowed.