📜 ⬆️ ⬇️

Matryoshka C Layer system of the program language

Let's try to present chemistry without the Periodic system of Mendeleev (1869). How many elements had to be kept in mind, and in no particular order ... (Then - 60.)

To do this, think about one or more programming languages ​​at once. The same feelings, the same creative mess.

And now we can experience the feelings of the chemists of the XIX century, when they were offered all their knowledge, and a little from above, in one Periodic Table.
')
image


The book "Matryoshka Sy. Layered system of the language of the program "presents all units of the C language in full view. This allows you to organize them, correct outdated information and even clarify the very concept of the program.

Today, programming information needs to be systematized even more than chemical elements 150 years ago.

The first need is teaching. Mendeleev began creating his own system when he faced the question of which element to begin lecturing: O, H, N, He, Au ... At the same time, it was easier for him - he taught chemistry to the best - students of St. Petersburg University. And programming is already taught in school and will soon begin in kindergarten.

The second necessity is a scientific approach. With the help of the Periodic System, new elements were discovered and information about old ones was corrected. She helped create the model of the atom (1911). And so on.

The third necessity is the clarification of the notion of a program.

Modern programming with one foot stuck in the 50s of the XX century. Then the programs were simple, and machines and machine languages ​​were complex, so everything revolved around machines and languages.

Now the opposite is true: programs are complex and primary, languages ​​are simple and secondary. This is called an applied approach, which everyone seems to be familiar with. But students and developers continue to convince everyone that everything is the same.

Which brings us back to the first lecture of privat-docent Mendeleev. What do freshmen say? Where is the truth? That is the question.

The book “The Matryoshka C. Layer system of the program language ". Moreover, it is addressed not only to students, but also to trained programmers, since it is they, that is, we, who need to look for the truth and turn the world around.

The following is a summary of the book.

1. Introduction


In 1969, the C language was created, which became the fundamental programming language and has remained for 50 years. Why is this so? First of all, because C is an applied language that gives the program a humane look instead of a machine language. This achievement secured the languages ​​of the C family: C ++, JavaScript, PHP, Java, C # and others. In the second place, it is a short and beautiful language.

However, the C language itself is usually mixed with machine assembler, thereby complicating and distorting its perception. The other extreme is the imposition of a kind of "philosophy" on the language: procedural, object, functional, compiled, interpreted, typed, and so on. This adds emotion, but it does not help to describe the language better.

The truth is in the middle, and for the C language - strictly in the middle between philosophical and machine perception.

The C language is not independent, it obeys the usual written language, and at the same time it itself controls the language of the assembler. This provision describes the speech model of the program , according to which the program is divided into three subordinate types: speech, code, command. C language is responsible for the second, code view.

Having determined the place of a language in a program, it is possible to organize information about it, which makes the Layer System of the program language representing the C language in the spirit of the Mendeleev system - on one page.

The system is built taking into account the commonality of applied languages , resulting from their speech subordination. One set of Matryoshka C units allows you to describe and compare different languages ​​by creating a series of Matrices: C ++, PHP, JavaScript, C #, MySQL, Python, and so on. It is worthy and correct that different languages ​​are described by units of the fundamental language.

2. CHAPTER 1. Speech model of the program. Clear C


The first chapter presents the speech model of the program , reflecting the applied approach. According to him, the program has three obvious sequential views:

  1. speech - direct speech of a programmer solving a problem,
  2. code - coding the solution into a mathematical form in the C language (or any other)
  3. and command - direct machine commands.

The speech model explains why C is a simple and understandable language. C is built in the image and likeness of familiar to us human speech.

The first type of program is the direct speech of a programmer. Speech corresponds to human thinking. Using speech, programs are written by novice programmers — first in Russian, then step by step translating actions into a code language. And it was in this pattern that the C language was created.

The programmer's conclusions expressed by speech are converted into a numerical code view. This transformation should be called a reflection , since speech and code have the same nature (reflection - birth - gender). This is quite obvious if we compare the speech (left) and code (right) types of the program.

image

It is curious that the reflection is very simple - only two kinds of expressions.

However, the modern description of the C language (from 1978) does not contain a sufficient list of titles either for the description of the language in general or for the task of reflection in particular. Therefore, we are forced to engage in creativity and enter these names.

The choice of words must be accurate and clear. This required a special approach, briefly expressed as follows - strict use of the native language. For the English, it would be English, but we are not English. So we use what we have, and we will try to speak in Russian.

