Interpreter
- What are interpreters for?
- How the interpreter works
- The difference between an interpreter and a compiler
- Famous interpreted languages and their applications
- Multiple interpreters for one language
- Advantages of interpreted languages
- Disadvantages of interpreted languages
- Which languages are better to learn: compiled or interpreted?
An interpreter is a program that executes code written in a programming language. It doesn’t translate it into machine code entirely, but rather accepts commands line by line and executes them immediately. You can give the interpreter a command and immediately see if it worked.
This is one of two ways to translate code into a form understandable by a computer. The second option is compilation, when the code is “translated” entirely into machine instructions. We’ll discuss the differences below.
Programming languages that work with interpreters are called interpreted. Most of the popular languages today are interpreted. Some of them are popular options for teaching computer science and programming.
What are interpreters for?
Programming languages are designed to be human-friendly. They are close to English, and their commands are human-readable. This applies primarily to high-level programming languages—those that are closer to humans than to hardware.
Computers don’t understand such languages. By default, code written in them is treated as plain text, not commands. After all, a computer is a computing machine that understands strings of ones and zeros, not text. But writing commands in so-called machine code is a very difficult, almost impossible, task. They are very long, especially if the program is complex, and are incomprehensible to humans.
Therefore, when developing a programming language, a program is always created to translate the code into a form understandable by a computer. An interpreter is one way to implement this process. A program in an interpreted language simply won’t run without an interpreter—the computer won’t understand it.
That is, an interpreter is needed so that programs in a particular language can be launched and executed.
How the interpreter works
The interpreter receives a command written in a programming language as input, reads it, and immediately executes it. Its operation can be roughly divided into two modes: interactive and batch.
Interactive mode. This is usually done in the console. It’s also called a REPL (read-eval-print loop). It works like this: a user types a command in the console to the interpreter, and it’s executed immediately when they press Enter.
Typically, this requires first launching the interpreter with a separate command, but not always. For example, if a JavaScript command is written in the browser console, no additional steps are required—browsers have a built-in JS interpreter by default.
Batch mode. This is used for larger tasks, ones that can’t be written line by line and executed immediately. A user writes some code in a file, saves it with the desired extension, and passes it to the interpreter. The interpreter receives the file, reads the code line by line, and executes it.
Most programs are written in batch mode: writing them in the console and immediately executing them would be inconvenient. The REPL is used for quick calculations, sending queries, and other actions that require a single command.
The difference between an interpreter and a compiler
Another way to “translate” code into a machine-readable form is through compilation. Programs that perform this are called compilers, and the languages that work with them are called compiled languages. The difference is that a compiler doesn’t perform any execution: it receives a code file as input, deciphers it, and translates it into machine code in its entirety. The result is an executable file that can be run within any operating system.
There are several differences between interpreters and compilers, both theoretical and purely practical.
- The interpreter works with the code line by line, while the compiler translates the entire block of code as a whole.
- The interpreter executes the code as soon as it “reads” the required line, and the compiler gives it to the system for execution – it only translates it itself.
- The compiler cannot be used in REPL mode, only in batch mode.
An interpreter can be compared to a simultaneous translator who immediately produces a voice-over of the translation. A compiler, on the other hand, is like a literary translator who translates texts and then sends the translation to those who will work with it.
Famous interpreted languages and their applications
The most popular interpreted languages today are JavaScript and Python. JavaScript gained popularity because it runs in the browser, making it widely used on the web, especially in front-end development. Python is used in machine learning, data analysis, mathematics, analytics, and automation, as well as on the web and in many other industries.
Other examples of interpreted languages are PHP, which is actively used on the web for the “server” part, and the universal Ruby and Perl, which are often used for automation, system administration, or working with text.
Interpreted languages are system- independent, so in theory they can be used anywhere. The main requirement is that the end device where the code will run has an interpreter installed.
But where maximum performance or closeness to the hardware is needed, compiled languages are usually preferred. They execute code faster by translating it into machine code, which the system understands and executes quickly.
Some languages, such as BASIC or Python, have both compiled and interpreted versions. They are used for different purposes.
Multiple interpreters for one language
Most often, a single language has multiple interpreters, or, as they say, multiple implementations or engines. A prime example is JavaScript: it has three main interpreters, one used by Chromium-based browsers, another by Mozilla, and a third by Apple browsers.
Different implementations may differ slightly in execution or in the handling of certain complex queries. Each engine has its own optimization mechanisms and specific features. If the code is expected to run under multiple engines, it’s advisable to take them all into account. For example, consider JavaScript: front-end developers working with the browser-based portion of a website must consider and test the code’s behavior in different browsers. But the general operating principle is the same for all engines.
How exactly the code should work is determined by a specification—a large document, usually from the language’s developers, that describes in detail all possible commands and principles. The creators of interpreters are guided by this document.
Advantages of interpreted languages
Interactivity. Code is executed line by line, which is convenient. If you need to test a simple query, you can simply launch the interpreter and issue a command in the console—everything will run instantly, without the time-consuming compilation and transmission to the system. This can also be used to perform simple actions, for example, to automate routine tasks.
Speed of learning and writing code. The aforementioned interactivity makes the language easier to learn. Firstly, you can immediately see the result of any action, and secondly, if an error occurs, the interpreter will point it out. And for the same reason, writing code is faster.
Ease of debugging. Debugging code written in an interpreted language is easier for the same reason: it’s executed immediately. With compiled languages, an error might occur in one place and become noticeable to the compiler in another. This complicates debugging. With interpreted languages, this is easier: the interpreter starts complaining as soon as it reaches the erroneous location.
Moreover, if a compiled program encounters an error, it won’t execute at all. An interpreted program, however, will execute up to the point of failure. This is also convenient for debugging, and helps solve at least part of the problem before the program crashes.
Human-readable. Most interpreted languages are high-level, close to human understanding. This means they have a clear syntax, their code is easy to read, and the languages themselves are relatively easy to learn. It’s certainly easier than writing in low-level languages or even machine code.
Platform independence. Execution is handled by the interpreter, not the system. Therefore, the language is OS-independent, meaning it’s cross-platform by default. This distinguishes interpreted languages from compiled ones, where execution is directly dependent on the system. After all, different operating systems perceive machine code differently, so compiler programs are specific to each system. And code compiled for Windows won’t run on Linux or Mac.
Optimization mechanisms. Interpreters themselves also play into the programmer’s hands: they have built-in mechanisms that optimize the code themselves. This means that if the code isn’t written most optimally, the interpreter will mitigate the lack of optimization using built-in mechanisms.
Of course, this doesn’t mean we should forget about code quality. It’s still important. But this feature allows us to focus on making the code clean and human-readable, rather than sacrificing clarity for the sake of a few milliseconds.
Disadvantages of interpreted languages
Slow program performance. Programs written in interpreted languages run slower than those written in compiled languages because the code isn’t executed directly by the system. However, the speed difference is mitigated by two factors: the optimization of the interpreters themselves and the absence of an intermediate step—compilation, or translation into machine code. Although compiled languages are preferred for performance-critical processes, interpreted languages are sufficient for most tasks.
Risk of error. We mentioned above that debugging code in interpreted languages is easier. This is true, but this advantage has a downside. Since the program runs immediately and executes until the error occurs, it’s easy to miss an error in rarely executed code blocks. There’s a risk that the program will run without the developer ever realizing the error. Compiled languages are immune to this: if there’s an error anywhere, the program simply won’t run. However, this problem can be avoided through proper testing.
Dependency on an installed interpreter. Interpreted languages are independent of the operating system, but they do depend on an interpreter. For code to run, you need not only to download the file but also install an interpreter. Without one, the computer simply won’t be able to run the program—there’ll be nothing to understand it. However, an executable file created with a compiler can be run anywhere, but only on the target OS.
Open source code. When compiled into machine code, the source code is hidden, preventing anyone from seeing how a particular function was implemented. Interpreted languages lack this advantage: the code isn’t translated into an executable file, but is executed directly by the interpreter. Therefore, the source code remains open and can be viewed by anyone. This is a disadvantage if the program code is a trade secret or the developer simply wants to hide it for some reason. Additional tools will have to be used to “hide” the code.
Which languages are better to learn: compiled or interpreted?
There’s no definitive answer as to which is better: both types have their own applications, advantages, and disadvantages. Therefore, we recommend focusing on the field you want to work in and the languages commonly used there. For example, in game development and when creating applications for various operating systems, compiled languages are typically used. On the web and for automation, interpreted languages are preferred. You can also try different options and figure out which approach suits you best.
Learn more about programming and information technology with our courses. We’ll help you find a new, high-paying career.
Explore More IT Terms
#
A
- A Guide to SQL Query Formatting
- A/B testing
- Agile
- Algorithm
- Algorithm complexity in 5 minutes
- Algorithms and Data Structures in C#
- An overview of the C # programming language
- An overview of the Python programming language
- Anaconda Python
- Android
- Android App Bundle
- Android SDK
- Angular
- Ansible
- Apache
- Apache Airflow
- Apache Kafka
- Apache Tomcat
- App Store
- AppCode
- Applications of microcontrollers: From simple circuits in electronics to complex systems
- Applications of the derivative
- Arduino: How to Program It: Basics for Beginners
- Array-based stack
- ArrayList
- ASCII
- ASP.NET
- Assembly Language Lessons
B
C
D
- Data Analytics: applications of data analysis in companies
- Data Engineer - Who is it, what does a data engineer do, and an overview of the profession
- Data modeling: what it is, types, and process steps.
- Data preprocessing: a complete guide for beginners and professionals.
- Data structure
- Database Tests with Answers
- Deep Learning
- Defining Aliases
- Defining Arrays
- Deque
- Developing a Website from Scratch
- Differential Equations
- Differentiation of functions
- Digital data: understand the importance of this asset for businesses.
- Double integrals
- Doubly linked lists
E
F
H
- Handling errors and exceptions
- Heads or Tails? How Probability Theory Is Used in IT
- History of the development of computer science
- How to effectively organize your workflow
- How to Learn Java: Tips for Beginner Developers
- How to Learn PHP: A Beginner's Guide
- How to Use S3 Storage in Kubernetes with CSI
- HTML
- HTML and CSS: Definition, Application, and Operating Principles
- HTML and CSS. Layout from Scratch: What to Learn, Where to Learn, and How Long Will It Take?
- HTML Frame Structure
- HTML Link Formatting
I
- if..else construction
- Infinite sequences and series
- Information properties
- Inheritance in Java: A Complete Guide to Principles and Implementation
- Inserting an Image
- Integration of functions
- Interactive Python Tutorial – Learn Programming from Scratch
- Interpreter
- Interview Problem: Finding a Deleted Element in O(N)
- Interview Scare: The FizzBuzz Challenge
- Introduction to C++
- Introduction to Machine Learning
- IT Specialist Resume (CV)
J
K
M
- Machine Learning
- Machine Learning Basic Tool: NumPy
- Machine Learning Basic Tool: Pandas
- Machine Learning Mathematics
- Mathematics for programmers: what is really needed?
- Microcontroller and Microprocessor - what's the difference?
- ML Engineer: Who They Are, What They Do, How Much They Earn, and How to Become a Neural Network Specialist
- Monte Carlo Simulation: How It Works and What It's For
O
P
- PHP lessons
- Private DNS server and its configuration
- Program code
- Programmer's Dictionary
- Programming
- Programming with pseudocode
- Python Code Formatting Guide: PEP8
- Python for data analysis: how to do it and main libraries
- Python Lessons
- Python Superstar: 5 Ways to Use the * Operator
- Python vs. Julia: Should You Replace Python with Julia?
R
S
- SFML Graphics Library Tutorials
- Sorting Algorithms in Programming: Types, Descriptions, and Comparisons
- SQL commands: see what they are, what the main ones are + examples
- SQL Interview Questions and Tasks
- SQL Lessons
- SQL Stored Procedures
- SQL Syntactic Sugar: The COALESCE Function
- Stack
- Start in analytics: Python or R
- Statistical analysis: importance for decision making.
- String formatting in Python
- Structure of computer science
- Swift Lessons
- switch/match construct
- Syntax
T
- Terms in programming
- Text and paragraph formatting tags
- The concept of information and its transmission
- The Future of Python: Key Trends and Insights from Global Researc
- The Infrastructure of Code: A Complete Guide to Repositories for Languages, Frameworks, and Compilers
- The pip package manager in Python
- The role of informatization in the development of society
- Transfers
- Tutorials / Articles
- TypeScript: What It Is and Why Developers Need It
W
- What are databases, and why do they need DBMS and SQL?
- What do Linux distributions consist of?
- What is .NET and what is it used for?
- What is a GPU in a computer, in simple terms?
- What is Arduino: How it Works and the Platform's Capabilities
- What is Big Data? Introduction, Types, Characteristics, and Examples
- What is Golang and what is it used for?
- What is Haskell and what is it used for?
- What is Kotlin and what is it used for?
- What is Linux? The History of Linux
- What is machine learning, and how does it work?
- What is Power BI: everything about the data analytics software
- What is the C++ programming language?
- What is the OSI Model: A Complete Explanation of the Seven Layers and Their Role in Networking
- What's the difference between x86 and ARM processors?
- Where to start learning the C programming language?
- Which Linux distribution should you choose? A Linux distribution overview





