When you learn a new programming language, you will often encounter static , dynamic , strong , weak , implicit , explicit types when you see the features of the programming language. Indefinitely, here combined with the online information to summarize their meanings and differences, the description is not necessarily professional, accurate, but to further understand the concept of these words can be.
The type system is used to define how numbers and expressions in a programming language are categorized into many different types, how these types are manipulated, and how these types interact. Depending on these differences, you can divide the programming language into the following categories:
Static type programming language VS dynamic type programming language
In a statically typed language, each variable name is bound to:
- A type that is bound by the definition of a variable at compile time
- An object, which is optional, if the variable name is not bound to an object, then the name points to null
For example, the following are definitions of string type variables in Java:
String str1; //reference to nullString str2 = "Hello world";
Two variables str1, str2 are defined, their types are String types, and str1 does not point to a specific object, but str2 points to a string object of "Hello world".
Note that the static type of programming language, once the variable name is bound to a type (by declaring the statement), then it can only bind to objects of this type (through an assignment statement). If you try to bind a variable of that type to a different type of object, you will throw an error with the type exception at compile time.
For example, the following code assigns an integer object to a String variable of type to give an error:
String str1;str = 10;
In a dynamic type language, each variable name is bound only to the object. Binding a name to an object when the program is running, and it is allowed if the name is bound to another object of a different type.
For example, here is the code in Python:
var = "Hello world"//...var = 10
The Var variable is first assigned a "Hello World" string object, which can be assigned to other types of objects at any time during the run. This does not make an error in Python.
Can reflect the difference between the two:
Java, C + +, C #, and so on can be seen as statically typed programming languages, while Python, PHP, and Perl are dynamic type languages.
Strongly typed programming language vs weakly typed programming language
Depending on whether the variable can be implicitly (implicit) converted to an unrelated (unrelated) type, the programming language can be divided into weakly typed programming languages and strongly typed programming languages, which can complete the conversion, while the latter requires explicit ( Explicit) to convert. Note that the unrelated type conversions here refer to conversions similar to numeric types and string types, while most languages allow implicit conversions between related types , such as conversions of type int to float.
In weakly typed programming languages, the number 9 and the string "9" can be converted to each other, for example, the following code is legal:
a = 9b = "9"c = concatenate(a, b) // produces "99"d = add(a, b) // produces 18
However, in a strongly typed programming language, the following two statements throw type exceptions, and to avoid these exceptions, we often need to do this through some explicit type conversion operations:
a = 9b = "9"c = concatenate(str(a), b)d = add(a, int(b) )
According to the above description, we can know that like Python, Java, and so on are strongly typed programming languages, and Perl, PHP, and so on are weakly typed programming languages.
Explicit type programming language vs implicit type programming language
There is also a way to differentiate between explicit and implicit type languages, depending on whether the variable name requires an explicit type declaration. The former requires the type of the variable to be explicitly given when the variable is defined, while the latter can use the type inference to determine the type of the variable.
Most of the statically typed languages, such as Java, C + +, are explicit type languages, but some are not, such as Haskell, ML, and so on, which can be inferred based on the operation of the variable; Scala is a new type of static typing programming language that runs on a Java virtual machine. Also used is type inference; Boo is a class Python programming language that runs on top of the. NET CLI and uses type inference.
Summarize
This article only gives a non-formal definition that aims to understand the design ideas of various types of programming in the type system, and of course this article only mentions the iceberg of the type system.
This article is a large number of content compiled from this article, also refer to the question and answer, wiki related terms, special thanks!
Type systems for programming languages