Reflection perform two kinds of expressions:

  1. calculation (HF) - reflects the change in the properties of the object. The property of an object is expressed by a number, then the action on a property is an action on a number - an operation.
  2. submission (PC) - reflects the change in the order of actions. The prototype of the PC is a verbal complex sentence, so most PC types begin with the subordinate alliances “if”, “otherwise”, “bye”, “for”. Other species of PCh complement them.

By the way, can you believe that in the C description there is no name for the expressions for evaluation - are they called simply “expressions”? After this, the absence of a name and association for a kind of subordination, and indeed a paucity in terms of names, definitions and generalizations, will no longer surprise. This is because the famous C / R (“The C Language”, Kernighan / Richie, 1978) is not a description, but a guide to the use of the language.

However, I would like to have a description of the language. Therefore, it offers a Layered System language program .

3. CHAPTER 2. Layer system. Concise C


Any description should be accurate and extremely brief. In the case of a program language, a frontal description is difficult.

Here we have a program. It consists of modules. Modules consist of subroutines and collections. Subprograms consist of separate expressions: declarations, calculations, submissions. Submissions - as many as ten species. Submissions connect sublevels and subroutines. Ad few too. However, ads are included not only in sub-programs and sublevels, but also in modules and collections. And most expressions consist of words that are so difficult to describe, so usually they are simply given in two lists - source and derived words, which are to be found throughout the study and application of the language. Add to this punctuation and a number of expressions.

In such a presentation is not easy to understand who was standing on anyone.

The direct hierarchical approach of describing a language will be overly complex. The search for detour paths leads to a description of the language based on its verbal nature and command side. Thus, a Layer system was born, partly coinciding with the Periodic system of Mendeleev, which is also a layer one . As it turned out 42 years after its publication (1869), the periodicity of the system is associated with the electron layers (1911, the Bohr – Rutherford atom model). Also, the Layer and Periodic Systems are related to tabular placement of all units on one page.

The description of language units is brief - only 10 kinds of expressions and 8 genera of other units, as well as informative and visual ones. Although unusual for the first acquaintance.

Language units are divided into 6 levels:

  1. units - table rows
  2. departments - special groups of childbirth (part of the first line)
  3. sort - cells (main division level)
  4. supra species separators of species (rare level)
  5. types - formulas of units at the bottom of the cell or separately
  6. samples are units themselves (only for words)

Samples of words describes the dictionary - a separate subsystem composed of the same six levels.

The speech component of the C language is quite obvious, although it still deserves a description. But the command part of the language is connected with compilation management, during which a third type of program is created - the command one. Here we come to the most exciting side of the C language - beauty.

4. FOLLOWING CHAPTERS. Handsome si


The C language is the basis of modern programming. Why? Firstly, due to the greatest compliance of speech. Secondly, because it beautifully bypassed the limitations of machine processing of numbers.

What exactly did C suggest? Image and layer.

The word "image" is a translation of the English word "type", which is derived from the Greek "prototype" - "prototype." In Russian, the word “type” does not convey the cornerstone of the concept being expressed, besides it is mixed with the official meaning “species”.

Initially, the image solved a purely computerized computational problem, and then became the runway for the birth of object languages.

The layer immediately solved several problems, both machine and applied. Therefore, consideration will begin with a single-task image and go to the multitasking layer.

One of the unpleasant features of historical programming is that most concepts, including basic ones, are given without definitions. “A programming language (the name of a river) has a whole and a floating type of numbers ...” - and scratched on. What is “type” (image) is not necessary to determine, because the authors themselves do not fully understand and will shut it down “for clarity.” If they are priprut to the wall, they will give a vague and useless definition. It helps to hide behind foreign words: for Russian authors - for English (type), for English - for French (subroutine), Greek (polymorphism), Latin (encapsulation) or their combinations (ad-hoc polymorphism).

But this is not our destiny. Our choice - definitions with a raised visor in pure Russian.

Form


An image is a prototypical name of a quantity, defining 1) its own properties of a quantity and 2) selection of operations to a magnitude.

The word “type” (type) corresponds to the first part of the definition: “own properties of a quantity”. But the main meaning of the image is in the second part: “selection of operations for quantities”.

The starting point for introducing an image in the C language is a usual calculation, for example, the operation of addition.

Hand-written or typed paper math does not make a special distinction between the kinds of numbers, usually making them real. Therefore, their processing operations are unambiguous.

