Differences between compiled and interpreted type, dynamic language and static language, strong type language and weakly typed language

Source: Internet
Author: User

I. Compiled and interpreted type

We first look at the compiler type, in fact, it is the same as the assembly language: There is a translation program to convert our source code, generate the corresponding executable code. This process is a bit more professional, called compilation (Compile), and the compiler responsible for compiling is naturally called the compiler (Compiler). If we write the program code is contained in a source file, then usually compiled after the direct generation of an executable file, we can run directly. But for a more complex project, for ease of management, we usually distribute the code in various source files as different modules to organize. When you compile individual files, you generate the target files (object file) instead of the executable file that you said earlier. Typically, a source file is compiled with a target file. The contents of these target files are basically executable code, but because they are only part of the entire project, we cannot run them directly. After all the source files have been compiled, we can finally "package" these semi-finished target files into an executable file, which is the responsibility of another program, because this process seems to be to assemble the target file containing executable code, so called link, And the program that is responsible for linking is called ... called the link Program (Linker). Link program in addition to link to the target file, there may be a variety of resources, such as icon files Ah, sound files ah what, but also responsible for removing the target file redundancy between duplicate code, and so on, so ... is also very tired. Once the link is complete, you will generally get the executable file we want.

We've probably introduced the features of the compiled language, and now we're going to look at the explanatory type. Well, literally, "compilation" and "interpretation" really mean "translation", but the difference is that the timing of the translation is not the same. For example: If you are going to read a foreign language book, and you do not know it, then you can find a translator, give him enough time to translate the whole book from beginning to end, and then give you the native language version of the book to read, or you can immediately let the interpreter assist you to read, let him sentence to you to translate, If you want to look back at a chapter, he will have to re-translate it for you.

Two ways, the former is equivalent to what we just said the compiler: once all the code into the machine language, and then written into the executable, and the latter is equivalent to the interpretation of the type: in the first moment of the program run, there is only the source program and no executable program, and every execution of the program to the source program, a command, There will be a shell called an interpreter that transforms the source code into binary code for execution, and in general, explains, executes, interprets, executes ... Therefore, the interpretation procedure is inseparable from the interpretation procedure. Like the early basic is a classic interpretation of the language, in order to execute the basic program, you have to enter the basic environment before you can load the program source files, run. In an explanatory program, because the program is always in the form of source code, the porting is almost no problem as long as there is a corresponding interpreter. Compiled program Although the source code can also be ported, but the premise is that different systems must be compiled separately, for complex projects, it is really a very small time consumption, and it is likely that some of the details of the place or to modify the source code. Moreover, the interpretation of the program saves the steps of compiling, debugging is also very convenient, editing can be run immediately, do not have to be like a compiled program every small change must be patient waiting for a long compiling ... Linking ... This process of compiling links. However, there are pros and cons, because the interpretation procedure is to put the process of compilation into the implementation process, which determines that the interpretation of the program is destined to be slower than the compilation of a large section, like hundreds of times times the speed gap is not surprising.

Compiled and interpreted type, both have pros and cons. The former because the program execution speed, the same conditions on the system requirements are low, so like the development of operating systems, large-scale applications, database systems, such as the use of it, such as C + +, Pascal/object Pascal (Delphi), VB and other basic can be regarded as compiled language, and some web script , server scripts, and auxiliary development interfaces for applications where speed requirements are low and the compatibility of different system platforms are required, it is common to use explanatory languages such as Java, JavaScript, VBScript, Perl, Python, and so on.

However, since the compilation and interpretation of the pros and cons of each other, so a number of emerging languages have a tradeoff between the two trends, such as the Java language is relatively close to the interpretation of the characteristics of the language, but before execution has been pre-compiled, generated code is between the machine code and Java source code between the intermediary code , the runtime is interpreted by the JVM (the Java Virtual Machine platform, which can be interpreted as an interpreter). It retains the high abstraction and portability of the source code and has completed much of the precompiled work on the source code, so it is much faster to execute than the "pure interpreter" program. and languages like VB6 (or previous versions), C #, Although the surface is generated by the. exe executable file, but the actual build after VB6 compiled is also a kind of intermediary code, but the compiler in front of a section of the automatic call to an external interpreter code (the interpreter is independent of the user-written program, stored in a DLL file of the system, all the executable program generated by VB6 compilation will be Use it) to explain the actual program body being executed. C # (and other. NET language compilers) generate. NET target code, which is executed by the. NET interpretation system (just like the JVM, which is also a virtual machine platform). Of course, the. NET target code is quite "low-level", closer to the machine language, so it is still considered a compilation language, and its portability is not as strong as Java claims, Java claims to be "compile, execute everywhere", while. NET is "once encoded, compiled everywhere." Oh, of course, these are off-topic. In short, with the development of design technology and hardware, the boundary between the two ways of compiling and interpreting is constantly becoming blurred.

Second, dynamic language and static language
Usually we call dynamic language, static language refers to dynamic type language and static type language.

(1) Dynamic type language: Dynamic type language refers to the language of data type checking during run time, that is, when programming in a dynamic type language, you never have to specify a data type for any variable, and the language will record the data type internally when you assign it to a variable for the first time. Python and Ruby are a typical dynamic type language, and many other scripting languages, such as VBScript, are also dynamic type languages.

(2) Static type language: Static type language is just the opposite of dynamic type language, its data type is checked during compilation, that is, when writing a program to declare all variables of the data type, C + + is a static type language typical representative, other static type language also has C #, Java and so on.

For dynamic language and static language distinction, apply a popular word is: static typing when possible, dynamic typing when needed.

Three, strong type definition language and weak type definition language

(1) Strongly typed definition language: A language that enforces the definition of a data type. In other words, once a variable is assigned a data type, it is always the data type if it is not cast. For example: If you define an integer variable A, the program simply cannot treat a as a string type. A strongly typed definition language is a type-safe language.

(2) Weakly typed definition language: a language in which data types can be ignored. In contrast to strongly typed definition languages, a variable can assign values of different data types.

Strongly typed definition language may be slightly slower than weak type definition language, but the rigor of strong type definition language can effectively avoid many errors. In addition, "The language is not a dynamic language" and "the language is the type of security" is completely no connection between!
For example: Python is a dynamic language and is a strongly typed definition language (type-safe language); VBScript is a dynamic language and is a weak type definition language (type unsafe language); Java is a static language and is a strongly typed definition language (type-safe language).

Differences between compiled and interpreted type, dynamic language and static language, strong type language and weakly typed language

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.