Wouldn't it be nice if computers understood human language?

As computer program developers, we could tell the computer, "when the user presses the button, do this!"

Unfortunately, computers are not that sophisticated. Not yet anyway! So we rely on a text-based computer language known as a programming language.

To give you something more concrete to work with, here is an example of a language called JavaScript.

Don't worry if it doesn't make much sense at the moment:

var x;
x = 5;
document.getElementById("demo").innerHTML = x * 10;

Why do we need programming languages?

Modern computers are made up of several components, but none are more important than the central processing unit or CPU.

The CPU runs instructions such as those expressed in a programming language at rapid speed. The more powerful the CPU, the more instructions it can run per second.

Surprisingly, CPUs do not understand programming languages like JavaScript or C++ directly. Due to their primitive but powerful nature, they only understand the binary system (which stores data in 0s and 1s)

Programming languages are what bridge the gap between programmers and computers.

Each programming language has its own syntax (a set of vocabulary, symbols, and rules). They are challenging to learn, but it's certainly much easier than learning machine code.

The evoloution of programming languages

There are 3 types of programming languages you need to know about:

  1. Assembly languages
  2. Machine languages
  3. High-level languages

Machine Languages

Also known as machine code. Machine languages are sets of binary digits (0s and 1s). A computer's Central Processing Unit (CPU) can execute it directly.

Here is how you express "Hello" in machine code:

01001000   01100101   01101100   01101100   01101111
How on earth does machine code work?

Computers use transistors or small electrical switches. Through electric signals received by the computer, only two options - on (1) and off (0) - are available for these switches. A computer reads the combination of on and off signals to create the desired output.

As you can imagine, working with machine code is tedious and error-prone. As humans always look for more efficient ways of doing things, assembly languages were created.

Assembly languages

Assembly languages changed the game for computer programmers.

Instead of 0s and 1s, they use symbols and characters to represent instructions to be executed by computers.

It uses commands such add, mov, sub, and others.

To use machine code, you need a strong understanding of how the processor and computer memory work (and work together), but there is no doubt that this is much easier to understand than machine code.

Since the CPU only understands 0 and 1, a special translator known as an assembler is used to translate the assembly language to machine code for the computers to execute.

The following is an example of an assembly language code to print "Hello world" on screen.

.model small
.stack 100h
S1 db "Helloworld$"

main proc
mov ax,@data
mov ds,ax
lea dx,s1
mov ah,9
INT 21h
mov ah,4ch
INT 21h
main endp

It's not exactly intuitive, but we're moving in the right direction.

High-level languages

High-level languages are the languages most programmers today are familiar with. The syntax is more human-readable.

Similar to how an assembler translates assembly code into machine code, many high-level languages use a translator known as a compiler.

Compilers convert the whole code into machine language before execution. Examples are C, C++, Rust, and Go.

Other high-level languages are run by interpreters.

Unlike compiled languages, where the whole code gets converted before execution, interpreters run the code instruction by instruction. Examples are JavaScript, Python, and Ruby.

Interpreters aren't the best for high-performance code but have some added benefits. For example, the interpreter or runtime can recover if an error happens.

Often, when we refer to programming languages, it is the HL languages that we are referring to.

The verdict

Programming languages have come a long way since Ava Lovelace wrote the first computer programs in the 1840s.

While computers fundamentally only understand 0 and 1, computer scientists kept pushing this primitive idea to the limit.

It's remarkable to think that 0 and 1 are the foundation of modern computers and all the intensive applications we run from web servers to video games. Still, we could not imaginer coding with only 0 and 1 and that is where high-level languages come in.

Oftentimes, when someone talks about a "programming language" they mean JavaSCript, Python, C#, Java or another high-level language.

While all these languages run and work in slightly different ways (and have slightly different focuses, advantages and disadvantages), they all exist to do one thing: make programmers more productive.