- If we were to double click our Python file,
it would just open in an editor, but it wouldn't do anything
with the code that we put inside.
Why is that?
Well, it's because Python is an interpretive language.
This means we have to interpret it into machine code
and we haven't run the interpreter yet.
There are three main ways to translate source code
into machine code: compile it, interpret it,
or an combination of both.
Compile, interpret?
Let me give you a real world example.
Say you need to write a letter to someone
who speaks Mandarin, but doesn't speak English.
What would you do?
You could first write it in English
then use a translation service to convert your letter
into Mandarin and mail it.
The other person would never see your original letter,
only the one that was in Mandarin.
That's basically what compilers do.
They take your high level programming language
and turn it into an executable that contains
low level machine code.
This way, users can run your code on their machine
without every needing your original source code.
Now the second option for sending out a letter
is to send it to them in English,
then they could have a friend who speaks English
read each line of the letter first
and tell them what it means in Mandarin.
Every time our Chinese friend needs to read the letter,
the interpreter will need to come back over
and reinterpret the letter.
This is essentially what computer interpreters do:
they process your source code each times its run,
line by line, and it's up to the other user
to have the needed interpreter available on their machine.
Now this is of course an over simplification
of both compilers and interpreters.
They perform complex functions that help
to optimize the size, speed,
and security of your source code,
but it helps to convey the general idea
of how they differ.
Typically, languages like C, C++, and Objective-C
are known as compiled languages, whereas PHP and JavaScript
are known as interpretive languages.
And finally, Java, C# and Python
use the combination approach.
Nowadays, the line between compiling and interpreting
is a bit blurry, as many languages
have some variants of both.
The key thing to keep in mind,
is that you may need to perform additional steps
to get your code to run on your, or someone else's machine.