Interpreter
Interpreter
A program that executes source code line by line. Python and JavaScript are representative examples. Contrasted with a compiler.
Interpreter
A program that executes source code line by line. Python and JavaScript are representative examples. Contrasted with a compiler.
An interpreter is a program that reads source code line by line and executes it immediately. Unlike a compiler, which first translates the entire code into machine code, an interpreter interprets the code at execution time. Many scripting languages, such as Python, JavaScript, Ruby, and PHP, use the interpreter approach.
The advantages of an interpreter are immediate feedback and platform independence. You can run code right after writing it, and as long as an interpreter is available, the same code runs on any operating system. Interactive programming is also possible through a REPL (Read-Eval-Print Loop).
On the other hand, execution speed is slower than that of compiled languages, because the code has to be interpreted every time. To compensate for this, modern interpreters use JIT (Just-In-Time) compilation. V8 (JavaScript), PyPy (Python), and others compile frequently executed code into machine code at runtime, greatly improving performance.
In practice, pure interpreters or compilers are rare. Java compiles to bytecode and the JVM then interprets it, and Python also generates .pyc bytecode. Like this, most modern languages use a mix of compilation and interpretation.
# 인터프리터 언어 실행 방식 비교
# Python - 인터프리터로 직접 실행
python script.py
# Python REPL (대화형 모드)
python
>>> 2 + 3
5
>>> print("Hello!")
Hello!
>>> exit()
# Node.js (JavaScript 인터프리터)
node script.js
# Node.js REPL
node
> const x = [1, 2, 3];
> x.map(n => n * 2)
[ 2, 4, 6 ]
> .exit
# Ruby 인터프리터
ruby script.rb
irb # Interactive Ruby
# 인터프리터 vs 컴파일러 비교 예시
# 인터프리터 언어 (Python)
# - 작성 → 바로 실행
# - 실행 시 한 줄씩 해석
# - 에러가 해당 줄 실행 시 발견됨
# 컴파일 언어 (C)
# - 작성 → 컴파일 → 실행
# gcc main.c -o main
# ./main
# - 모든 에러가 컴파일 시 발견됨
Backend developer: "Our Python server's responses slow down at peak traffic. Is that a limitation of being an interpreted language?"
Tech lead: "With PyPy, JIT compilation can make it 3-5 times faster. Or you could write only the hot paths in Cython."
Backend developer: "Can we switch to PyPy without modifying the existing code?"
Tech lead: "Most pure Python code is compatible. You just need to check whether you use C extension modules."
Interviewer: "Please explain the difference between a compiler and an interpreter."
Candidate: "A compiler converts the entire source code into machine code or intermediate code and then executes it, while an interpreter reads the code line by line and executes it immediately. A compiler needs build time but runs fast, whereas an interpreter runs immediately but is relatively slower."
Interviewer: "What is the principle behind JIT compilation?"
Candidate: "It detects frequently called code during execution and dynamically compiles it into machine code. It combines the flexibility of an interpreter with the performance of a compiler. The V8 engine is a representative example."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
Reviewer: "This script is too slow, and it uses eval() a lot."
Author: "I need to generate code dynamically. Is there another way?"
Reviewer: "eval is very slow because the interpreter has to parse and execute the code every time. If you define the functions in advance and select from a dictionary instead, it will be much faster."
Author: "I heard there are security issues too. I'll refactor it."