01: Introduction-[Programming Language]-excerpt & Annotation

Source: Internet
Author: User
Read navigation

For the directories of other articles in this series, stamp them here.

1. Machine language> assembly language> advanced language

Language is a tool for communication between people. For example, I write this blog post in Chinese to discuss technical issues. The same is true for programming languages, it's just a machine that communicates with people.

I can write blog posts in Chinese or English (if I am proficient in English). I can write a website using PHP or ASP. NET.

This indicates thatLanguage is essentially a communication tool.Which language does not affect the result of communication. However, in practice, the language should be determined based on the actual situation. This is a cost problem. For example, if my mind gets cramps today, I need to use Japanese, then I am tired of writing (the key is not), and the reader may also swear.

Early computers were a giant, and their energy consumption was equivalent to a small factory, but the computing power was indeed inferior to a hand-held calculator today. That is to say, at that time, the labor cost was much lower than the machine cost of the machine, which determined that the machine was centered, not human. Therefore, people use machine languages that computers can directly understand to write programs.

Here is a chestnut that calculates the maximum common divisor of two integers (the computer language of the MIPs r4000 processor). The hexadecimal format is as follows:

1 2dbdffd0 afbf0014 oc1002a8 00000000 0c1002a8 afa2001c 8fa4001c2 00401825 10820008 0064082a 10200003 00000000 10000002 008320233 00641823 1483fffa 0064082a 0c1002b2 00000000 8fbf0014 27bd00204 03e00008 00001025

These machine languages are unfriendly to reading and understanding people. As programs become more complex and people urgently need a simple and error-free form of recording, people create assembly languages and use short words to help remember machine operations.

The preceding example is rewritten using the MIPs r4000 processor assembly language:

 1    addiu  sp,sp-32 2    sw     ra,20(sp) 3    jal    getint 4    nop 5    jal    getint 6    sw     v0,28(sp) 7    lw     a0,28(sp) 8    move   v1,v0 9    beq    a0,v0,D10    slt    at,v1,a011 A: beq    at,zero,B12    nop    13    b      C14    subu   a0,a0,v115 B: subu   v1,v1,a016 C: bne    a0,v1,A17    slt    at,v1,a018 D: jal    putint19    nop20    lw     ra,20(sp)21    addiu  sp,sp,3222    jr     ra23    move   v0,zer

Reading and understanding of this chestnut is much easier than machine language. However, this encoding form is not recognized by computers. A program called assembler is required to translate it into the machine language of the corresponding machine for execution.

The relationship between such an assembly command and the path of a machine is still obvious. For different computers, different assembly languages are required; in this era, program design is still centered on machines. programmers may have to solve problems with machine thinking.

Just like the transition from machine language to assembly language, programming becomes increasingly complex and various types of computers become increasingly complex, making it increasingly difficult to compile programs for each machine and increasing labor costs.

According to the abstract principles used in the field of computer scienceAn intermediate layer is required to isolate the relationship between a computing operation and the specific operation commands of a specific machine.That is, the middle layer must be independent of specific machine operations. Then, people created a High-level programming language to make such an intermediate layer. Since computing operations are separated from specific machine operations, the specific execution of the machine is still a machine operation, A more "Advanced translator" is required for the translation. This advanced translator is the compiler.

Since this kind of translation work was completed by machines, in the early days of the emergence of compilers, people are always able to write the appropriate assembly language that is more efficient than the advanced language code (after all, the computing power of computers was also a luxury in the early days ). However, with the further expansion of the program, the improvement of hardware performance, the optimization of the compiler, And the maintenance cost of the program, this performance difference is slowly insignificant compared with the labor cost.

Now let's think about it. This is also the case when C ++ was launched and Java Based on Virtual Machine technology emerged.

Since the emergence of advanced programming languages, programming has gradually begun to shift from machine-centric to human-centric.

2. Compilation and interpretation

From an abstract point of view, the compilation and execution of advanced languages are roughly as follows:

After the compiler translates the source program into a Target Program (typically a machine-Language Program), the program will be removed from the need for a compiler to run.

The interpreter is another way to implement advanced languages:

Different from the compiler, the interpreter is always waiting. The interpreter itself is equivalent to a "Virtual Machine", and its "machine language" is the high-level language of the source program.

Compared with the compiler, the interpreter can have more flexibility. It can easily generate a new piece of code at the initial stage of the program running, and then execute it at a later time, and postpone some decisions to the runtime before making decisions. In contrast to the interpreter, a compiled language usually provides better performance. It can determine some decisions during compilation, such as some memory la S.

Although the concepts of the two are very clear and there are great differences, in reality, some languages are "mixed" and the process is roughly as follows:

If the translator in the initial stage is relatively simple, it is called an interpreted language. If the translation stage is complex, it becomes a compiled language.

However, simplicity and complexity are adjectives and cannot be quantified. It is entirely possible that a complex translator is responsible for generating intermediate language programs, and a Complicated Virtual Machine (Interpreter) is used to execute intermediate languages. Java and. NET are also implemented in this way.

  • Connectors and pre-processors

The program written in the advanced language we use usually requires a library (including some Io, network, and other operations ), during compilation, we need to link the source program we wrote with the library program to generate the target code. For example, to read and write files, we need to link the IO-related library program. Generally, the target code is an assembly language rather than a machine language. This method is more conducive to debugging programs and reading convenience. It also isolates the changes in the compiler and machine language file formats.

The pre-processor can provide a Conditional compilation function, such as the compiling condition # If debug in C #, and the macro mechanism in C and C ++ is also a pre-compiled fan Tao.

3. Programming Language Design implementation and Classification

In reality, there is always an irreconcilable conflict between language design and implementation. From the perspective of design, we always hope that a language can have more powerful expression capabilities, but it is always restricted by the implementation of the language. The root cause may be human-centered conflicts with machine-centric conflicts, because the execution of your language is ultimately inseparable from the execution of machines, therefore, Language designers have to seek a balance between the two.

Based on the existing computing model (the results produced by the calculation or the results affected by the calculation), there are roughly two categories (of course, these so-called classifications are also obtained from different perspectives. If you look at them from another perspective, it may be another scene.) declarative language and imperative language. From a certain perspective, the declarative language is obviously more "advanced", because it is closer to the user-programmer, and farther away from the implementer-language designer. However, the current language is still dominant, mainly because of the difficulty of implementation, performance requirements, and other reasons that restrict the development of declarative language. The upper layer is an abstract high-level language, and the lower layer is the implementation details. The higher the abstract level, the more difficult the implementation is, because the more complicated you want to isolate hidden details.

Functional language is one of the declarative languages, and its popularity has also increased sharply in recent years. The well-known C, C ++, Java, and C # Are all fan Tao of the Von noiman system, of course, it is also a subset of imperative languages. Unlike functional languages that use functions and values as the first-class citizens of the language (which can be assigned to variables, transmitted as parameters, and processed as return values, the basic operation in the von noriman language is the value assignment statement.Side effectsTo influence the subsequent computing results.

Scripting languages, such as JS, are generally explanatory languages with strong flexibility and generally act as "binder.

And so on.

Remarks

As these are all my personal opinions, some mistakes will inevitably occur. You are welcome to discuss them.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.