A simplified overview of what a programming language is and the overarching differences between a compiled and an interpreted language.
A programming language is a series of commands, put together in the form of a language, that directly or indirectly correspond to operations a computer is able to perform. In its simplest form, just like tapping the button on my coffee machine initiates a series of internal processes that in the machine to produce coffee; so is the programming language a collection of virtual buttons that allow a programmer to interface with a computer to perform a given task.
For the sake of visualization, the code above tells the computer to temporarily store the first number, then invoke the addition functionality, and finally add the first and the second number together. The result, 2.
Even though there are many different programming languages, most languages are abstraction-languages that interact with the language a computer deals in. At the most essential level, the lingua franca of a computer is made of the binary on and off electrical switches – the 0 and the 1.
When I run a program written in a said programming language, a series of processes are executed to translate the commands in the language I used into commands a computer can run and understand.
The first thing to note is that when I run a program, the computer creates what is referred to as a runtime environment, a little self-contained sandbox that gives the program access to the functionality and resources it needs to run – this ranges from RAM memory to GPU power, sensors or networking.
Part of that runtime environment includes a series of mechanisms that are responsible for translating my code to more low level commands the computer can execute – this is known as machine code.
There are two routes available at this point. The computer can compile and run the program or it can interpret it as it is being run. Most languages can be both compiled or interpreted.
But in their use by programmers, certain languages have lent themselves to being compiled and others interpreted. Therefore, we refer to languages as either being compiled or interpreted languages.
A program written in a compiled language gets translated to machine code prior to it being run. It is that machine code that then gets shared among computers (i.e. the apps I download from the Appstore). This makes the running of a program quite fast since the computer running the program is doing so from code that has already been compiled, eliminating the need for any more translation.
While being faster at runtime, compiled languages can also slow down the process of development since every time I want to run my program as I’m coding it, I have to re-compile it in its entirety.
C, Objective-C, or Swift are compiled languages.
A program written in an interpreted language gets translated to machine code as it’s being run; line by line, on the fly. This makes a program faster to code and iterate on, but at times slower to run since the computer is having to do all the interpreting as it’s running the computer.
To address the potential slow down in runtime, some interpreted languages now run on what is called a Just In Time Compiler (JIT). With JIT, a program being shared between computers in an in-between format called JIT format. This is compiled enough that it makes running the program faster while not being so compiled that it makes development slow.
In conclusion, it can be said that a computer as we know it is the result of a series of layers that range from low-level 0s and 1s, all the way up to modern programming languages and even to the mouse and the keyboard.
When I use a mouse to click an icon on my desktop, that intent exists at multiple levels. From the click and icon interface, to the code written by the team at Apple that gets triggered by said action, all the way down to machine code and the 0s and 1s that in turn retrieve whatever information I’m requesting from memory and translates it all the way up to my laptop’s screen again.
Finally, this post was written with the intent for me to understand and learn this process. Therefore, any corrections and improvements are welcome and appreciated.