There are genuine benefits and downsides to both methods.
Fig 1.7.1: The pros (✔) and cons (✖) of compiler and interpreter
Compiled languages can often create faster programs because you've done the conversion in advance. But one downside is that because machine code is platform specific, if you compile your program so it runs on a PC, that means it won't work on a Mac. Similarly, if you compile your program so it runs on a Mac, that means it won't work on a PC.
Some languages support compiling multiple different versions of your program for different operating systems and with interpreted languages. They're often cross-platform because as long as the person you're sending your source code to has the interpreter, you don't care what operating system they use. However, interpreted programs can run slower because the conversion still has to happen in addition to running the program.
On top of that, with interpreted languages, you also have to give your source code to whoever wants to run your program. It could be both a benefit and a hazard.
Option number 3: Intermediate State
This is somewhere in the middle of compiler and interpreter. Modern languages often try to compromise by having programs that can be partially compiled into an intermediate state or in-between state. It’s what's often called intermediate language. Another term is bytecode.
It's a way that you can do as much of the compilation as possible in advance, but not quite all the way to that platform specific machine code, leaving the final step. This is what's often called “just in time” compilation. It is done on the computer of whoever is running the program.
Fig 1.7.2: The intermediate process
Now, all of these options are important to know, but they aren’t something you need to worry that much about or even have to make a decision on. That’s because most programming languages naturally fall into either compiled or interpreted or in between categories. There are always edged cases and exceptions.
Here’s a handful of examples here of what's most common for some programming languages.
Fig 1.7.3: Some compilation models
C ++, Swift, C and objective-C are typically just compiled. JavaScript, Python and PHP are typically interpreted languages. The best-known language that takes that middle ground (hybrid intermediate approach) is Java.
However, you don't choose a language just for its compilation model. You will decide on the language for other reasons like what platform or type of application you’re making. Then you'll need to understand the way that source code in that language actually makes it onto the CPU.
Having covered that, it's about time we dive a little deeper into some specifics.