Society in the Society - Talking about the Development of Computer Languages

zhaozj2021-02-16  59

Society in the Society - Talking about the Development of Computer Languages

One. Original social machine language

Humans have just been born, and society is just a prototype. The productivity is extremely low, and human beings have the most freedom.

In 1946, the situation of the first modern computer of Vonnoiman was like the primitive society.

"Programmer" (I don't know if this name is invisible. They) is an expert in electronic technology. They complete various calculations through design complex circuit boards, while the computer is only used to meet the most fundamental needs - military (This can be seen in human nature). "Programmer" is the owner of the computer, and they can manipulate all hardware resources, command the clumsy homonomer to complete all kinds of incredible tasks.

Language birth

The development of IO has prompted the language of the language. The production of perforated paper strips makes the programmer do not have to have too many electronic technology knowledge, they only need to know the computer's language (instructions), they can communicate with them. The language that the computer can understand is a long skewer number consisting of 0 and 1, which is the machine language. The programmer is hard to punch on the paper strip and send a signal to the computer.

Let us speculate what this simple program should be written by machine language (since it is speculative, then most details may be wrong, so I have always thought that it is a good idea to be a historian).

Void main ()

{

INT I, J, K;

I = 1;

J = 1;

K = i j;

}

Please forgive me to translate this ancient text into Chinese, because I think no one will be interested in it:

Set the memory location of 40000 (if it is a 32-bit computer);

Set the memory location of 50000 (if it is a 32-bit computer);

The memory position is added to two machine characters of 40000 and 50000, and the result is placed to the machine word of 60000.

Because the programmer can control all hardware resources, they can specify any memory location to use (as long as the hardware allows), the above 40000 or the like can be other numbers.

Senior Programmer has lived freedom but simple life.

Social continued progress, IO continues to develop. New IO devices, such as tape, keyboard, etc., make the perforated paper strip thrown into the garbage pile. But programmers are still equal and free.

The collapse of the primitive society

The appearance of the privilege class marks the original social line will collapse, and the nobles are operating systems. The aristocrat monopolized some privileges. The programmers can't operate all hardware resources as before, quite a number of resources take over the operating system, and the programmers have lost some freedom, but in exchange for the improvement of development efficiency.

Let us consider it again, what should be achieved by the machine language above:

version 1:

Set the position of 40000 (if it is a 32-bit computer);

Set a machine word (if it is a 32-bit computer if it is 32-bit computer);

The two machine characters of the position is 40000 and 50000 are added, and the result is set to the machine word of 60000.

It seems that version 1 seems to be almost identical to the previous implementation, but in fact, the 40000 and other numbers here are no longer the actual memory location, the operating system is responsible for selecting the actual memory location, that is, it will be responsible for the program ( Process) Address mapping to actual physical address.

Version 2:

Move the stack pointer down to 12 bytes;

Set the memory location as a machine word of PSTACK - 12 is 1;

The memory position is set to 1 machine word of PSTACK - 8; add the machine word of the above two positions and assigns the machine word of the memory position as PSTACK - 4.

Realization of Version 2 Assume that there is a stack pointer register in the hardware, fortunately, our most familiar X86 series CPU satisfies this.

Stack is a very important concept, we will discuss this later.

Whether you like or not, the most free era of programmers has passed. In this great era, every programmer is all everything, they know how their program is running, rarely have a fascinating and anxiety, they are the owner of the computer. But this era has not returned it.

Machine language, this most fundamental language has also been thrown to the compiler, and the programmers don't have to remember the difficulty 0,1 strings!

Two slave social assembly language

Because of the machine language is very difficult, people have gradually use the mission symbol to replace 0, 1 string, such as add, move, and more. They are just a simple replacement of machine language, but only this is still a huge progress, and the emergence of compilation has greatly improved the development efficiency of programmers.

Of course, the computer does not understand the assembly language, the compiler is responsible for translating the assembled statement into a machine language.

Slave society - Honghui

Early assembled statements and machine language statements are one-one correspondence. However, this averageism of this machine has apparently become an obstacle to social development. Can more workers, macro-complimentary statement, one of the probabilistic languages ​​that may be reached. This abstraction improves the work efficiency of programmers, but it makes them get far from the machine. With the advancement of society, humans are gradually lost freedom.

The human nature is greedy, in order to get higher efficiency, the programmer is willing to pay the price of freedom, people are calling more abstract languages, can block all the machine details, and society is brewing revolution.

The birth of three feudal social high-level languages

The emergence of Fortran marks a new era, people have to be pumped from complex machine details, people don't need to manage memory, registers, etc., which is of course a great revolution in computer history.

Early feudal society: Goto rampant times

The high-level language appears, and Goto has been aware of the tools of the programmers because of his flexible and efficient tools. Goto even became a scale of the programmer level.

Although the programmer has lost freedom to control hardware resources, it is not limited in the use of advanced languages. They can use any style, strange skills, write out except for them (most cases include them) who can't understand.

Feasuring Society: Structured Program Design

When most people are also immersed in Goto, when they bring them freedom and glory, the genius figures of the never, but the inventors of this monarch are still the semaphore, but they are unfortunately, they will find GOTO. Problems brought. The Netherlands legendary scientist published his famous papers "GOTO harmful theory" and sensationalized the entire computer world. Edsger Dijkstan pointed out that GOTO is the brank that leads to complex, confusion, and difficult to understand, which also makes efficiency difficult to measure, and the program is difficult to maintain.

Through everyone's efforts, people summarize a set of effective programming methods, called structured programming. The programmer can no longer be encoded, and Goto has become a poison that programmers avoid. Yet another time, human beings have paid a freedom for the progress of society.

High-level language compilation

Here, I don't want to talk about the principle of compilation (I don't understand J), I just want to understand it according to my own understanding, talk about a few important issues (as an example of C / C ).

