A compiled language is one where the program, once compiled, is expressed in the instructions of the target machine. For example, an addition "+" operation in your source code could be translated directly to the "ADD" instruction in machine code.
An interpreted language is one where the instructions are not directly executed by the target machine, but instead read and executed by some other program (which normally is written in the language of the native machine). For example, the same "+" operation would be recognised by the interpreter at run time, which would then call its own "add(a,b)" function with the appropriate arguments, which would then execute the machine code "ADD" instruction.
You can do anything that you can do in an interpreted language in a compiled language and vice-versa - they are both Turing complete. Both however have advantages and disadvantages for implementation and use.
I'm going to completely generalise (purists forgive me!) but, roughly, here are the advantages of compiled languages:
- Faster performance by directly using the native code of the target machine
- Opportunity to apply quite powerful optimisations during the compile stage
And here are the advantages of interpreted languages:
- Easier to implement (writing good compilers is very hard!!)
- No need to run a compilation stage: can execute code directly "on the fly"
- Can be more convenient for dynamic languages
Note that modern techniques such as bytecode compilation add some extra complexity - what happens here is that the compiler targets a "virtual machine" which is not the same as the underlying hardware. These virtual machine instructions can then be compiled again at a later stage to get native code (e.g. as done by the Java JVM JIT compiler).
Answer from mikera on Stack OverflowWhich programming languages are commonly interpreted?
Some popular interpreted languages include Python, JavaScript, Ruby, Perl, and PHP. These languages are widely used in web development, scripting, and automation tasks due to their ease of use and quick development process.
How does an interpreted language differ from a compiled language?
In an interpreted language, the code is executed line by line, while in a compiled language, the entire code is converted into machine language before execution. This means that interpreted languages offer more flexibility in terms of modifying and testing code on the fly.
What are the advantages of using an interpreted language?
One advantage is that you can write code and see the results immediately, making it great for prototyping and iterative development. Interpreted languages also tend to have simpler syntax and are often easier to learn compared to compiled languages.
Videos
A compiled language is one where the program, once compiled, is expressed in the instructions of the target machine. For example, an addition "+" operation in your source code could be translated directly to the "ADD" instruction in machine code.
An interpreted language is one where the instructions are not directly executed by the target machine, but instead read and executed by some other program (which normally is written in the language of the native machine). For example, the same "+" operation would be recognised by the interpreter at run time, which would then call its own "add(a,b)" function with the appropriate arguments, which would then execute the machine code "ADD" instruction.
You can do anything that you can do in an interpreted language in a compiled language and vice-versa - they are both Turing complete. Both however have advantages and disadvantages for implementation and use.
I'm going to completely generalise (purists forgive me!) but, roughly, here are the advantages of compiled languages:
- Faster performance by directly using the native code of the target machine
- Opportunity to apply quite powerful optimisations during the compile stage
And here are the advantages of interpreted languages:
- Easier to implement (writing good compilers is very hard!!)
- No need to run a compilation stage: can execute code directly "on the fly"
- Can be more convenient for dynamic languages
Note that modern techniques such as bytecode compilation add some extra complexity - what happens here is that the compiler targets a "virtual machine" which is not the same as the underlying hardware. These virtual machine instructions can then be compiled again at a later stage to get native code (e.g. as done by the Java JVM JIT compiler).
A language itself is neither compiled nor interpreted, only a specific implementation of a language is. Java is a perfect example. There is a bytecode-based platform (the JVM), a native compiler (gcj) and an interpeter for a superset of Java (bsh). So what is Java now? Bytecode-compiled, native-compiled or interpreted?
Other languages, which are compiled as well as interpreted, are Scala, Haskell or Ocaml. Each of these languages has an interactive interpreter, as well as a compiler to byte-code or native machine code.
So generally categorizing languages by "compiled" and "interpreted" doesn't make much sense.
Python is what is called an "interpreted language," meaning that the code is compiled on-the-fly when a code is executed. Although this slows things down, the usually benefit sites say is that this means Python code is more readily sharable.
However, I am confused by how it makes the code more sharable. Here is my point of view: if you go on Unity's website, there is a version for download for Mac, Linux, and Windows; each of these use a different operating system, I understand why Unity has a different version for each of these, since the program must work in a way the operating system understands.
However, all three versions will still use C# (the coding language Unity uses), which means that a C# script file can be shared across Mac, Windows, and Linux, and still work on Unity, making C# an Interpreted Language as well, since it is sharable. This is obviously not true, but thus my confusion: What does it mean to be an interpreted language in the context of my example? In terms of shareability, C# is no different.
I am also new to computers, so maybe there is something obvious that my textbook fails to elaborate on.