The Converters
Have you ever wondered how the 'source code' gets converted to 'machine code'? 🤔
There are two ways to do this: by Compiling or by Interpreting. Programming languages will fall into one or the other, but you should understand the difference, at least at a high level.
💠What is a Compiled Language?
A compiler is a program that DIRECTLY CONVERTS your source code to machine code.
So, here you write your code but to run it, you need the compiler that will go through your code line by line and create a separate executable file. This file will contain the machine code.
I'm sure you have all come across a file that ends with a .exe. However, executable files don't always have to end this way. You can get executable files in .bat or .bin or even .com. On a Mac, you get .dmg and .app files.
The benefit of executable files is that the user can directly run the file but they never see the code. In other words, you as the programmer keep the source code and the user never sees it.
Just like a secret agent!🥸
💠What is an Interpreted Language?
An interpreter is a machine that READS the source code.
Here, you write your source code as normal. The difference is that to run the code, you DON'T need to compile your source code into machine code.
This means that the interpreter does not save your code as a separate executable file. It will interpret the code line by line whenever you want to run the program.
It can be slow like a tortoise though. 🐢
💠Is a Compiled Language better than an Interpreted Language?
The correct answer is that they both have their pros and cons. Let's take a look.
Since compiled code is an executable file, you can easily send it to different people. You can also write your code in a way that is optimized for a particular CPU (making it faster). And perhaps the largest benefit is that nobody will ever see your source code.
The downside of compiled code is that the executable file that is created, can only work on one operating system. In theory, this means that your .exe file should not be able to run on a Mac (as a side note, with how innovative developers have become, this is now possible).
There are other downsides too. Every time you want to run your code for testing, you have to take that extra step of compiling it to machine code first which takes some extra time. 🙃
With interpreted code, you don’t have to stress yourself about what kind of operating system is going to run your code. This is because you can just send source code and the other side will take care of it. In short, the interpreted code is more flexible across different CPUs.
But there are also cons. Users who want to run your code on their machine must have an interpreter for that language installed on their machine. If they don't have the correct interpreter installed, it will not run.
The second disadvantage is that the source code is available to be seen by everyone because you’re sending it to everyone who needs to run that code on their machine.
So, my dear readers, by now it must be clear to you the difference between the two converters. As programmers, it is quite important to know about the converter your programming language is using. If you find this blog informative, do drop a ❤️ and I'll see you next Saturday, in a new blog. Till then,
Learn, Share, Grow!
Bye!