Machine mathematics strictly divides numbers into integers and fractional ones. Different types of numbers are stored in different ways in memory and are processed by different processor commands. For example, the commands for adding integers and fractional numbers are two different commands, corresponding to two different processor nodes. But the team of addition of integer and fractional arguments is missing.

Applied mathematics, that is, the C language, separates the types of numbers, but combines operations: addition for integers and / or fractional numbers is written with a single sign of the action.

A clear definition of the concept of image allows you to definitely talk about two other concepts: magnitude and operation .

Magnitude and operation


The value is the number being processed.

Operation - processing the values ​​of the initial values ​​(arguments) to obtain the total number (total).

The magnitude and operation are interrelated. Each operation is a value, since it has a numerical total. And each value is the result of sending the value to the processor register / from the processor, that is, the result of the operation. Despite this relationship, the main thing is the possibility of their separate description, even with the repetition of one word in different parts of the dictionary, which is what happens in Ma3.

The machine approach divided all the numbers used by the programmer into commands and data . Previously, they both were just numbers, for example, commands were written with numeric codes. However, in applied languages, teams stopped being numbers and became words and signs of actions . Only “data” remained numbers, but to continue to call them so ridiculous, because when moving from a computer to a mathematical point of view, the numbers are the quantities that divide the original ( data ) and the total ( desired ). “Unknown given” - it will sound silly.

The teams were also divided into two types of actions: math and service. Mathematical operations - operations. For service will turn later.

In the C languages, the usual paper and machine unambiguous, or single, mathematical operations almost completely become multiple.

Multiple operations - several operations of the same name with different images of arguments and different actions that are close in meaning.

Integer arguments correspond to the whole operation, fractional - fractional. This difference is especially evident in the division operation, when the expression 1/2 gives a total of 0, not 0.5. Such a record does not conform to the rules of paper mathematics, but the C language does not seek to observe them (unlike Fortran) - it plays according to its applied rules.

In the case of mixing of integers and fractional numbers, the only correct reduction of the values ​​of the arguments is included - the selection conversion of the value from one image to another. Indeed, when adding an integer and a fractional number, the result is fractional, therefore the image of the operation selects the operation of converting the integer argument to a fractional value.

A number of operations are not multiple , but single . Such operations are defined for only one type of argument: the remainder of the division is the whole arguments, the stacking (bitwise operations) are natural integers. Ma3 indicates the multiplicity of operations with signs (# ^) indicating the images for which the operation is defined. This is an important, but previously missed property of each operation.

All functions are arbitrary unit operations. The exceptions are the operators - shellless functions built into the language (source operations).

Promotion


Assistance is a concomitant operation action.

If we consider the operation as the main action, then we can distinguish two related, which provide for the operation and are different from it. These are 1) variable control and 2) submission. Such an action is called promotion .

Here it is necessary to be distracted and separately tell about Russian translations of textbooks on programming. In the C / P text, a new word statement (expression) was introduced to record actions, which attempted to separate machine command concepts into different actions: 1) operation, 2) declaration, and 3) submission (called “control structures”). This attempt was buried by Russian translators, replacing “expression” with the word “operator”, which:

  1. has become synonymous with the machine word "team",
  2. turned out to be synonymous with the phrase "sign of action"
  3. and also received an unlimited number of additional values. That is, it turned into a similarity of the English article "eeee ...".

Consider related actions, or assistance .

Variable control


Variable control (UE) - creating / deleting variable cells.
UE occurs implicitly when declaring a variable, which is already written on another occasion - to indicate the image of a value. Only one kind of added variable is explicitly controlled using the malloc () and free () functions.

It should be noted that implicit actions are more convenient for writing, since they do not require writing at all, but more difficult to understand - they are more difficult to take into account and interpret.

Subordination


Submission - connecting / disconnecting layer partitions.

The C language suggested a different from assembler, applied method of controlling the order of actions - submission. It reflects and develops the vocal complex sentence with an explicit division into the main part (the sentence submission) and the subordinate part (sublayer / subprogram sections).

Both ad and submission are completely built on the concept of layer .

Layer


A layer is a limited, single-level selective set of expressions.

The layer explicitly and implicitly took over the execution of several tasks at once:

  1. streamlining the program
  2. limiting the visibility of names (implicitly)
  3. managing variables (memory cells) (implicitly),
  4. definition of subordinate sections for submission,
  5. definitions of functions and collections and others.

In machine languages ​​there was no concept layer, so it did not appear in C / R, and if something was not there, then introducing it in subsequent books would be heresy and free-thinking. Therefore, the concept of a layer did not appear at all, although it is extremely useful and quite obvious.

