TIME CAPSULE:
Hi, me in the future! You're probably super embarrassed by me right now but I'm super bored in calc. I hope you are going to graduate
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
My topic for the year is "Compilers".
I've said before that a compiler is a program that turns the code that humans type (public static void main....) into the code that computers can understand (0's and 1's). However, I am generalizing somewhat.
Any code that will be run will need to be translated into 0's and 1's eventually. A compiler is simply one of the methods of translation. Other methods include interpretation and a blend of compilation/interpretation. What differentiates these methods is the time at which translation is completed.
- Compilation: The entire program is translated before you want to run the code. The translation is done by a compiler, a program that takes your code as an input and produces the "0's and 1's" as an output.
- Interpretation: The entire program is translated when you want to run your code. The translation is done by an interpreter, a program that takes your code as an input, analyzing it and mimicking its function with its own pre-written code of "0's and 1's".
- Hybrid: The program is partially translated before run-time and is fully translated during run-time. A compiler will convert the code into an intermediate form, and the interpreter will interpret the intermediate form.
Compiling code and interpreting code have their own advantages and disadvantages, and the third method seeks to find "the best of both worlds" (-1 pt, cliche).
Advantages of Compiling Code
- Running the code is faster. The 0's and 1's produced by the compiler are in the processor's native language. An interpreter acts as an intermediary between the code and processor, and adding a third party always takes a longer time.
- Compilers error-check your program. When translating into machine language, the compiler checks syntax to make sure nothing obviously wrong happens when you run the program. If there is an error, the compiler will tell you and there will not be code generated. However, an interpreter will not check the code before it tries to run it, leading to situations where code will be almost fully run before the blatant error at the end is encountered (a great inefficiency).
Advantages of Interpreting Code
- Interpreting code is platform-independent. You can use the same code on different computers and have everything work fine. The interpreter (remember, simply a program) will compensate for differences in processors, etc. However, with compilers, the generated machine code is specific to the computer it was compiled on. This means that if you take the output (0's and 1's) from one computer to another, the new computer will quite likely not understand the program.
- Interpreters are simple to use. With a compiler, you must run a program (the compiler) to convert your code, then run the executable produced. With an interpreter, you simply give the interpreter your code, and the program will run it for you.
~
Now, on to the hybrid method. This is employed by one of the most common programming languages in the world: Java.
We can see on the left that both a compiler and interpreter are utilized for the running of the program. The compiler turns the code into an intermediate form, byte-code, that is neither the human form nor computer form. The interpreter (specifically the Java Virtual Machine) then takes the byte-code and runs it.
Advantages of the Hybrid Method
- Relatively fast: slower than compiling but faster than interpreting
- Machine-portable: The byte-code can be transferred between computers and still work, since the interpreter handles hardware differences between systems
Sources:
http://stackoverflow.com/questions/3265357/compiled-vs-interpreted-languages
http://www.programmerinterview.com/index.php/general-miscellaneous/whats-the-difference-between-a-compiled-and-an-interpreted-language/
https://thesocietea.org/2015/07/programming-concepts-compiled-and-interpreted-languages/
http://stackoverflow.com/questions/95635/what-does-a-just-in-time-jit-compiler-do
https://www.upwork.com/hiring/development/the-basics-of-compiled-languages-interpreted-languages-and-just-in-time-compilers/
No comments:
Post a Comment