1. Memory allocation strategy - stacks and piles

Stacks and stacks are not easy to confuse, but they blame the stack as "stack" in some books, bringing many doubts to people. To put it bluntly, the stack and the stack are a false memory in the process space (will be mapped to physical memory, so it can be said to be a space in memory), and the computer is given more support.

Remember the stack pointer register, when the program calls memory, the stack pointer will point to the top of the stack, the distribution of storage space is done by the mobile stack pointer (see Version 2). So, which variables will allocate space in the stack:

l function parameters

E.g:

Int Add (INT I, INT J)

{

INT K = I J;

Return K;

}

When this function is called (a = add (1, 2)), the stack pointer moves the 8 bytes, parameters i (1) and j (2) will be stack, when the function returns, the stack pointer up Move, space is automatically released.

l Partial non-static variable (automatic variable)

Taking the above function as an example, the storage space of the variable K is also allocated in the stack. When this function is called, the parameter is first pressed, then the stack pointer continues to move down 4 bytes, give K assign space, The results added by I and J were first assigned to K, and then the value of K is then assigned to the caller of the caller. At this time, the function is to exit, and the stack pointer moves 12 bytes to release all spaces. Because the distribution of local non-static variable variable space is determined by the compiler during compilation, it is also referred to as an automatic variable.

Since the stack uses it so convenient, what should you do? Obviously, if we can know how much space to apply before the program is running (compile), the stack is enough, but in complex applications, it is difficult to know how many spaces you want to apply in advance - such as in the air tube system Only how many aircraft do you know if you can know how to use external signals.

We can see the stacks as a storage space, when we need to store space, you will receive it from the warehouse. When this space is not used, it will return it (this is a fairly complex algorithm). The process of receiving and returning is determined by the program (so-called dynamic decision), and the location where the storage space cannot be determined when compiling.

Dynamic application space by keyword new in C language (using function malloc in C), such as:

INT * PINT = New INT;

An int type will be allocated in the heap (note that the storage space of the pointer PIN is in the stack).

The storage space allocated in the heap is determined at runtime. The compiler cannot automatically clear these storage space, so it must be responsible for clearing, C using keyword delete, such as:

DELETE PINT;

Since storage space is limited resources, if we don't release it in time, this error is called memory leakage.

Note: Some languages ​​such as Java, the space in the heap is automatically released. In fact, Java is achieved by implementing a "garbage collector" during operation.

Here, the problem of stacks and stacks is basically over, but since a local non-static variable has been talked, it is possible to understand the static variables and global variables.

Such examples:

Int Sum (INT i)

