Is go a weak language?

王林
Release: 2023-02-09 16:08:01
Original
2284 people have browsed it

go is not a weak language. Go is a strongly typed language developed by Google. In the Go language, there is no need to write a semicolon after each line of program, braces cannot be placed on a new line, and if judgments and for loops do not need to be wrapped in parentheses.

Is go a weak language?

The operating environment of this article: windows10 system, GO 1.18, thinkpad t480 computer.

Go is not a weak language, but a strongly typed language.

Go (also known as Golang) is a statically strongly typed, compiled, concurrent programming language with garbage collection capabilities developed by Google's Robert Griesemer, Rob Pike and Ken Thompson. . The Go language syntax is similar to C, but its functions include: memory safety, GC (garbage collection), structural form and CSP-style concurrent computing.

Introduction to weakly typed languages ​​and strongly typed languages

  • Weakly typed language is the runtime In a language that only determines the data type, 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.

    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 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.

    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.

Performance of strong typing in Go language

In Go language, variables have clear types Yes, 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
Copy after login

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
Copy after login

When a variable is declared, the system automatically assigns it a 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: The basic types of 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

[Related recommendations:

Go video tutorial, Programming teaching

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!