JavaRush /Java Blog /Random EN /Programming language levels
Marat Sadykov
Level 41

Programming language levels

Published in the Random EN group

Introduction

What are the programming languages? What are the concepts behind them? How did they develop? In this article, we will consider the types of programming languages ​​based on the so-called levels - from machine codes (low level, close to computer hardware) to languages ​​\u200b\u200blike Java or C# (high level). The less transformations the text listing of the program goes through on the way of turning into a set of zeros and ones, the lower the level.
Programming language levels - 1
Next, we'll look at:
  1. Low-level languages ​​(machine codes and assembler)
  2. Intermediate ( C, Fortran .... )
  3. High level (C++, Java, Python, Ruby, JavaScript...)
The level also characterizes how detailed the listing of the future program needs to be in order to implement the implementation. How easy is this process for a person. You should not take the level of the language as an unambiguous indicator of its capabilities. A programming language is a tool that is effective in one area and less useful in others. Both joiner and carpenter work with wood. The first has the main tool - a set of chisels, the second - an ax. However, a carpenter will make a carved cabinet more elegant, and a carpenter will quickly put up a house. Although each is capable of doing the work of the other, it will do so much less efficiently. Various data in the computer are represented as sets of zeros and ones. The control commands for its processing are the same data containing instructions inside that determine the location of the necessary information and the method of modification.

Machine Languages ​​(Lowest level)

We'll have to make a brief visit from the Software area to Hardware. Let's look at it in a simplified way. The processor is the main "brain" of the computer. The motherboard on which it is installed contains controllers that are used to interact with other devices through buses (data channels for communication).
Programming language levels - 2
Some work at high speed (red arrows): the processor draws commands from memory and manipulates data, the video card - especially in 3D games, consumes huge amounts of textures, shapes, pixel coordinates and other objects to build an image on the monitor screen. Others (due to the limitation of the speed of information exchange) do not need such high rates. A variety of internal and external devices are connected in the diagram with green arrows.

The inner world of the processor

All processor instructions come from memory for execution in binary form. The format, number, subset of instructions depend on its architecture. Most of them are incompatible with each other and follow different ideologies. And also the type of command strongly depends on the mode (8/16/32 ... bit depth) and the data source (memory, register, stack ...) with which the processor works. The same action can be represented by different instructions. The processor has instructions for adding two operands (ADD X, Y) and adding one to the specified one (INC X). Adding a triple to an operand can be done as ADD X,3 or by calling INC X three times. And, with respect to different processors, it is impossible to predict which of these methods will be optimal in terms of speed or amount of memory occupied. For convenience, binary information is written in hexadecimal form.
int func() {
    int i = getData("7") ;
    return ++i;
   ...
}
Code that implements the same actions as a sequence of instructions for the processor: ... 48 83 ec 08 bf bc 05 20 00 31 c0 e8 e8 fe ff ff 48 83 c4 08 83 c0 01 ... This is how the low-level programming language for the intel processor actually looks like. A fragment that calls a method with an argument and returns the result incremented by one. This is the machine language (code), which is transmitted immediately, without transformations, to the processor for execution. Pros:
  • We are completely masters of the situation, we have the widest possibilities for using the processor and computer hardware.
  • All options for organizing and optimizing the code are available to us.
Minuses:
  • It is necessary to have extensive knowledge of how processors work and to take into account a large number of hardware factors when executing code.
  • Creating programs slightly more complex than the above example leads to a sharp increase in the time spent on writing code and debugging it.
  • Platform Dependency: A program designed for one processor will generally not function on others. Perhaps, for this processor, in other modes of its operation, code editing will be required.
Machine codes were widely used at the dawn of computers, there were no other ways of programming in the era of computer pioneers. Currently, they are occasionally used by engineers in the field of microelectronics in the development or low-level testing of processors.

Assembly language (low level)

Unlike a computer, we perceive information better in textual / semantic, rather than digital form. You can easily name fifty names of contacts on your smartphone, but you can hardly write down the corresponding phone numbers by heart. Likewise with programming. We will climb the type ladder by taking three main steps:
  • Let's compare the groups of digital processor instructions that perform the corresponding actions with one symbolic command.
  • Let's single out the arguments of the processor instructions separately.
  • Let's introduce the ability to name memory areas, variables, the location of individual commands.
