Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The difference between weak type, strong type, dynamic type and static type in programming language

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

In this issue, the editor will bring you the differences between weak types, strong types, dynamic types and static types in programming languages. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Sometimes when you go to an interview, such as an iOS development position, the interviewer will ask questions along the runtime and dynamics, and you will be confused if you don't know some basic knowledge of the programming language! As a developer, are you confused about weakly typed, strongly typed, dynamically typed, and statically typed languages?

Dynamic language vs static language (dynamically typed language vs statically typed language)

Statictypingwhenpossible,dynamictypingwhenneeded

Type system (typesystem): a system in a program that specializes in data processing. Languages can be divided into:

Dynamic system (dynamicallytypedsystems), such as Lisp,JavaScript,Tcl and Prolog

Statically typed systems (staticallytypedsystems), such as C++ and Java

Static system staticallytypedsystems) can be further divided into:

Contains a declarative type (manifesttype) language, that is, the type of each variable and function is clearly declared

Type-inferred language (e.g. MUMPS,ML)

Classification of four languages and their differences

Dynamically typed language (DynamicallyTypedLanguage):

A language that does data type checking only at runtime, that is, when programming in a dynamically typed language, you never have to specify a data type for any variable. The language records the data type internally when it first assigns a value to a variable.

For example: ECMAScript (JavaScript), Ruby, Python, VBScript, php

Python and Ruby are typical dynamically typed languages, while other scripting languages such as VBScript are more or less dynamically typed.

Advantages: easy to read, no need to write a lot of type-related code

Disadvantages: it is not convenient to debug, non-standard naming will make it difficult to understand, not conducive to understanding, etc.

Statically typed language (StaticallyTypedLanguage)

The language used to check data types during compilation, that is, to declare the data types of all variables when writing a program, is fixed. Before you can use data, you must declare the data type (int,float,double, etc.). It is equivalent to allocating memory space for them before using them.

For example, C _ is a typical representative of statically typed languages. Other statically typed languages include C #, JAVA and so on.

Advantages: the structure is very standard, easy to debug, convenient for type safety

Disadvantages: to do this, you need to write more type-related code, which is not easy to read and unclear.

Strongly typed definition language (Explicittypeconversion, mandatory data type definition language, type safe language):

Once a variable is assigned a data type, it will always be that data type if it is not cast.

For example: if an integer variable an is defined, a cannot be treated as a string type without display conversion

A strongly typed language is a language that requires variable / object type declaration and generally needs to be compiled and executed. For example, C/C++/Java/C#

Weakly typed definition language (Implicittypeconversion, type unsafe language):

A language in which data types can be ignored. In contrast to strongly typed definition languages, a variable can assign values of different data types.

For example: in VBScript, you can concatenate the string'12 'with the integer 3 to get the string' 123, which can then be thought of as the integer 123 without showing the conversion.

The above is the difference between weak type, strong type, dynamic type and static type in the programming language shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report