--> Difference Between Compiler and Interpreter [Must Read] - TechTrickHD.Com
Home Reviews

Difference Between Compiler and Interpreter [Must Read]

Difference Between Compiler and Interpreter 2020 Easily Explained


Many people want to know what is the difference between compiler and interpreter.
The difference between compiler and interpreter is easily explained in this article. I'm sure you will learn something new about the difference between compiler and interpreter.



 Difference Between  Compiler and Interpreter 2020 Easily Explained
 Difference Between  Compiler and Interpreter 2020 Easily Explained


We need to get our source code converted into machine code somehow before it can run.
There are two main ways of doing this what's called compiling the source code and what's called interpreting the source code.

Now luckily this is not a big decision you have to worry about most languages. you'll deal with will naturally fall into one or the other but it is worth knowing the difference between compiler and interpreter. so let's have a simple scenario let's say it's just you and me you have your computer and I have my computer and you're going to write a program that you want me to run now with a compiled language what happens is you write your source code and then you have a program called a compiler that will go through that source code and create a separate file that contains the machine code and you just give me that file this end result is sometimes referred to as an executable or an executive or file.
Because I can directly execute it I can now just run your program you keep your source code and I never see it now with an interpreted language on the other hand you don't compile your source code beforehand. You just give me a copy of it.
I'll need my machine to interpret it whenever I want to run your program.
Now interpreter is different to a compiler. It does this on the fly we can think of. It as going through your source code line by line and processing it on the spot it does not save it as a separate machine code file.
Now you've used interpreted languages even if you don't know it. Whenever you've looked at a web page with JavaScript which if you've surfed the web for more than two minutes in your life you have this is what's been happening. The JavaScript has been sent to you over the web along with a bunch of other files like webpages and images and it's been sent as source code onto your machine and your web browser has just interpreted that JavaScript.
So it can run that code so which one's best while they both have their good and their bad points benefits of compiled code once it's compiled it's immediately ready to run and you could send it to a hundred or a thousand or a hundred thousand different people.
It's ready to go it can be optimized for a CPU so it can actually be faster and you don't have to send your source code to everybody which might be a good thing however the downsides are if I compile it on a PC that executable file won't work on a Mac, in fact, it often needs to be compiled separately for different kinds of CPU even on the same platform.
When you're writing code to compile is an extra step that you have to take every time you want to test your program. Now with interpreted code, the big benefits are I don't really care what kind of machine is on the other end because we don't provide machine code.
We just send the source code and we let the other side take care of it so it can be more portable and more flexible across platforms. It's also a little easier when testing because you just write your source code and then run it letting the interpreter take care of converting it there is no in-between compile step and it can be easier to debug when things go wrong.
Because you always have access to all the source code however it has its downsides too. Because everyone who needs to run that program on their machine has to have an interpreter for that language on their machine it also can be slower. You have to interpret it every time the program is run and the source code is effectively public because you're sending it to everyone who needs to run that program now because there are good things about compiled languages and good things about interpreted languages there's also a third way of doing this which is a bit of both instead of the compiled model where all the work is done upfront that can be a little bit inflexible or the interpreted model where all the work is done. On the receiving end but can be a little bit slower we kind of do half and half upfront we compile it part of the way to what's called an intermediate language which takes it as far along the way to machine code as it can get while still being portable often across platforms you then distribute this sending it to the people who need to run it. Each person who runs it takes it.
The last step to take it to machine code on their computers. This is sometimes referred to as just-in-time or JIT compilation now this intermediate language sometimes also goes by the name of bytecode. So this process has to happen somehow it's just how much of it happens on your machine and how much of it happens on mine now while theoretically, all computer languages could use any of these methods. The normal usage of any one language tends to be one or the other so for example C C++ and Objective. C these are typically found as compiled languages so you need a compiler and the compiler can be downloaded for free but are often built into integrated development environment applications now languages like PHP and JavaScript indeed most languages with the word script at the end are usually interpreted. Languages like Javac-sharp vb.net Python use this intermediate hybrid approach now whether a language is compiled or interpreted or somewhere in between is rarely a reason by itself to choose a language but it can be something that you take into account if one main priority of your program is absolute maximum speed running on one single platform you'll probably look at a compound language if you're more interested in easily moving your code across multiple platforms.