Without a layer it is impossible to briefly and clearly explain many of the actions and rules of the program. For example, why a goto like a simple three kopecks is bad and a tricky while is a good one. You can only swear powerlessly, as Dijkstra did (“qualifications of programmers is a function inversely dependent on the frequency of appearance of goto operators in their programs.” In short, only goats use goto. Level of justification is God.) they are not obliged to explain anything at all, but, as we have said, this is not our destiny.

By the way, it can be assumed that Den Richie left goto precisely as a key for searching for some unnamed concept, because there was no need or beauty in goto expression. But there was a need for a simple and clear explanation of the new principles of the language, which Richie himself did not want to give, and which are just based on the notion of a layer .

Deviation


Deviation - change the normal properties of the new name.

The most important deviation is associated with the layer properties of the program, and is described by one word “static”, which has different meanings in each type of layer.

5. LAST CHAPTER. Commonality of applied languages


Applied languages ​​are figurative languages ​​(having an image, "typed"). They are based on an explicit or implicit use of the image. And here again a contradiction appears: an obvious image is more understandable, but less convenient, and vice versa.

image

(The layout of the table has not yet been brought up, therefore the table is given by a picture.)

After C, the development of applied languages ​​took the path of increasing their imagery. The most important for understanding high-quality is the direct descendant of C - the C ++ language. He develops the idea of ​​arbitrary selection of operations to values ​​and embodies it on the basis of the si-shnogo expression of the selection, which receives a new name - the object. However, C ++ is not as concise and expressive as C, due to the overload of new types of collections and the associated rules. By the way, let's talk about "overload".

Overload and polymorphism


The word “overload” is an obsolete term for a machine approach, meaning the creation of multiple operations .

The machine (system) programmers could be annoyed by the multiplicity of operations: “What does this sign (+) mean: the addition of whole numbers, the addition of fractional numbers or a shift in general ?! Nowadays, they did not write like that! ”Hence the negative connotation of the chosen word (“ brute force ”,“ tired ”). For an application programmer, multiple operations are the cornerstone, the main achievement and legacy of the C language, so natural that it is often not realized.

In C ++, multiplicity has spread not only to the original operations, but also to functions — both individual and class-based methods. Together with multiple methods, the possibility of redefining them in extended classes appeared, which was vaguely called "polymorphism". The combination of polymorphism and overload gave an explosive mixture that shattered into two polymorphisms: "true" and "ad-hoc". Understand this can only contrary to the assigned names. Foreign names paved the road in ad.

The declaration of the form “overload” is better to be expressed with the word “ pre - declaration ” - adding the declaration of the function with the same name with arguments of another image.

A declaration of the form “polymorphism” is better called re - declaration — overlapping declaration in a new expanding layer of a function of the same name with arguments of the same image.

Then it will be easy to figure out that the methods of the same name of different images (arguments) are added , and the same image is redeclared .

Russian words decide.

Runway


Consideration of the concepts of highly-shaped languages ​​confirms the importance of a clear definition of fundamental concepts. With properly described C, learning highly-shaped languages ​​will be easy and enjoyable.

This is especially important for implicit high-shaped languages (PHP, JavaScript). For them, the importance of objects (composite images) becomes even higher than in C ++, but the very concept of an image becomes implicit and hardly perceptible. In terms of convenience, they have become easier, but in terms of understanding - more difficult.

Therefore, the study of programming languages ​​should begin with the C language and move on in the order of appearance of the C family languages.

The same goes for language descriptions. Different languages ​​have a matching or smaller set of kinds of units than C language. The number of types and samples may differ in both directions: C ++ has more types than C, and Javascript has less.

Special mention deserves the language MySQL. It would seem - nothing in common, but it is perfectly described by the Matryoshka, and getting to know him becomes faster and easier. What is important, given its importance for the web - dining road modern programming. And where is MySQL, there are other SQL. Well, and all sorts of Fortran-Pascal-pythons are also described by the Matryoshka as soon as they reach the hands.

So, great things are waiting for us - an applied description of the C language and a unified description of the languages ​​following it. “Our goals are clear, the objectives are defined. For the work, comrades! (Stormy, prolonged applause, turning into a standing ovation. Everyone stands up.) "

Your opinions will be listened to with great attention, your help in creating the site of nesting dolls will be greatly appreciated. More complete information about the book lies on the site, cunningly hidden in the Matryoshka X.

Source: https://habr.com/ru/post/452328/


All Articles