Are dynamic languages ​​static languages

The difference between strong, weak, static and dynamic input

1. The difference between static and dynamic typing
Personally, I understand that this difference is mainly due to the different timing of the type test. That is, you can determine the type of language by determining when the language checks for type errors.

Static Type: The type of each variable is known at compile time. So if a type error occurs, the compilation will fail.

Dynamic typing: the type of each variable is not known at compile time. So when a type error occurs, an error occurs at runtime.

The Go type check takes place at compile time and is therefore statically typed.

2. The difference between compiled and interpreted
Personal understanding, whether compiled or interpreted, is essentially about translating high-level languages ​​(Java, C, Python, etc.) into languages ​​the computer can understand and execute. This difference is mainly due to the timing of the translation.

Compiled: The translation takes place before the execution of a program and translates a high-level language into a machine language. If you run it again, you can use the most recently translated machine code directly without recompiling it.

Interpret: The translation occurs when the program is running, that is, while the translation is being carried out. If you run it again you will have to compile it again.

The Go language can be compiled directly into an executable file. In Windows, for example, it can be compiled directly into an EXE file. So it's a compiled language.

3. Is the Java language typed statically or dynamically? Is it compiled or interpreted?
Java language type checking is done at compile time, so personally I think the Java language is a static type. Zh
The Java language first receives the .class file through the compiler, and then its virtual machine interprets and executes the .class files one by one. So I think Java is essentially an interpreted language, but it needs to be generated by the compiler first. Why do they do that? Personally, this goes for the cross-platform properties of Java. Unlike Java, some languages ​​are translated directly into machine code (e.g. C #), a typical type of compilation.
--------------------- 
Author: Saffron
Source: CSDN
Original: https://blog.csdn.net/ch717828/article/details/68951965
Copyright Statement: This article is an original article from the blogger. Please reprint the link to the blog post!

 

In statically typed languages, variables have types, and at compilation it is determined that variables of a given type can only contain data of the same type. In a dynamically typed language, variables have no type, only data have types, and variables can be any type of data. For example, C is a statically typed language and an int variable can only be treated as an int. Python is a dynamic language. Variables can contain integers, strings, lists, closings, and other data.

Java is often thought of as a static language, but it's not exactly that. Java variables have types, but variables can contain subtype data. For example, animal variables can include cat or dog. The specific type is determined by runtime data. This is clearly a characteristic of dynamic languages. In extreme cases, variables of type Object in Java can contain any data because each type is a subclass of Object. With all variables and function parameters declared as object type, I fear that Java can be used as a dynamic language. So Java is not a purely statically typed language, but breaks the boundary between the two.

The reason for this is to add dynamic functionality to static languages. Static languages ​​are strict and easy to review and optimize, but they are not flexible enough, especially with large software and changing requirements. A small change often requires changing multiple codes. The dynamic language is flexible, but due to the lack of type information, it is not easy to make mistakes in the early stages and it is not easy to optimize. This merger of Java is a good practice. It contains some of the type information that can be used to check and optimize compilation time. The remaining type information is shifted to execution-time decisions to ensure dynamics.

Generally speaking, static language and dynamic language are not one or the other, but a transition zone. If the code for the variable does not contain any type information, it is a purely dynamic language. In this case, all variables can be viewed as an object type. If your code can contain some type information on variables (these types are obviously derived object classes) then the language is static. The more abstract the type specified in the code, the less information (the abstraction is the object in the extreme). The more specific the type, the more information the compiler can examine in more detail and better optimize the code. If the type information of a variable is fully specified in the code, it is a purely static language. Imagine a language that is not limited to dynamic or static typing, but can be compiled and executed depending on the level of abstraction or specificity of the types specified in the code. Such a language should be able to better combine the flexibility of dynamic languages ​​with the rigor of static languages ​​and to adapt based on the specific adaptability of the code between the two.

 

Some of the concepts of the type system are different, and their usage is also chaotic. Some things aren't even well defined. The following is a relatively "strict" statement in academic circles.

 

First, understand the basic concepts

Program Errors

  • trapped errors. Causes the program to stop executing, e.g. E.g. divide by 0, array access out of bounds in Java
  • untrapped errors. Execution continues after an error, but any behavior can occur. B. Buffer overflow in C, jump to wrong address

Forbidden Behaviors

When designing a language, you can define a groupforbidden behaviorsIt must contain alluntapped errors, but it can contain included errors.

 

Well behaved 、 ill behaved

  • well behaved: If prohibited behavior is not possible during program execution, thenwell behaved
  • badly behaved: otherwise badly behaved ...

With the above concepts, we will discuss strong and weak typing, static and dynamic typing

Strong and weak types

  • Strongly typed: If all programs behave well in a language, ie prohibited behavior is not possible, the language is strongly typed.
  • Weak typed: Otherwise it is typed weakly. For example, the C language buffer overflow is associated with intercepted errors, that is, prohibited behavior. So C is a weak guy

Tends not to tolerate implicit type conversions. Weak types are less strict than strong types; B. implicit conversion of variable types, allowing casts, etc. Strongly typed languages ​​generally do not allow this.

Weak guy

1

2

Heavy typing

1

2

3

4

 

  

Dynamic and static input

  • Static: Statically typed if a badly behaved program is rejected at compile time;
  • Dynamic: If bad behavior is rejected at runtime, it is entered dynamically.

There are two types of static types:

  • If the type is part of the language syntax, it is entered explicitly, e.g. B. Java and C;
  • Implicitly entered if the type is inferred at compile time, e.g. B. ML and Haskell

Simply put, after a variable has been declared, the language, the type of which cannot be changed, is a static language. The language, which can change its type at any time, is a dynamic language. Due to the nature of dynamic languages, support for runtime virtual machines is generally required.

Dynamic type

1

2

3

4

5

6

 

 

Static type

1

2

3

4

5

6

  

 

  

 

  

 

Here are some examples