What Is Strong Typing?
Strong typing means that the type to which any object expressed in a program must depend can be determined at compile time. Commonly strongly typed languages are C ++, Java, Apex, and Python. Strongly typed languages have huge advantages in the development of large-scale information systems.
- Strong typing is for the strictness of type checking. It means that any variable must specify its type when it is used, and this variable can only store data of this type during the running of the program. Therefore, for strongly typed languages, a variable is not cast, it is always this data type, and implicit type conversion is not allowed. For example: suppose a variable a of type double is defined, and the program int b = a cannot be compiled without coercion. Commonly used strongly typed languages are Java, C #, Apex, and Python.
- Strong typing is an advantage of custom classes, it makes the data handled by objects easier to understand. Therefore, strongly typed languages have huge advantages in large-scale information system development, especially when designers define a data access layer composed of custom classes and publish the design to other programmers in the organization. It can find many errors that are easily overlooked during the compilation process through the type checking mechanism, thereby ensuring the quality of the software and making large-scale software integration possible. [1]
- There are three types of languages: weak type and weak type. Among them, no type does not check, and even does not distinguish between instructions and data; weak type checks are weak, and only strictly distinguish between instructions and data; strong types are strictly checked at compile time. Strongly typed languages do not allow two different types of variables to interoperate without coercion. For example, weakly typed languages allow implicit conversion of variable types, coercion, etc., such as string and numeric values can be automatically converted; strongly typed languages generally do not allow this. An example is given below.
- (1) Weakly typed language vbs:
- a = 1
- b = a + "1" + "a" // The result is 11a, where a becomes a string
- c = a + 1 // The result is 2, where a is a number
- (2) Strongly typed language C #:
- int a = 2
- string b = a.ToString () + "1" + "a"
- int c = a + 1
- The above example can illustrate: Weakly typed language has no obvious type, and it can automatically change the type with different environments; strong type does not have such a rule. Operations between different types are strictly defined. Variables can only be manipulated.
- (1) Regardless of whether it is strongly typed or weakly typed, variables have two attributes: type and value; that is, weakly typed variables also have types. Regardless of the programming language, the variables used in it have both types and values. Strongly typed variable types must be clearly defined in the source code and called "variable declarations". Weakly typed variable types do not need to be declared and are interpreted by the interpreter. However, this does not mean that weakly typed variables have no concept of type. For example, PHP's gettype returns the "current" type of the variable.
- (2) The type of a strongly typed variable cannot be changed, and a weakly typed variable is changed on demand. This is the true meaning of strong and weak. Once a strongly typed variable is declared, it can only store a value of this type. Other values must be converted before they can be paid to the variable. There are conversions that the compiler understands automatically, and there are coercions explicitly specified by the programmer. However, weakly-typed variable types are continuously converted as needed.
- (3) The cast does not change the variable type. A strongly typed language has a "cast", which changes the type of the value of a variable for assignment without changing the type of the variable. The type of a variable cannot be changed.
- (1) An error type match can be checked at compile time to improve program security;
- (2) The corresponding operations can be optimized according to the type of object to improve the quality of the target code;
- (3) Reduce overhead at runtime. [2]