DEV Community

Loralighte
Loralighte

Posted on

What is a compiler and an interpreter?

I have has experiences with developers who don't know the differences of a compiler and interpreter, or why they should care. The difference between the two is required to know, as it can mean the difference in speed, functionality, and shipping code. Not only that you can see many issues when trying to do things in interpreted languages that compiled ones don't have.

What is a compiler?

A compiler is a set of code to read files and shoves it into assembly code for the CPU to translate into machine code so it can run it. The compiler targets the direct architecture the compiler is compiling for, and ships it to that architecture. Some people say compilers compile to machine code, and while this might be true sometimes, most compile to assembly (whether it'd be amd64, ARM, RISC-V, etc.).

What is an interpreter?

An interpreter is a set of code to read files and execute them line by line, figuring everything out as it goes along. The interpreter doesn't care for architecture of the CPU and runs it without going into assembly language first.

Benefits of compiled over interpreted

Compiled languages are faster, and are easier to debug and ship. Compilers don't need the same exact interpreter to run, with the same exact version. As long as the code set is supported and the binary used on the proper architecture, the overall result will work anywhere. It can also (depending on dependencies) work anywhere.

Benefits of interpreted over compiled

As long as the person has the proper interpreter version, it will work anywhere, on any hardware, on any OS no matter what. Even dependencies will be easier to ship with as it will run the same interpreter (or close versions of the same interpreter). They are also easier and faster to run (although slower to execute).

Which should you pick

It depends on a lot of factors, more than I stated here. This is the absolute basics. Need more speed? Compiled. Need the ability to run anywhere regardless of speed? Interpreted.

Examples of compiled and interpreted languages

Compiled: C, C++, Java, Haskell, Vala
Interpreted: Python, JavaScript (Nodejs),


Why did I make this? Boredome.

Top comments (2)

Collapse
 
lexplt profile image
Alexandre Plt

One could argue that Java isn't compiled into machine code but jvm bytecode and thus needs the VM to run

Collapse
 
kailyons profile image
Loralighte

But still "compiled" technically, plus VMs add a lot of complexity that no one really needs, like lang to lang compilations. I only focused on the absolute basics