Level concept in programming languages - PROGRAMMING FOR BEGINNERS: All Concepts Explained (2016)

PROGRAMMING FOR BEGINNERS: All Concepts Explained (2016)

2. Level concept in programming languages

Every programming language has some "level", from very high to lowest, which is machine language. When we talk about programming languages's level it refers to how precisely can program written in specific programming language control and access hardware; also, how precisely it can manipulate data. You can think of "precisely" here this way: if program, for example can access only words of provided text file, then it is more high level than the one which can access text at the single character level. Level concept is very important in programming languages and you need to select what level programming language you need (or is needed for your particular needs). There are generally "high level" and "low level" programming languages available, but they can be further divided into "very high level" or "very low level" etc. programming languages. To learn about the advantages and disadvantages of high and low level programming languages, read the following sections about each category.

2.1 High level programming languages

Today, high level programming languages are more common than low level programming languages, but this was not the case in the past. In the past, opposite was the case. As computers developed and became faster over time, high level programming languages started to appear and soon became popular. The reason was that writing programs in high level programming languages is easy and requires fewer code to be typed compared to writing programs in low level languages. Also, when programming in high level language, programmer does not need to know much about hardware technical details and can concentrate on real problem solving (i.e. algorithm design because algorithms solve different types of problems) using high level view of program design. The drawback of high level programming languages is that programs written in them run slower compared to programs written in low level languages and that in many cases they don't precise, low level control over hardware and data. High level programming languages include Python, Java, Visual Basic and C#. Interestingly, C and C++ are both in some aspects high level and in some aspects low level programming languages, but are generally considered high level programming languages.

2.2 Low level programming languages

Low level programming languages have advantage of accessing and precisely controlling hardware and data at low level, which is not the case with high level programming languages. There are fewer low level programming languages than high level programming languages. The lowest level and most basic program code is machine language code. Then there are assembly languages, which are lowest level programming languages humans can understand. Assembly languages are used in specific situations where low level hardware access or low level data processing is necessary. Assembly languages can even access cache memory, which is special memory inside CPU. Interestingly, C programming language has many low level functions and is close to assembly language; even complete operating systems can be written in C.

Machine and assembly languages

Machine language instructions are the most basic instructions that CPU can execute (i.e. run). When source code is compiled, it is translated into machine language instructions. Machine language instructions are string of 0s and 1s (binary digits) which are understood and run by particular CPU. Where we meet programs in machine language form in everyday life? Most commercial software you have is in the machine language form (most probably compiled from high level compiled language like C or C++). Code which is saved in machine language form as computer file is called compiled executable or just executable. Because machine language instructions are different for all the different CPUs, different types of CPUs might have different machine language instructions even in case of doing the same task. When programmers use compilers, they convert program instructions written in high level compiled programming languages to machine language instructions that CPU can directly execute. Different compilers generate different machine language instructions. Generally, machine language instructions run quite fast and commercial programs and games are sold in the form of machine language instructions saved as file (this file called executable file). But there are cases where maximum speed of program execution is needed. To achieve this, you can write program in assembly language. Programs written in assembly language run faster than compiled programs and can most precisely control hardware; assembly language is the lowest level programming language that humans can program in.

Assembly language is not like any other programming language. It is essentially machine language instructions written and represented in human readable form. To execute program written in assembly language, you need to translate assembly language code into machine language code, which can be directly executed by the CPU. Translation can be done using special program called assembler.

Assembly language is also used in computer security and software piracy world. Special program, called disassembler can convert back machine language instructions into assembly language like instructions. This allows hackers to reverse engineer program and learn how program is built, then disable or remove program copy protection. On the other hand, computer security professionals reverse engineer malicious programs to learn how they cause damage and to trace hacker who wrote malware.

Today, few people write programs using assembly language, because it is hard to write and understand. Instead, some part of program where execution speed is critical can be written using assembly language. Today, people choose high level programming languages instead of assembly language, such as C or Java.