Compilation vs Interpretation

In this lesson, we’ll be overviewing the differences between compiling and interpreting a programming language in modern-day computing programmers have the choice now between many different programming languages the choice of a programming language depends on many different factors such as what platforms the programmer wants to develop for or kinds of applications the programmer wants to create whether that be a web application mobile or desktop game or even an operating system one other factor that will usually weigh in on a programmers decision to prefer one language over another could be whether that particular language is usually compiled or interpreted notice my careful use of the word usually in the last sentence this is because languages are independent of how they are actually implemented it’s not that one language can’t be interpreted or can’t be compiled but.

Today most languages naturally fall into these categories given their feature set and the tools that have been made available for them just wanted to get this out of the way since a lot of programmers seem to think otherwise okay moving on let’s picture a simple scenario where I the programmer wants to send out my coded application to you the consumer the first way I could do this would be to compile the program on my computer using a compiler which would take my human-readable source code and convert it to its binary machine code equivalent after this process is complete I now have two separate files one original file containing my source code and another excusable file containing the binary code for the CPU on a certain computer to run now I can send you the consumer the binary executable file and then you can run my application the second way of distributing and running my application would be through interpreting my program source.

With the use of what’s called an interpreter in this method I would send you the actual source code I wrote instead of a compiled excusable file with my source code in hand you would then download an interpreter program for your machine and then you could take my source code and interpret it on the fly into a running program but what exactly do I mean on the fly in the compiling sin Aereo the entire program source code is converted first before any computer can run it this way my entire program is already translated into its binary form ready for the CPU to execute in the interpreting scenario I send you my original source code for which the interpreter goes through one line at a time converting each line to its binary equivalent and then executing that line immediately before moving on to the next line so what are the advantages and disadvantages of these two approaches well let’s start with compilation compiling a program is always going to be faster than interpreting.

One if speed is your main concern then you’ll probably want to precompile your language also compiling a language first means that your original source code is kept private as no one will be able to read your optimized machine code whereas with interpreted languages your source code is freely distributed to the public so anyone can see exactly how your program works some of the disadvantages of pre-compiled programs include having to recompile your program for specific platforms this means that you would have to make sure you created separate binaries for Windows computers Mac computers and Linux computers and even then you would have to create CPU specific binaries from within those platform builds this means compilation is not cross-platform and is pretty inflexible also during development compilation requires an extra step actually compiling your program.

Each time you want to run your application for debugging purposes for bigger projects this extra step can add a considerable amount of time to a program’s development for interpretation we’ve already mentioned most of its disadvantages as it’s often slower given its line by line translation in real-time and it’s freely distributed source code however interpretation also flips most of the disadvantages of compiled languages on their head interpretation is cross-platform so the programmer only needs to really distribute one file instead of 20 and let the interpreter program on the consumer’s machine do the rest interpreting a language also makes things easier to debug since we don’t have to worry about the extra step of compiling every time we want to check our code our story though doesn’t end here over the years computer engineers have been exploring techniques to speed up the interpretation process today the process for certain languages most notably c-sharp and Java have expanded to utilize what’s known as an intermediate language or bytecode and a JIT or just-in-time compiler with these techniques added.

The programmer would now compile their program first into bytecode or il and send that code over to the consumer this has two distinct advantages over normal interpretation one the programmer no longer has to send over their original source code and to this new intermediate code has been slightly optimized and is closer to the machine meaning that translation from it to machine code is much quicker once transferred that bytecode or il code can then be converted into machine code by the JIT compiler this speeds things up tenfold because now the JIT compiler can optimize our bytecode even further before it’s run on the machine if you want to know more about this process and the relationship between interpreters JIT compilers and bytecode then click here so which languages are normally compiled versus interpreted normally languages such as C C++ and Objective C are compiled while languages such as PHP JavaScript Java C sharp and Python are interpreted although with PHP and JavaScript their interpreters don’t have the extra functionalities of using bytecode and JIT compilation I hope this lesson served as a good overview for the concepts of compilation versus interpretation.

Leave a Comment