You're probably more interested in an interpreted one but more usually you're driven more by what you need to do do you need to build iPhone apps or Windows. Desktop apps or dynamic websites or in our case just learn the fundamentals of programming and you let that decision drive the language choice and the language choice will determine whether you're compiled interpreted or somewhere in the middle.


In simple, the difference between compilers and interpreters are also discussed.
So let us begin with compilers


What is a compiler? 

The compiler takes an entire program and converts it into object code. So object codes are also known as the machine codes which are understandable by our computer.
So the program which we write is in the higher-level language okay like in C or C++ in Python like you have seen these are all high-level so we need to convert.
It into such a form which is understandable by the bio-computer so our computer only understands the language of zeros and ones so we need to convert it into object code
So our compiler converts the entire program into an object code now what are the properties of the object would it can be directly executed after linking to object could the object code which has been created after compiling can be directly executed after linking.
There is a store typically in a file like you must have seen that when you create of when I when you create a program then an executable is also created.
Now you can execute it using the executable file as many times as you want unless you have edited your program code.
Once you have edited your program then in order to take its effect you need to first compile it and then the executable will be recreated and then you can just execute it to see its effect
You must be knowing all these things so what are the compiled programming languages we have C and C++ which uses compilers.
So let us see what our interpreters and then in at the end we will see the differences between compiler and interpreter so stick with us
Now in the interpreter and interpreter directly execute instructions without previously converting them to object code.
So in the compiler we saw that when we give a pole then a compiler converts it into object code.
Now the compiler does it all at once it takes the entire program and converts it into the object code.
What does the interpreter do?
The interpreter will take the code and will start executing it line by line.
It will see a line and then we'll execute it then we will see the second line and then executed now whenever it finds an error in a line.
Suppose in this line in have an error so it will stop here executing and only a single error will be reported while in the compilers you know that all the errors are reported if you are if you have worked in C++ in C++ and Python. You must have seen that while you are compiling in C or C++ you will see all the errors which have occurred all at once but in Python you will see only one error at a time. Because python is using interpreter and c++ is using a compiler.
Now let us see the differences between compiler and interpreter and even order a dot Now let us see the difference between compiler and interpreter


So compiler generates a standalone machine code like I have already shown you that the compiler converts the program into a machine code that it is an object code in a standalone mode now. Whenever required to execute a program you don't need to execute our program you just need to execute the executable file like.
We had a program and after compiling this program and executable was created dot exe file.
Now if you don't edit this program then you can execute this executable any number of times. So this what it is saying that compiler generates a standalone machine code if the program is not edited then it can be executed just by using machine code. Now if you edit your program then you need to recompile it in order for a new executable to be created.
The interpreter doesn't generate any standalone machine code. It is always dependent on this program now suppose that you have two computers in a distributed system, one computer is creating the code that means writing the code and the executable file is being transferred to another computer which is executing it any number of times.
Now suppose you know that the program will never change then you will once you create an executable file and you transfer it to the other computer now you can delete this file from your own computer even if the connection is lost.
This computer the other computer will always keep on executing using the executable file because it is not dependent on the program. It is not dependent on the program it has the executable and it will execute it to generate the outputs. But by using an interpreter you cannot do this interpreter interpreted a program is always dependent on the source code. Now once our computer has the source code and it interprets and transfers the bytecode to another computer B. Suppose this all computer in computer B now once it is executed by B the bytecode is lost. It will not be saved anywhere because it is not in a file. It is in a stream so when a B is required to again execute that program then it will have to assess that file which is contained in and it will ask a to recompile that file so when uses interpreter then again a byte stream will be created and it will be sent to B so you can see that B for executing its file. Bis dependent on the source code but by using compiler it is independent of the source code this is one of the major difference which you won't find any. Now coming on to the second difference a compiler this one is very common that compiler takes the entire program and compiles it all at once while the interpreter does that line by line so if you have many lines in your code. If you have many lines in your code then the compiler will take the entire file entire through the program and it will
compile the whole program and will list down all the errors either one error two error or three if there are any errors.
Now the interpreter what it does is it will start from line number one it will execute it and if it is correct then it will move to run to line number two then to line number three and so on as soon. It finds any error suppose in line number three then it will stop here and will show it will flag an error report.
So what is the benefit of this method?
The benefit of this method is that if the debugging will be easier so as soon as the first error is flagged. Our execution will stop our compilation process will stop okay but in the compiler, all the errors are shown and shown all at once.


 Difference Between  Compiler and Interpreter 2020 Easily Explained
 Difference Between  Compiler and Interpreter 2020 Easily Explained