Let's compare fragments of the previous program in machine code (in the center) and in assembly language (on the right):
2004b0     48 83 ec 08      sub    $0x8,%rsp
2004b4     bf bc 05 20 00   mov    $0x2005bc,%edi
2004b9     31 c0            xor    %eax,%eax
2004bb     e8 e8 fe ff ff   callq  getData
2004c0     48 83 c4 08      add    $0x8,%rsp
2004c4     83 c0 01         add    $0x1,%eax
As you can see, the process of writing a program has been simplified: there is no need to use reference books for the formation of digital command values, calculate the lengths of transitions, distribute data in memory over its cells, and other features of the processor. We describe the desired action from a set of symbolic commands and the arguments necessary for the execution logic, and then the translator program translates the text file into a set of zeros and ones understandable to the processor. Pros:
  • The process of writing and modifying code has been simplified.
  • The control to all resources of the equipment was saved.
  • It is relatively easier to port the program to other platforms, but they require modification depending on hardware compatibility.
Minuses:
  • Assembler is a low-level programming language. Creating even small sections of code is difficult. In addition, it is also necessary to take into account the specifics of the operation of the equipment.
  • Platform dependency.
The most popular Java demo:
public static void main(String[] args) {
    System.out.println("Hello World!");
}
would look like this (NASM syntax, using Windows API and kernel32.lib):
global _main
	extern  _GetStdHandle@4
	extern  _WriteFile@20
	extern  _ExitProcess@4

	section .text
_main:
	; DWORD  bytes;
	mov 	ebp, esp
	sub 	esp, 4

	; hStdOut = GetstdHandle( STD_OUTPUT_HANDLE)
	push	-11
	call	_GetStdHandle@4
	mov 	ebx, eax

	; WriteFile( hstdOut, message, length(message), &bytes, 0);
    push	0
	lea 	eax, [ebp-4]
	push	eax
	push	(message_end - message)
	push	message
	push	ebx
	call	_WriteFile@20

	; ExitProcess(0)
	push	0
	call	_ExitProcess@4

	; never here
	hlt
message:
	db  	'Hello, World', 10
message_end:
Like machine code, assembler is more commonly used by engineers and system programmers. It is used to write hardware-dependent parts of the kernel of operating systems, critical in terms of time or features of the implementation of the driver for various peripheral devices. But lately, it has been resorted to less and less often, since its use greatly narrows the portability of programs to other platforms. Sometimes they use the process of disassembly - they create an assembler listing of a program from digital codes to parse the logic of executing small fragments. In rare cases, if the original high-level code is not available: analysis of viruses to combat them or loss of source code. Assembly language is classified as first / second generation(we will not consider separately pseudocodes before the advent of assembler and their difference from symbolic instructions). I would like to highlight the use of assembler in Demo Scene (demo scene): a fusion of art, mathematics and low-level coding, embodying the artistic intentions of their creators in the form of programs that generate video clips with resource constraints. Often the total size of the program and data file should not exceed 256 bytes (the 4/64 kilobyte format is also popular). Here is an example 4 KB program:

C/Fortran languages ​​(intermediate/high level)

With the development of the capabilities of computer technology, the amount of functionality and the timing of the implementation of the code in assembler were no longer satisfied. The costs of writing, testing, and maintaining programs grew an order of magnitude faster than their capabilities. It was necessary to reduce the requirements from the programmer in terms of knowledge of the functioning of the equipment, to give him a tool that allows him to write in languages ​​close to human logic. Go to a new level of types of programming languages. Provide the ability to split into various modules with a subsequent sequential call (a procedural programming paradigm), provide various data types with the possibility of constructing them, etc. Additionally, these measures have brought improved portability of the code to other platforms, more comfortable organization of teamwork. One of the first languagesFortran . The ability to create in text form with a description of the logic of execution using loops, branches, subroutines and operating with arrays and representing data as real, integer and complex numbers enthralled engineers and scientists. In a short time, scientific "frameworks" and libraries were created. All this was the result of the fact that Fortran is still relevant, albeit in a narrow scientific environment, and is developing, since the baggage of developments is very large, the IMSL library alone has been actively developing since 1970 (!) Years, do you remember a lot of such relevant software -old-timers? Another branch of the development of languages ​​of this level is C. If Fortran became a tool for scientists, then C was created to help programmers creating application software: operating systems, drivers, etc. The language allows you to manually control the allocation of memory, gives direct access to hardware resources. C programmers have to control low-level entities, which is why many people are of the opinion that C is an advanced assembly language and is often referred to as a "middle" level language. Having introduced data typing into the assembler, elements of procedural and modular programming, the C language is still one of the main ones for system programming today, which is also facilitated by the rapid development of microelectronics in recent times. All kinds of gadgets, controllers, network and other devices need drivers, implementation of protocols for collaboration and other relatively low-level software for implementing interaction with hardware. All of the above contributes to the demand for the language at the present time. Object-oriented and functional principles have been further developed in the form of C++, C#, Java, taking a lot from the syntax of C. Pros:
  • Simplification of the code creation process: introduction of types, breakdown into modules, reduction of program listing.
  • The transparent logic of the underlying algorithm due to the departure from machine codes to commands that are more understandable to humans in a semantically descriptive style.
  • Portability. It became enough to recompile the program text for execution on another platform (perhaps with a slight modification).
  • The speed of compiled programs.