{

Static SUM = 0;

SUM = I;

Return Sum;

The variable SUM in the function is static variable, and the storage space of the static variable is not allocated in the stack. It is

Assigned in a special location, referred to as a static memory area. We don't need to know where the static storage area is, we only need to understand that the storage space allocated in the static storage area will only be released when the program exits. Therefore, the variable SUM in the function has a memory function, such as:

A = SUM (1); a = 1;

B = SUM (2); b = 3.

Global variables are variables defined outside of all functions, which can be used by all functions. Of course, it is also stored in a static memory area.

2. Compile and link

l Declaration and definition

To distinguish between compilation and link, you must first understand the difference between declaration and definition.

Bruce Eckel's classic masterpiece "C Programming Thought" 2.1 is clearly explained here, I am here to quote his explanation.

"Statement" introduces the name to the computer, indicating what this name is meaning. And "Definition" truly allocates storage space for this name.

Remember, any variable in C / C can only be defined once!

So, defining variables in the header file is not a good habit, because once this header is included in multiple other files, it will be multiple definitions during the link (weird, in some old-fashioned C compilers, do not Generate an error, but in any case, please don't do this).

Keyword Extern Represents Now we now declare a variable (function), but the function is optional, and the function that does not have a function is automatically seen as a statement.

l Compilation and link

Compile and link is two phases, compiled units are files, that is, only one file can be compiled, the result of compilation is the binary target file. In the link phase, each target file is "linked" to form an executable (or a dynamic connection library, etc.).

Compilation phase Allows that there are variables or functions that have declared but unseaved, variable names, or function names are stored in the target file, and all target files will be integrated in the link phase compiler to find all variables and functions.

E.g:

The file main.c is as follows:

Void Notexit (INT I);

void main ()

{

Notexit (1);

}

Cc main.c can be compiled, but will report an error in the link phase:

NOTEXIT: Unresolved Function.

If the file NOEXIT.C is as follows:

Void Notexit (INT i)

{

Return;

}

Cc main.c NOTEXIT.C can be compiled and linked.

Similarly, if there is a definition of multiple NOTEXIT functions, the program will not pass the link.

But unfortunately, if the function is defined in the file NOTEXIT.C as follows:

Void NotExit (Double I)

{

Return;

}

Cc main.c notexit.c can actually be compiled and link (if the CC call is a C language compiler). However, if it is a C compiler, the above program cannot be linked.

So, how does C do this? This is going to talk from the function overload:

The overload allows us to define a function with the same name (as long as their parameters are different), this will bring confusion to the link phase. If the function name is the same, how does the linker know which function should be called? Answer is in the function name, the C compiler will change the internal name of the function! For the simplest example,

Void Notexit will be named NOTEXIT_INT inside; and Void Notexit (Double i) will be named Notexit_Double.

EXTERN "C" generation: Since the compiler will change the name of the function within the internal change, unfortunately there is no standard to specify this behavior, the function name generated by different compilers is different. So, if you want to use the libraries generated by other C compilers, it will become very difficult. In order to solve this problem, people came up with Extern "C". This symbol representation generates a function in the way C compiler, that is, the compiler cannot change the function name. In this way, it means that this function cannot have the benefits of the C function: it cannot be heavy, and it cannot be a member function.

Four Capitalist Social Oriented Language

Historical wheels are unstoppable, structured programming has no scenery for too long, they have to give the wind to the emerging nobles - object-oriented.

Since the first successful object-oriented language SMALLTALK, people have taken OO express, and all kinds of emerging faces are constantly appearing, and some ancient language is not lonely, put on the OO coat for themselves. The most successful object-oriented language is: C , Java, etc.

C is an extension to C. c is the most influential language in the feudal society. It is well known in his flexible and efficient. C inherits the advantages of C, miraculously supports all OO characteristics without losing too much efficiency (Bjarne Stroustrup is a genius). However, it is precisely because C has too many traditions that need to be inherited. It has too many non-OO characteristics, so it is not a "pure" object-oriented language. Moreover, C supports a lot of controversial features in OO, such as: multiple inheritance, virtual inheritance (if you don't want to go with you, don't use them), etc., make C a very complex language. Some people even think that the size of C is much more than ada (on my opinion, Ada is a complicated language, and its strong type check makes the habit of freedom I feel like bringing a shackles).

In contrast, Java is "pure". Java is relieved in C but abandoning many of C that does not meet the characteristics of OO specification, and strives to make yourself simple. Java is not just a programming language. It also represents a trend. The Java program has a unified operational environment - Java virtual machine, so it can easily cross the platform, become a new favorite of major manufacturers. Compared with C , Java's largest disadvantage is that the operation is low, but with the shortcomings of Java itself and hardware, this disadvantage is increasingly unspeakable, and significant improvement in development efficiency makes a large number of C programmers transfer Java camp. Some people even think that Java will replace C languages ​​as high-level language replacement languages.

Talking about some problems for object-oriented

1. Object-oriented three largestones

Package, inherit, polymorphism

2. About code reuse

Object-oriented appearance, a large number of libraries are designed, compared to traditional function libraries, they are more easier to use, people think that a good code reuse mechanism is found, and the role of inheritance is exaggerated. However, many years have passed, and people find that the code is still very difficult to task. People are reflecting and put forward some new perspectives:

l Use inheritance with caution, more combination

l About the inheritance and interface inheritance

Realizing inheritance is a traditional inheritance method, which not only inherits the interface of the base class (member function), but also inherits the realization of the base class.

The interface inheritance finger only inherits the interface of the base class, but does not inherit the realization of the base class. For the convenience of understanding me to give an example of C :

Class Iadd

{

Virtual Int Add (INT I, INT J) = 0;

}

Class Add: Public Iadd

{

Int Add (INT I, INT J)

{

Return I J;

}

}

As a result of the base class only provides a description of an interface, the specific implementation is completed by realizing the manufacturer, and the implementation of different vendors can be interchanged due to the same interface.

If you use a standard interface, the developer as the software can purchase the implementation he needs on the market. At this time, the software will be built as a wood, which is called "Component Programming".

At present, new technologies, new ideas, new words are endless, dazzling. The various technical fields are increasingly differentiated, and the programmers are getting farther and farther from the bottom, and there are more and more fields that do not understand, and they are more and more anxious and fascinated. They have turned by the owner of the computer. Slave.

In short, this is a complicated era. This is an era that is completely lost in freedom. This is an era that makes the programmer's fascinating, no matter whether you like or not, we are now in this great era.

Five-communist society ?? language

This is an ideal society, human beings will move to the freedom kingdom and get the greatest freedom. But this era is still far away ...

转载请注明原文地址:https://www.9cbs.com/read-22363.html

New Post(0)