QUICK GUIDE: HOW A PROGRAMMING LANGUAGE WORKS?
Have you ever wondered how actually a programming language works? How it is possible to write a code and gets a result on your screen instantly?
Today, we’re answering these crucial questions. It doesn’t matter if you are a beginner, intermediate or even advanced user. I’m sure that everyone finds it useful in some way in your long-term journey.
#1 What is a computer?
Can you even imagine the world without a computer? I was one of many people who lived in a world without a computer until I hit the age of 10. When I will get my first computer, it was a magical time for me. A computer doesn’t remind those computers which exist today. But even then, it was possible to do many things with a computer.
So, I can bet on you that you use it a computer now, almost every day if you just sitting now before the screen and reading the post. Perhaps, you used a computer to write a document, buy something online, listen to music, play computer games, edit photos or just chat with your friends via Facebook, Instagram, Twitter or other social media.
Computers are used for many things these days as predicting the weather, performing financial transactions or even controlling factories. Have ever stopped to wonder what exactly a computer is? How can just one machine perform so many different tasks at once?
Definition of a computer
An up-to-date computer we can define as “a machine that stores and process information under the control of a developing program”.
Firstly, we can give some kind of information to the computer and it can transform those kinds of information into new, useful output which can be even much more valuable to us than information which we put first into this device.
Secondly, do computers operate under the control of a developing program? A computer program is a step-by-step set of instructions telling the computer exactly what to do. It is like a recipe. If we change something in the program, the computer performs different actions, and what comes naturally did also a different task.
You can see that your computer is so flexible, at one moment can be a word processor, next to a financial planner, a calculator or any game. The machine stays the same, but the program is something that controls what happens in the machine.
So, every computer is just a machine for carrying out programs. In this world, there are many different kinds of computers which have the same power as programming and each one can basically do all the things you can even imagine.
#2 What is programming?
The software known as programs rules the hardware as the physical machine. It says what any computer can do. With no software, computers would just be the only expensive machines.
So, basically, programming is the process of creating software. It is something which is worth talking about today, which gives almost infinite possibilities to grow businesses and to ease people life. That’s so wonderful that exists people who are eager to learn this craft and create amazing stuff with it.
#5 How a computer works?
Yes, you don’t need to know all the “hot” details of how the computer works, but understanding fundamentals, I am sure, will help you in your programming journey. Despite different computers can vary a lot, at some level all are similar.
The “brain” of the machine is the Central Processing Unit known as the CPU. Here, all the basic operations are performed. The CPU can carry out easy arithmetic operations like adding two numbers and can also do logical operations like checking if two numbers are equal.
RAM, SDD, HDD as different kinds of memory
We know that memory stores programs and data. The CPU can directly access what is stored in the main memory (RAM – Random Access Memory). Main memory is quick, but it is also variable. When the power is turned off, all information in the memory is lost. That is why we need second memory to provide more constant storage.
In a PC, the fundamental secondary memory is an internal hard disk drive (HDD) or solid-state drive(SDD). An HDD stores information as magnetic patterns on a spinning disk and an SSD uses electronic circuits called flash memory. For secondary memory, most computers also support removable media such as USB memory or DVDs.
People just interact with computers through input and output devices. For example, you probably know the common devices such as keyboard, mouse and monitor. Information from input devices is processed by the CPU and store in main or secondary memory.
Also, when information needs to be displayed, the CPU sends it to one or more output devices. So, what happens if you fire up your favourite program? Firstly, the instructions from the program are copied from the secondary memory into the main memory. When it is done, the CPU starts executing the program.
We can say that the CPU follows a process called the fetch-execute-cycle. The first instruction is fetched from memory, decoded to know what it represents, and appropriate action performed. Then the same thing happens with a second.
The cycle goes on, instruction-by-instruction. This is absolutely all until you turn off your computer again. So, yes, it doesn’t sound exciting, but computers can execute those kinds of operations with incredible speed doing amazing things in seconds.
#6 Difference between interpreting and compiling
Ok, we know that a program is a set of instructions telling the computer what to do. But, of course, we need to write those instructions in a language that a machine can understand. In our language, we have lots of imprecision. We understand each other because we share common experiences and knowledge, but even then sometimes people are so confused by someone who is talking about something that they cannot understand.
Computer scientists design special notations for expressing computations in an exact and precise way which is known as programming languages.
Everything in a programming language has an accurate form (syntax) and accurate meaning(semantics). A programming language is something like a code that a computer understands.
All those languages are known as high-level languages which can be used and understood by people. But computer hardware can only understand low-level language( machine language). This hardware performs instructions by instructions.
All these instructions are represented in binary: 0s and 1s. That sounds really complicated at first. But because we have such a beautiful programming language we can communicate with those machines by those languages which like a translator between us and hardware. That’s wonderful.
In a programming language, like Python adding two numbers can be easy: a=b+c. But of, the course here we need to remember that we have to translate the high-level language into machine code that the machine can execute.
We have two options: a high-level language can either be compiled or interpreted.
Compiler vs interpreter
A compiler is a program that takes another program written in a high-level language and translates it into an equal program in the machine language of the computer.
An interpreter is a program that imitates a computer in understanding a high-level language. It doesn’t translate the source code into a machine language. It analyses and executes code instruction by instruction if it is necessary.
The basic difference between these two is that compiling is a one-time translation and when a program is compiled it can be run over and over again with no compiler or source code. But in the interpreting case, an interpreter and the source code are needed every time when the program runs.
As you can guess, compiled programs usually will be faster because translation is done only once, but interpreted languages are more flexible env as programs can be developed and run interoperable.
What is more, translation is an advantage that high-level languages have over a machine language: portability. You need to know that all computers have their own machine language, created by designers or the CPU.
A program for the processor in your laptop won’t be run directly on your smartphone. However, a program written in a high-level language can be run on many different computers as long as they have a relevant compiler or interpreter.
To sum up, a programing language is a form of communication between you and the machine. “Under the hood”, as you have seen, are performed sophisticated operations which allow you to do whatever you want in just a second or even less.
If you just feel that you want to see more, I highly recommend the course on YT by freeCodeCamp.org. Enjoy and comment below, if you find it interesting.