Compiled language, interpreted language, statically typed language, dynamically typed language concepts and differences

Today, I saw a blog post that summarizes static, dynamic, strong type, and weak type very well, under this Mark.

Compiled and Interpreted Languages

1. Compiled language

A language that requires a compiler to compile source code into machine code before it can be executed. Generally need to go through the compilation (compile), link (linker) these two steps. Compilation is to compile the source code into machine code, and linking is to concatenate the machine code of each module and the dependent library to generate an executable file.

Advantages: The compiler generally has a precompiled process to optimize the code. Because the compilation is done only once and does not need to be compiled at runtime, the program execution efficiency of the compiled language is high. Can be run independently of the locale.

Disadvantage: After compiling, if you need to modify it, you need to recompile the entire module. When compiling, the machine code is generated according to the corresponding operating environment. There will be problems in porting between different operating systems. Different executable files need to be compiled according to the operating operating system environment.

Representative languages: C, C++, Pascal, Object-C, and the recently popular new Apple language swift

2. Interpreted language

Interpreted language programs do not need to be compiled, which saves a process compared to compiled languages. Interpreted languages ​​are translated line by line when the program is run.

Advantages: It has good platform compatibility and can run in any environment, provided an interpreter (virtual machine) is installed. Flexible, you can directly modify the code when modifying the code, and can be deployed quickly without downtime for maintenance.

Disadvantages: It has to be interpreted every time it runs, and the performance is not as good as compiled languages.

Representative languages: JavaScript, Python, Erlang, PHP, Perl, Ruby

3. Mixed languages

Since the compiled and interpreted types have their own shortcomings, some people will think of integrating the two types, taking the best and removing the dross. There are semi-compiled languages. For example, C# and C# are not directly compiled into machine code but intermediate code when compiling. The .NET platform provides an intermediate language runtime library to run the intermediate code. The intermediate language runtime library is similar to the Java virtual machine. After .net is compiled into IL code, it is stored in the dll. When it is first run, it is compiled into machine code by JIT and cached in memory, and is executed directly next time (the blogger replied). I personally think that aside from bias, C# is the best programming language on the planet. Unfortunately, Microsoft's policy limits the promotion of C#.

Java first generates bytecode and then interprets and executes it in the Java virtual machine.

Strictly speaking, hybrid languages ​​are interpreted languages. C# is closer to a compiled language.

 

Dynamic and static languages

1. Dynamic language

A language whose structure can be changed at runtime: for example, new functions, objects, and even code can be introduced, existing functions can be deleted, or other structural changes can be made. In layman's terms, the code can change its own structure according to certain conditions at runtime.

Main dynamic languages: Object-C, C#, JavaScript, PHP, Python, Erlang.

2. Static language

Corresponding to a dynamic language, a language whose runtime structure is immutable is a static language. Such as Java, C, C++.

 

3. Note:

Many people think that interpreted languages ​​are dynamic languages, but this is wrong! Java is an interpreted language but not a dynamic language. Java cannot change its structure at runtime. Does the opposite hold? Dynamic languages ​​are interpreted languages. Also wrong! Object-C is a compiled language, but it is a dynamic language. Thanks to the unique run time mechanism (to be precise, run time is not a syntax feature but a runtime environment, which will not be expanded here) OC code can insert and replace methods at runtime.

C# is also a dynamic language. Through the reflection mechanism of C#, a piece of code can be dynamically inserted for execution. So I say C# is the best programming language on the planet.

 

Dynamically Typed Languages ​​and Statically Typed Languages

1. Dynamically typed languages

Many online sources confuse dynamically typed languages ​​with dynamic languages, which is simply misleading. Dynamically typed languages ​​and dynamic languages ​​are two completely different concepts. Dynamically typed languages ​​refer to languages ​​that do data type checking during runtime, which is about data types, while dynamic languages ​​are about changing structures during operation, and about code structures.

Data types in dynamically typed languages ​​are not determined at compile time, but deferred type binding until runtime.

Main languages: Python, Ruby, Erlang, JavaScript, swift, PHP, Perl.

2. Statically typed languages

The data type of a static language is determined during compilation or before running, and the data type of the variable must be clearly determined when writing code.

Main languages: C, C++, C#, Java, Object-C.

3. Note:

Quite a few programmers, including myself, think that interpreted languages ​​are dynamically typed languages ​​and compiled languages ​​are statically typed languages. This is also wrong. Swift is a compiled language but it is also a dynamically typed language. C# and Java are interpreted and statically typed languages.

Strongly and Weakly Typed Languages

1. Strongly typed languages:

In a strongly typed language, once a variable is assigned a data type, it will always be that data type if it is not casted. You cannot treat an integer variable as a string.

Primary languages: Java, C#, Python, Object-C, Ruby

2. Weakly typed languages:

Data types can be ignored, and a variable can be assigned values ​​of different data types. Once an integer variable a is assigned a string value, then a becomes a character type.

Main languages: JavaScript, PHP, C, C++ (C and C++ are controversial, but it is possible to assign an integer value to a character variable, probably the original intention is strong type, which is close to weak type in shape)

3. Note:

Whether a language is strongly typed is not necessarily related to whether it is dynamically typed. Python is a dynamically typed language, a strongly typed language. JavaScript is a dynamically typed language, a weakly typed language. Java is a statically typed language, a strongly typed language.

Quoted from http://www.cnblogs.com/zy1987/p/3784753.html?utm_source=tuicool&utm_medium=referral

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325693118&siteId=291194637