r/AskComputerScience • • Apr 25 '21

Does all programming turn into machine code?

I don’t know if this question makes sense but when you write code in whatever language, python, C, Java etc does it all eventually get converted into assembly and then machine code?

35 Upvotes

32 comments sorted by

View all comments

Show parent comments

2

u/Objective_Mine MSCS, CS Pro (10+) Apr 25 '21

Mainly performance.

At the simplest level, interpretation means that you have the CPU running a program A (the interpreter) that's executing another program B (the interpreted program), rather than having the code of program B executed directly on the CPU.

At runtime, interpreted program execution tend to be 2 to 100 times slower than just running a program that's been compiled into native machine code, depending on the language and the interpreter, and on which kind of code the interpreted program happens to consist of.

1

u/dgpking Apr 25 '21

Ah, and what about benefit of interpreted over compiled, easier?

3

u/Objective_Mine MSCS, CS Pro (10+) Apr 25 '21

In no particular order:

  • No need to compile in advance; mainly a matter of convenience, but can speed up the cycle of writing code and testing it when the compilation step can be skipped.

  • No need to compile the interpreted program for each target CPU or platform; only the interpreter needs to be compiled for each platform.

  • Some interpreted languages such as Python are ridiculously flexible in terms of what you can do at runtime. It might be difficult to compile all of that flexibility into machine code directly.

I don't have time to elaborate on this right now, but https://en.wikipedia.org/wiki/Interpreter_(computing)#Compilers_versus_interpreters have more on this. Googling might also help, as it's a common topic.

1

u/dgpking Apr 25 '21

Very helpful, thanks.