The source code for this blog is available on GitLab.

Wiregate Blog

Programming Languages Explained

Cover Image for Programming Languages Explained
Mikhail Shevtsov
Mikhail Shevtsov

πŸ“ Note: Thumbnail was generated using Flux Schnell model with help of ComfyUI;
This article was written with help of NI - Natural Intelligence
πŸŽ₯ Don't have time to read? - Watch the video we created: Programming Languages Explained

Assembly πŸ€–

Initially all programs were written in a binary - so called assembly programming language. Where you literally instruct CPU what to do within ALU. While assembly by being a low-level programming language provides very fine control over ALU it requires programmers to actually know CPU architecture and binary logic - it’s very hard and expensive. Assembly provides low level optimizations that benefit execution performance. Examples of such programs that are being developed and actively maintained are sorting algorithms, hash functions, loops etc. So to reduce complexity and to improve efficiency smart people invented high-level programming languages.

πŸ“ Example of assembly hello world app for Linux X86:

section .data
    hello db 'Hello World!', 0x0A     ; The string to print, with a newline

section .text
    global _start                     ; Entry point for the program

_start:
    ; Write the string to stdout
    mov eax, 4                        ; syscall number for sys_write
    mov ebx, 1                        ; file descriptor 1 is stdout
    mov ecx, hello                    ; pointer to the string
    mov edx, 13                       ; length of the string
    int 0x80                          ; call kernel

    ; Exit the program
    mov eax, 1                        ; syscall number for sys_exit
    xor ebx, ebx                      ; exit code 0
    int 0x80                          ; call kernel

High-level programming languages πŸ“‘

The purpose of high-level programming language is to simplify the procedure of writing business logic using human readable text. High level programming languages are classified as compiled and interpreted.

Compiled programming language 🏭️

Compiled programming language translates high level human readable code into machine cod during compilation procedure. A program that does actual compilation is called a compiler. It’s worth mentioning that each program needs to be compiled to specific computer architecture. Programs compiled for X86 will not work on ARM processors and vice versa. So compilation for specific architecture is required. Compilation is an irreversible process. You can’t reliably convert assembly code to high level source code.

Performance wise in majority of the cases compiled programs do execute faster πŸ‡ than Interpreted programs.

Majority of compiled languages are statically typed. Explanation follows in the next paragraphs.

Most popular compiled languages are C, C++, Rust, Objective C, C#.

πŸ“ Hello world on written on C programming language:

#include <stdio.h>
int main() {
   printf("Hello World!");
   return 0;
}

Statically and dynamically linked libraries πŸ“šοΈ

Applications can perform certain typical actions such as display images, uncompress archives and many others. While it’s possible to write all such functions from scratch it’s impractical to do so. For that purpose libraries are used. Libraries help to reduce complexity of the development process by splitting applications into modules. New features and bug fixes can be performed within the scope of the module rather than the whole application. The process of integrating libraries to the main application is called Linking. Linking can be done dynamically - meaning that all libraries are compiled separately and connected to the main application during the runtime of the application or statically - meaning that all machine code of the libraries is integrated into the main application binary. Dynamic libraries usually have extension .dll for Windows and .so for Unix.

Interpreted programming language 🐍

Interpreted programming language translates high level human readable code into machine code during execution of the program. The program that does that is called an interpreter. Since an interpreter is also a program which is already compiled for specific architecture of the CPU it can translate high level code to machine language on the fly.

Performance wise in majority of the cases interpreted programs are slower 🐒 than compiled.

Most popular interpreted languages are Python, JavaScript, PHP, Ruby.

πŸ“ Hello world on written on Python programming language:

print("Hello World!")

Typisation in the programming languages 🚧

Programming languages can be classified as statically or dynamically typed.

In statically typed programming language all variables and data structures are pre-defined before compilation or execution of the program. For example this means that if the developer defines variable A as string he cannot change its value from string to a number later in the code. This can be verified during Ahead Of Time (AOT) compilation and print logical error. This simple technique helps to reduce the number of errors during execution which leads to more stable programs.

In dynamically typed programming language variables can be reassigned from one type to another. For example a variable A can first contain a number and later can contain a string. That method simplifies the development process.

Data Structures

Variables πŸͺ†

Variables can be integer numbers, floating point numbers, strings. They are considered to be the simplest possible data structure. To dig deeper variables are stored using specified addresses in the RAM. Address is a binary number (11111111111111101011111101111111111100001101100) of the memory cell in RAM usually represented as hexadecimal number (0x7fff5fbff86c) for ease of reading.

Constants are the special variables whose value, after assignment, should not be changed by the running program.

Other Data Structures 🎁

Beside Variables there are other data structures such as Arrays, Associative Arrays, Linked Lists, Queues, Stacks and many others. The purpose of these structures is to store data more efficiently so it would be easier to work with the data.

Functions in the programming languages 🚦

One of the ways to simplify programming of the business logic is to use so-called functions. Like in math where f(x) is a function which produces some value depending on the properties of that function in the programming functions can return values or do some stuff. Functions can accept input arguments such as a number, a string or any other data structure and return values or data structures or they can work without any arguments at all, everything depends on the business logic of the function itself.

Conclusions πŸš€

In reality programming languages are not as complex as everybody thinks. If you only starting to learn programming - begin with simple interpreted language like Python. After understanding basics - all other languages will follow as easy as reading the syntax.