Problem
I’m still trying to figure out what the difference is. Many explanations may be found online, however they tend to focus on the abstract distinctions rather than the practical ramifications.
CPython (dynamic, interpreted) and Java have accounted for the majority of my programming experience (static, compiled). There are, however, other types of interpreted and compiled languages that I am aware of. Are there any advantages or disadvantages to each type, other from the fact that executable files can be disseminated from programs written in compiled languages? People often argue that interpreted languages can be used interactively, but I assume that compiled languages, too, can have interactive implementations, correct?
Asked by chimeracoder
Solution #1
A compiled language is one in which the program is expressed in the target machine’s instructions after it has been compiled. 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 in which the instructions are read and executed by another program rather than being directly executed by the target machine (which normally is written in the language of the native machine). The interpreter, for example, would recognize the identical “+” operation at run time and call its own “add(a,b)” function with the proper arguments, which would then execute the machine code “ADD” instruction.
You can do whatever you can do in an interpreted language in a compiled language, and vice versa; both are Turing complete. Both, however, have benefits and drawbacks in terms of implementation and use.
I’m going to generalize entirely (pardon me, purists!) However, these are some of the benefits of compiled languages in general:
Here are some of the benefits of interpreting 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 recompiled into native code at a later time (e.g. as done by the Java JVM JIT compiler).
Answered by mikera
Solution #2
Only a specific implementation of a language is compiled and interpreted, not the language itself. Java is a great illustration of this. For a superset of Java, there is a bytecode-based platform (the JVM), a native compiler (gcj), and an interpreter (bsh). So, what exactly is Java now? Compiled in bytecode, natively compiled, or interpreted?
Scala, Haskell, and Ocaml are examples of compiled and interpreted languages. Each language has an interactive interpreter as well as a byte-code or native machine-code compiler.
As a result, describing languages as “compiled” or “interpreted” makes little sense.
Answered by lunaryorn
Solution #3
Consider a “blast from the past” scenario.
Once upon a time, there was a land where computing interpreters and compilers reigned supreme. The virtues of one over the other sparked a flurry of debate. At the time, the prevailing consensus was something like this:
The runtime performance of an interpreted program versus a compiled program differed by one or two orders of magnitude. Other points of distinction, such as run-time mutability of the code, were also of importance, but the main distinction was centered on run-time performance difficulties.
The scene has changed so much in recent years that the difference between compiled and interpreted data is almost meaningless. Many compiled languages use run-time services that aren’t entirely based on machine code. Furthermore, before being executed, most interpreted languages are “compiled” into byte-code. Byte-code interpreters can be very efficient, even outperforming some compiler-generated code in terms of execution speed.
Compilers generate native machine code, whereas interpreters read source code and synthesize machine code on the fly with the help of a run-time system. Today, just a few classic interpreters remain; practically all of them compile to byte-code (or some other semi-compiled state), which is then executed on a virtual “machine.”
Answered by NealB
Solution #4
The most extreme and straightforward scenarios are as follows:
With that out of the way, let me to explain why life is no longer so straightforward. As an example,
Finally, interpreting vs. compiling is a trade-off these days, with time spent (once) compiling often rewarded by greater runtime performance, but an interpretative environment allowing for more interactivity. Compiling vs. interpreting is mostly a question of how the job of “understanding” the program is divided up amongst different processes, and the boundary between the two is becoming increasingly blurred as languages and products aim to deliver the best of both worlds.
Answered by Carl Smotricz
Solution #5
From http://www.quora.com/What-is-the-difference-between-compiled-and-interpreted-programming-languages
Answered by Bhavin Shah
Post is based on https://stackoverflow.com/questions/3265357/compiled-vs-interpreted-languages