Home  >  Article  >  Backend Development  >  Is go language a static language?

Is go language a static language?

青灯夜游
青灯夜游Original
2023-01-30 18:35:293862browse

Go language is a static language. GO is a statically strongly typed, compiled, concurrent programming language with garbage collection capabilities developed by Google. Static language (strongly typed language) is a language in which the data type of variables can be determined at compile time; in Go language, variables have clear types, and the compiler will also check the correctness of variable types. The general form of declaring variables is "var name type".

Is go language a static language?

The operating environment of this tutorial: Windows 7 system, GO version 1.18, Dell G3 computer.

GO is a statically strongly typed, compiled, concurrent, and garbage collection programming language developed by Google.

In the Go language, variables have clear types, and the compiler will also check the correctness of the variable type. In mathematical concepts, a variable represents a number that has no fixed value and can be changed. But from a computer system implementation perspective, a variable is one or more segments of memory used to store data.

The general form of declaring variables:

var name type

Among them, var is the keyword to declare the variable, name is the variable name, and type is the type of the variable.

It should be noted that the Go language is different from many programming languages ​​in that it puts the type of the variable after the name of the variable when declaring the variable. The advantage of this is that it can avoid ambiguous declaration forms like in C language, such as int* a, b;. Only a is a pointer and b is not. If you want both variables to be pointers, you need to write them separately. In Go, they can and easily be declared as pointer types:

var a, b *int

The basic types of the Go language are:

  • bool

  • string

  • int、int8、int16、int32、int64

  • uint、uint8、uint16、uint32、uint64 , uintptr

  • byte // Alias ​​of uint8

  • rune // Alias ​​of int32 represents a Unicode code

  • float32, float64

  • complex64, complex128

When a variable is declared, the system automatically assigns it the zero value of that type. : int is 0, float is 0.0, bool is false, string is empty string, pointer is nil, etc. All memory in Go is initialized.

Extended knowledge: Introduction and differences between dynamic languages ​​and static languages

Dynamic languages ​​(weakly typed languages) are languages ​​that determine the data type at runtime. There is no need to declare the type of a variable before using it. Usually the value of the variable is the type of the value to which it is assigned. Such as Php, Asp, JavaScript, Python, Perl, etc.

$a = 1;
$b = "2";
$c = [1,3,4];

Static language (strongly typed language) is a language in which the data type of the variable can be determined at compile time. Most static languages ​​require that the data type must be determined before using the variable. Such as Java, C, C, C#, etc.

String s="hello";    //String 类型的变量
boolean b=true;    //boolean 类型的变量
int i=0;    //int 类型的变量

Weakly typed language is a language in which data types can be ignored. It is the opposite of a strongly typed language, where a variable can be assigned values ​​of different data types. A variable's type is determined by its context, which is more efficient.

Strongly typed language is a language that must force the data type to be determined. Once a variable is assigned a certain data type, if it is not forced to convert, it will always be this data type. The type of a variable is determined when it is declared, which is safer.

Difference:

  • Due to the mandatory declaration of data types, the static language allows the development tool (IDE) to have a strong ability to judge the code. When implementing complex business logic and When developing large-scale commercial systems and applications with long lifecycles, developers can rely on powerful IDEs to develop more efficiently and safely.

  • Dynamic language thinking is not constrained and can be used at will, focusing more on the product itself; focus on thinking about business logic implementation, and the thinking process is the implementation process.

[Related recommendations: Go video tutorial, Programming teaching

The above is the detailed content of Is go language a static language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn