Skip to content
BENIBIX Learn

Compilers and Interpreters

Level 1 · How languages differ

The two ways source code gets run. What a compiler does before the program starts, what an interpreter does line by line, and scripting languages.

Course contentsLesson 2 of 12

Level 3 · General-purpose and systems languages

  1. Python, Java and C#
  2. C, C++, Rust and Go

Level 4 · Languages for phones

  1. Swift, Kotlin and Dart

Level 5 · Data and functional languages

  1. R, Julia and MATLAB
  2. Haskell, Scala and Elixir

Level 6 · Scripting languages

  1. Shell Scripts, Perl and Lua

After this lesson you can

  • Explain what a compiler does
  • Explain what an interpreter does
  • Say why a language is called a scripting language

12 mincovers 5 glossary entries

Worth reading first: Programming Language Basics

How source code turns into a running program

Source code has to become machine code before a chip can run it. There are two ways to do that. A compiler turns the whole program into machine code first, in a build step. It saves the result as a file you can run. An interpreter reads the source and runs it as it goes, a line at a time, every time.

A compiled language is one that is usually run through a compiler. C, C++, Rust and Go are compiled. The build can take seconds or minutes. Then the program runs fast, because the work of turning words into numbers is already done. The file you hand out is the machine code, not the source.

An interpreted language is one that is usually run by an interpreter. Python and JavaScript are the best known. There is no build step, so you change a line and run it straight away. The cost is speed, since the reading is done while the program runs. The person running it also needs the right tool installed.

Many languages sit in between. Java and C# are compiled, but not all the way to machine code. They become bytecode, a halfway form that a runtime turns into machine code as the program runs. That lets one built file run on any machine that has the runtime.

A scripting language is one built for short programs that do a job for you. One might rename 500 files, or pull the numbers out of a report. These are almost always run with no build step, so a script can be written and run in minutes. Python, the shell and PowerShell are often used this way.

Compiled and interpreted say how a language is usually run. They are not a law. There are tools that build Python first, and tools that run C line by line. When people call a language compiled, they mean its normal tools build it first.

The common mistake is to think compiled always means faster to use. It means faster to run. For a script you run once, the time saved by skipping a build is often bigger than any speed lost while it runs.

Compiled and interpreted, side by side

CompiledInterpreted
When code is turned into machine codeBefore it runs, in a buildWhile it runs
Speed when runningFastSlower
What you hand outA built fileThe source code
ExamplesC, Rust, GoPython, JavaScript
The code goes straight to machine code, or to a halfway form. A runtime then finishes the job as it runs.

Worked example

Jack ships a tool to 40 laptops

Jack writes a small tool for 40 office laptops. His first version is a Python script, but 12 of the laptops have no Python installed.

He rewrites it in Go and compiles it once. He copies one 6 megabyte file to each laptop, and it runs with nothing else installed.

The words for this lesson5

Check yourself

What does a compiler do?

Finished this lesson?

Marking it complete also marks its 5 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.