Topics
Programming Languages

Programming Languages

A programming language is a well-defined, structured language, which comprises a set of instructions for computers to make them perform specific tasks or operations. Computer programmers write their programs using one of many languages available depending on what they are writing programs for.

Programming languages can be classified into the following:

Machine Language

This is a language that is written as a sequence of binary digits (bits), in other words, a sequence of 0s and 1s. The Central Processing Unit (CPU) of a computer understands this sequence of bits and executes the instructions coded in the sequence. Every type of CPU is designed differently and has its version of machine language as specified by the designers of the processor. So a machine language program written for one type of processor will only work on that type of processor.

Each instruction makes the CPU perform a specific task, such as reading data from an input device, writing the data to storage, performing an arithmetic or logical operation, or controlling a peripheral such as the monitor to display data. A machine language program also indicates the sequence in which instruction should be executed and how many times should be repeated in a loop, which will be decided according to certain conditions.

While it is theoretically possible for humans to write programs directly in machine language, it is highly impractical, almost to the point of being impossible.

Connections Language

This is a language that is slightly more human-readable than machine language but not much more so. It uses alphanumeric codes to represent instructions instead of the 0s and 1s in machine language. It is quite possible to write programs for small computers (such as those embedded in simple devices, like a washing machine or traffic lights) using assembly language; however, a programmer needs to be an expert in the assembly language for the specific processor used in that device. Assembly language is finally translated into machine language by a program known as an assembler.

Machine and assembly languages are referred to as low-level languages, mainly because they are understood very well by computers but not by humans.

This is what a program in assembly language looks like:

Assembly Language Example

High-level Languages

Since programmers cannot realistically be expected to write programs in machine or assembly languages, they need a programming language that is easier for them to understand. This led to the evolution of several programming languages broadly referred to as high-level languages, which are easy for humans to write and read.

Large and complex programs are almost always written in a high-level language. They may not be as easy to understand as plain English, but they are a lot easier to understand than machine or assembly language, especially to a trained programmer. Some of the more popular high-level languages include C, C++, C#, Java, and JavaScript.

The description of a high-level programming language is usually split into "syntax" (form) and "semantics" (meaning).

  • Syntax is about the structure or the grammar of the language to be used to construct proper instruction. This is similar to human languages, which have grammar, or rules that define whether or not the sentence is properly constructed. But unlike in human languages where small grammatical errors are acceptable and the sentence may even be understood despite the errors, programming languages have zero tolerance for syntax errors and will not understand the instruction if even a single character is out of place.

  • Semantics is about the meaning of the instruction or what the processor is supposed to do. In some scenarios, the instruction may be correct in its syntax but wrong in semantics. For example, the syntax may allow an instruction that performs the addition of two numbers, but adding two letters has no meaning and is therefore semantically invalid.

Every language will have its own syntax and semantic rules, some are more forgiving than others.

Compilers

While high-level languages are human-friendly and simplify the task of writing computer programs, computer processors do not understand them. They only understand machine language. Therefore, any program written in a high-level language must be translated into machine language. This translation is done by programs known as compilers.

Program instructions in a high-level language, such as C, C++, C#, and Java, are referred to as the source code. This is translated by a compiler to machine language to create what is known as an executable program, a set of instructions that the computer processor can understand and execute. Machine code is specific to the type of processor. Thus, while the source code remains the same, you need to use a compiler according to the type of processor on which you intend to run your program.

Compilers may also be operating system dependent. The same source code may need to be compiled differently for different operating systems.

In addition to translating high-level languages to machine code, compilers also perform syntax checks on the source code. This is very useful to programmers to avoid releasing programs with errors. Compilers do not however check for the correctness of computations or logic, that must be handled by the programmer.

An interesting conundrum that should come to mind is this: If a compiler is a program written in a high-level language, then how is it compiled into a compiler?

The answer is that initially, it would have been necessary to write some low-level machine code to compile the compiler code into an executable. Once a minimal compiler was ready, it could be executed to create another one written in the language it compiles. That again can be used to create a higher level one and so forth.

Today enough high-level languages exist to allow new compilers to be created easily relatively. It does require an extraordinary level of programming skills since other programmers trust that their code will be compiled correctly and their program will execute as intended.

Levels of Compilation

Compiler Steps