What's the difference between compiled language and interpreted language?
Well, yeah. I was kinda curious about this question for some time, but I just did not have a time to really just google this. So let me do it now. Oh. And I mean, before this, I knew like something is really different between these two languages. For example, running a for loop looks like this:
Bash Shell script
Python
Ruby
C++
Java
well. I already notice some differences (Bash Shell Script & Python & Ruby vs C++ & Java), although I don't know if they are really important:
Language |
Interpreted |
Compiled |
Need to include libraries in the source file? |
No |
Yes |
Need a syntax to recall variables (something like ${ } or $ or #{ } ...) |
Yes |
No |
Semicolon to mark the end of a line of codes |
No |
Yes |
Syntax for for-loop is: for X in SomeList DoSomething |
Yes |
No |
Can be run directly without compilation? |
Yes |
No |
Need to have main method(function) to run a program? |
No |
Yes |
Alright. But what really makes these differences that I can observe from the codes? I then (finally) googled and put the explanations and differences into a table. Notice, importantly, that the language features that I discovered are pretty much useless(?):
Language |
Interpreted |
Compiled |
Instruction execution |
Instructions are not directly executed by a machine. They are converted (to an abstract syntax tree, vm byte code, machine code... etc) and executed by some other program (Interpreter) written in language of native machine. |
The original program is directly translated to native machine instructions to be executed by a machine. |
Relative speed |
For above reason, slower. "Interpreters can be 2 to 10 times slower than compilers. One reason for this is that they translate the same statements within a loop over and over again. Compilers can produce much more efficient object code than interpreters thus making the compiled programs to run faster." If there is a for loop, compiler will translate the statement once and execute it for n times. But an interpreter cannot do that. It needs to interpret the code for n times. |
For above reason, faster. Overhead for translation occurs only once. |
Pre-work(i.e. compilation) needed to execute the program |
No. Run on the go. |
Yes. |
More control over hardware aspects |
No |
Yes |
General language features (only general. this may not perfectly apply to all). Be warned that this part is more of for interest, because the 99% of difference between interpreted and compiled language come from the implementation, not the language itself. |
|
- |
Debugging: relative difficulty |
Easier |
Harder |
And I almost missed this great chart from upwork.com. It pretty much summarizes the differences and pros and cons:
Strange languages?
Java. Bytecode language. It falls under the category of both interpreted and compiled language. thesocietea.org summarizes it quite well:
Java. Bytecode language. It falls under the category of both interpreted and compiled language. thesocietea.org summarizes it quite well:
In a bytecode language, the first step is to compile the current program from its human-readable language into bytecode. Bytecode is a form of instruction set that is designed to be efficiently executed by an interpreter and is composed of compact numeric codes, constants, and memory references. From this point, the bytecode is passed to a virtual machine which acts as the interpreter, which then proceeds to interpret the code as a standard interpreter would.
Yeap. So Java is actually a very special language. Lol.
But what still remains in my question, is the strikingly similar language features shared especially among interpreted languages. Is it just a coincidence or what? I need to find this out in later posts. Keep an eye on this.
But what still remains in my question, is the strikingly similar language features shared especially among interpreted languages. Is it just a coincidence or what? I need to find this out in later posts. Keep an eye on this.
Sources:
https://stackoverflow.com/questions/3265357/compiled-vs-interpreted-languages
https://stackoverflow.com/questions/2657268/whats-the-difference-between-compiled-and-interpreted-language
https://www.ibm.com/support/knowledgecenter/zosbasics/com.ibm.zos.zappldev/zappldev_85.htm
https://thesocietea.org/2015/07/programming-concepts-compiled-and-interpreted-languages/
https://www.sqa.org.uk/e-learning/ClientSide01CD/page_13.htm
https://stackoverflow.com/questions/3265357/compiled-vs-interpreted-languages
https://stackoverflow.com/questions/2657268/whats-the-difference-between-compiled-and-interpreted-language
https://www.ibm.com/support/knowledgecenter/zosbasics/com.ibm.zos.zappldev/zappldev_85.htm
https://thesocietea.org/2015/07/programming-concepts-compiled-and-interpreted-languages/
https://www.sqa.org.uk/e-learning/ClientSide01CD/page_13.htm