Suppose you have a hundred errors so in interpreter it is not dependent on how many errors you have you actually have it is not dependent on that it will only show the first error. Suppose you have say ninety-nine errors which are all dependent on the first error which you have committed.
So once you correct this first error then all the rest of the 99 years gets corrected. Because suppose you might have forgotten about the library function or odds.
Now the compiler will show a hundred errors and the interpreter will show only the first error now using this interpreter you will be able to solve it. Without any panicking, you will not panic at all once you have solved this first error.
This ninety-nine all these ninety-nine errors all get auto-corrected okay because they were all dependent on the first one but in the compiler you will be shown a hundred errors and you will get a panic. This is not a very good situation to be into so we can say that our interpreter makes the debugging a lot easier than the compilers.
Why do we use compiler?
So I have already shown that in the distributed system compilers are beneficial. It has its own benefits over interpreter and another benefit is that compilers are faster as compared to interpreters.
how are they actually fast?
so let us see you have a file suppose
You have a program file where you have ported your program now you have created the executable file.
You have created the executable file of bytecode.
Suppose this you and you are not editing your program so suppose you want to run it ten times
You will just create this machine code only once that is this bytecode will be converted from this original program only once and then it will be executed ten times so for conversion the maximum time is can is consumed in this conversion process from the normal high-level language to the bytecode.
The maximum time is consumed now for executing this executable takes a similar amount of time as an interpreter. The main task is the conversion so you know in order to execute it ten times
.
Suppose the execution time is T then it will take ten T plus the conversion time.
Now for the interpreter it won't convert it to an executable file and store in a standalone mode. It always serves the interpreter and always converts the program to bytecode on-the-go that means on the fly okay and it doesn't store in a file Because finally we need a byte code in order to make or computer understand so the interpreter also converts it to a byte code don't think that it doesn't convert to a byte code but it won't save it in a file.
So that it can be reused so suppose the first time both compiler and interpreter will take almost the same time because they're both are converting the program from our original code to executable
An interpreter is not converting to executable. It is converting to byte codes that are not saved in a file. Now from the second time the compiler won't convert anything it will just use the executable file and we'll run the program but the interpreter will again go to the original program and we will then start executing the entire instructions one by one and then we'll again convert it to byte codes.
So for interpreter the time will be 10 plus 10 times the conversion time. So you can see that 10 T plus 10 times the conversion time is always greater than 10 T plus 1 time the conversion time.

so you can see that the compiler is always faster than the interpreter.
So this is all about the difference between compiler and interpreter and I
The difference between compiler and interpreter are discussed you should which one you use for your purpose.

To Create A Free Blog Website On Blogger Complete Guide Step By Step And Earn Money 

 Keep visiting TechTrickHD.Com

Recommended Readings :

to Top