Minuses:
  • Lack of automatic memory management and the need for constant monitoring.
  • Lack of implementation of the concepts of object-oriented and functional programming.

Development of high-level languages

High-level programming languages, in terms of creating software, have increasingly moved away from machine codes and implement various, in addition to procedural, programming paradigms. They also include the implementation of object-oriented principles. C++, Java, Python, JavaScript, Ruby… – the range of languages ​​of this type is the most popular and in demand today. They provide more opportunities for the implementation of a variety of software and it is impossible to unambiguously determine the "specialization" of each of them. But the popularity of application in the relevant areas is due to libraries / frameworks for working with them, for example: JavaScript– front end. The language was designed to allow a client web browser to interact with a user and a remote server. The most popular libraries are Angular, React and VUE. At present, it is relatively actively used on web and other servers (backend), Node.js is especially popular. Ruby - Backend. It is used to create scripts (service files) and on web servers. The main framework is Ruby On Rails. Python– scientific and engineering field (in addition to the web area). It is an alternative to standard computing and mathematical packages (Mathematica, Octave, MatLab…), but has the usual semantics of the language and a large number of libraries. He has many fans in the field of machine learning systems, statistics and artificial intelligence. Of the commonly used libraries, it is necessary to mention django, numpy, pandas, tensorflow. C++– Universal, an evolutionary development of the C language. Provides functional and object-oriented programming capabilities without losing the ability to interact with low-level hardware. Due to this, productivity and flexibility are realized when creating software, but the price also corresponds: a high entry threshold due to a complex language specification, the need for independent control over resources when executing a program. Many single-user and system software are written using it: operating system modules (Windows, Symbian…), games, editors (Adobe Photoshop, Autodesk Maya…), databases (MSSQL, Oracle…), players (WinAmp…), etc. It should be noted that modern software is a complex product,

Further progress

Recently, another type of programming is gaining popularity - functional (further development of the language level) . Here is another kind of abstraction for calculations - functions that take a set of functions as arguments and return another one. The role of variables is played by the same functions (variables familiar to us are simply constant expressions, similar to final before declaring a type in Java). The function itself is closed in its scope, the result of its work depends only on the passed arguments. Two remarkable properties follow from this:
  • For testing, we only need function arguments (the result of the work does not depend on external variables, etc.).
  • A functional-style program is miraculously parallel-ready: successive function calls can be run on adjacent threads (because they are not affected by external factors) and do not need locks (that is, there are no synchronization problems). A good incentive to devote time to this topic, given the rampant spread of multi-core processors.
However, the entry threshold is higher than for OOP: for efficient code, it is necessary to build a program, describing the execution algorithm in the form of functions. But also for a pure functional style, it would be nice to know the basics of logic and category theory. The most popular are Haskell, Scala, F#. But fear not, Java (as well as other modern third generation languages) has elements of functional programming and it is possible to combine them with OOP. You will learn more about all these details at the CodeGym online internship. Logic programming area (next level of languages)has not yet found wide practical application due to low demand. The construction of programs requires knowledge of the basics of discrete mathematics, the logic of predicates, means of restrictions, and other sections of mathematical logic. The most popular active language is Prolog.

Conclusion

Currently, the most common languages ​​are OOP. Java, since its inception, has always been in the top, usually in the top three, in demand languages. In addition to OOP, it contains elements of functional programming, and you can combine different styles of writing your programs. The range of Java applications is very wide - these are business tasks, the implementation of web servers (backend), the main language for creating Android applications, cross-platform programming and workspace environments (IDE / AWP) and modeling, and much more. Java's positions are especially strong in the Enterprise sector, an area of ​​corporate software that requires high-quality and long-lived code, the implementation of the most complex business logics.
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION