Compiled, interpreted and dynamically typed and statically typed languages

1. Compiled language and interpreted language

Compiled language

Definition : Before the program is run, the source program is compiled into machine code (runnable binary code) by the compiler, and when the program is executed later, there is no need to compile it.

Advantages : The compiler generally has a pre-compilation process to optimize the code. Because the compilation is done only once and no compilation is required at runtime, the program execution efficiency of the compiled language is high and can be run independently from the language environment.

Disadvantage : If you need to modify after compilation, 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 environment of the operating system.

Summary : The execution speed is fast and the efficiency is high; it depends on the compiler and is less cross-platform.

Representative languages : C, C++, Pascal, Object-C and Swift.

Interpreted language

Definition : The source code of an interpreted language is not directly translated into machine code, but first translated into intermediate code, and then the intermediate code is interpreted and run by the interpreter. When it is running, the source program is translated into machine code, one sentence is translated, and then one sentence is executed until the end.

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

Disadvantages : It must be explained every time it runs, and its performance is not as good as a compiled language.

Summary : The execution speed is slow and the efficiency is low; it depends on the interpreter and has good cross-platform performance.

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

Mixed language

Definition : Since the compiled type and the interpreted type have their own shortcomings, some people will think of integrating the two types, taking the essence and removing the dross, and a semi-compiled and semi-interpreted language appears.

For example, C#, C# is not directly compiled into machine code but intermediate code when compiling. NET platform provides an intermediate language runtime library to run intermediate code, which is similar to the Java virtual machine. After .NET is compiled into IL code, it is saved in dll, and it is compiled into machine code and cached in memory by JIT when it is first run, and it is executed directly next time. Strictly speaking, mixed languages ​​are interpreted languages, and C# is closer to compiled languages.

Java is a compiled and interpreted language. Generally speaking, Java is closer to an interpreted language .

  • It can be said that it is compiled. Because all Java code needs to be compiled, .java is useless without being compiled. At the same time, around the efficiency of JVM, some optimization technologies such as JIT and AOT will be involved. For example, JIT technology will compile hot code into machine code. The AOT technology directly converts bytecode into machine code through tools before running.

  • It can be said that it is explanatory. Because the Java code cannot be run directly after being compiled, it is interpreted and run on the JVM, so it is interpreted and run.

2. Dynamically typed languages ​​and statically typed languages

Dynamically typed language

Dynamically typed language : A language that does data type checking during runtime, and it speaks of data types. The data type of a dynamically typed language is not determined at the compilation stage, but the type binding is delayed to the runtime stage.

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

Statically typed language

The data types of statically typed languages ​​are determined during compilation (or before running), and the data types of variables must be clearly determined when writing code.

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

3. Dynamic language and static language

Dynamic language

Dynamically typed languages ​​and dynamic languages ​​are two completely different concepts.

Dynamic language : It is about changing the structure at runtime, it is about the code structure. 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. In layman's terms, the code can change its structure according to certain conditions at runtime.

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

Static language

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

Guess you like

Origin blog.csdn.net/ThinkWon/article/details/108678327