Why do we need programming languages to talk to computers, and what do compilers and interpreters do?

W

Programming languages are the tools that allow computers to communicate with humans, and they come in two flavors: compilers and interpreters. A compiler converts an entire program into machine language at once, but the downside is that it can’t be executed in its entirety if there are errors. Interpreters, on the other hand, interpret line by line and provide immediate feedback, which is great for beginners. Each method can be used efficiently depending on its characteristics and should be chosen according to the purpose of the program.

 

When you’re new to programming, it’s easy to expect the computer to do everything for you. However, when you actually write a program, you realize that the joke “computers are so lazy and stupid” is not an empty one. Computers will never do anything you don’t explicitly tell them to do, and even if you do give them instructions, they won’t work properly unless they follow strict rules and sequences. Computers also don’t understand the language that humans use every day, and can only interpret machine language, which consists of zeros and ones. Because of these characteristics, we need a “programming language” to communicate with computers.
A programming language is a tool that acts as an intermediary so that computers and humans can understand each other, and it requires a program that converts it into machine language that computers can understand, called a compiler. Compilers convert the code you write into machine language in one step, so if your code isn’t written perfectly, it won’t run. One small typo or logical error can cause the entire program to fail. This can be frustrating for many programmers, and it can make the development process less efficient.
Interpreters have emerged to solve this problem. Unlike a compiler, an interpreter doesn’t convert the entire code at once, but rather interprets it line by line and translates it into a language that the computer can understand. This is similar to how a parent reads a book to a child, explaining things sentence by sentence. If the child doesn’t understand a difficult word, the parent explains it in a simpler way and moves on, and the child gradually understands the sentence. The interpreter is like this parent, interpreting each sentence of code in turn and translating it into a form that the computer can understand.
The interpreter must first teach the computer some basic functions. For example, “DEF(x, y) is a function that stores the value of y in x.” The interpreter teaches the computer basic operations or commands. It’s like teaching a child simple words. It then takes the code written by the programmer, line by line, and interprets it using a combination of predefined functions. For example, if a programmer enters the command “x = 2 + 3”, the interpreter converts this code into something like “DEF(x, SUM(2, 3))” and passes it to the computer. This allows the computer to understand and execute the command. This way, programmers can write code as if they were talking to a computer, and if they find an error in their code, they can immediately fix it and run it again.
One of the advantages of an interpreter is that the process of writing and modifying code is faster and more flexible than with a compiler. Because compilers have to translate the entire code, a small error can prevent the entire program from running, whereas interpreters run line by line, so if you encounter an error, you can just fix that line and run again. This is especially advantageous for educational purposes or prototyping, and makes computer programming more accessible to beginners. They can try out the code line by line to see how it works without having to write the program completely from start to finish.
However, the interpreter method can be somewhat inefficient once the code is complete. The code has to be re-interpreted and converted into functions on each run, which can slow down execution. For this reason, it’s common to use compilers for large programs or when optimization is important. However, if you need a simple development environment or for learning purposes, interpreters still have a lot of advantages.
In conclusion, as a tool to help the computer communicate with the programmer, interpreters are an important technology to make programming more accessible. If you understand the characteristics of both compilers and interpreters and can choose the right one for the right situation, you can make your programming work more efficient and flexible. I hope that beginners to programming will enjoy using an interpreter to communicate commands to the computer and gradually develop their ability to communicate with the computer.

 

About the author

Blogger

Hello! Welcome to Polyglottist. This blog is for anyone who loves Korean culture, whether it's K-pop, Korean movies, dramas, travel, or anything else. Let's explore and enjoy Korean culture together!