Is go a high-level language?

青灯夜游
Release: 2022-12-06 18:05:43
Original
5488 people have browsed it

go is a high-level language. Go language is a high-level programming language open sourced by Google in 2009. It is designed to solve practical problems in the development process of large-scale systems. It supports concurrency, unified specifications, simplicity, elegance, and powerful performance; its main goal is to "have both The development speed of dynamic languages such as Python and the performance and security of compiled languages such as C/C.”

Is go a high-level language?

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

Computer languages are divided into high-level languages and low-level languages. High-level language is mainly relative to assembly language. It is programming that is closer to natural language and mathematical formulas. It is basically separated from the hardware system of the machine and writes programs in a way that is easier for people to understand. The program written is called the source program.

High-level language does not refer to a specific language, but includes many programming languages, such as the populargo language, java, c, c, C#, pascal, python , lisp, prolog, FoxPro, Yi Language, Chinese version of C language, etc. The syntax and command format of these languages are different.

Go language is a high-level programming language open sourced by Google in 2009. It is designed to solve practical problems in the development process of large systems. It supports concurrency, unified specifications, simplicity and elegance. , with powerful performance, has been praised by many Go language evangelists as "the C language in the cloud computing era". The main goal of the Go language is to "have both the development speed of dynamic languages such as Python and the performance and security of compiled languages such as C/C."

Is go a high-level language?

#The Go language is sometimes described as a "C-like language", or "the C language of the 21st century". Go inherits similar expression syntax, control flow structure, basic data types, call parameter value transfer, pointers and many other ideas from C language. It also has the running efficiency of compiled machine code that C language has always valued and is consistent with existing Seamless adaptation to the operating system.

Go’s AdvantagesDisadvantages

Programmer’s Voice: I can prototype, test, and deploy a production system in a matter of days if the real world requires it, and It can handle 5 times more requests per second than the original, and the CPU and memory overhead are still very small. I think only the Go language can do it.

The Go language has the following advantages:

  • Separate binary release: Go project compilation will generate a static executable file. This file can be run independently without any other dependencies. This approach is particularly suitable for cloud-native container environments.
  • Cross-compilation: Compile binaries on any operating system that run on other platforms. For example, on a Mac system, binary files can be compiled that can run on Linux and Windows.
  • Garbage collection: Go language supports garbage collection. In comparison, C, Rust, etc. require developers to control themselves.
  • Execution performance: Go is very fast. Performance is close to C. Much higher than Java, Python, and Node.
  • Development efficiency: Go language has both the running performance of static languages and the development efficiency of dynamic languages.
  • Simplicity and efficiency: The design philosophy of the Go language includes simplicity and efficiency. A typical counterexample is the complex and bloated Java language.
  • Concurrency: The language level supports concurrency, simplifies concurrent development through coroutines and channels, and improves concurrency performance.
  • Rich standard library: The Go standard library covers text, IO, network, encryption, Web services, remote RPC, template engine and other functions.
  • C language can be called: C language functions can be called to further optimize performance and reuse the huge ecosystem of C language.
  • Fast compilation time: Go compiles very quickly. You can refer to two static blog generation systems, Hexo (developed by Node) and Hugo (developed by Go).
  • Engineering type: The purpose of Go language design is to become an engineering language to solve actual engineering problems. The Go language defines development specifications and provides a wealth of tools. Using Go language, you can write programs that are easy to read and understand, and easy to test, maintain and expand. [Related recommendations:Go video tutorial,Programming teaching]

Go language has the following shortcomings:

  • Lack of heavyweight framework. Such as Ruby's Rails, Python's Django, and Java's Spring.
  • Error handling: No exception system. Go officials are fixing this problem.
  • Software package management: For a long time, Go has not officially had a package management system. Until recently, Go version 1.13 officially introduced Go Module as an official dependency management tool.
  • is not a standard object-oriented programming model: this is also an innovation of the Go language. If you are a solid OOP advocate, you may feel a little uncomfortable

golang advanced syntax

rune
package main import "fmt" //rune相当于go的char 使用utf8编码,中文占3个字节,英文一个字节 func main() { s:= "ok我爱你" fmt.Println(len(s)) // 11 fmt.Println(len([]rune(s))) // 5 fmt.Println(len([]byte(s))) // 11 // str是int32类型 for i, str := range s { fmt.Printf("%d %c", i, str) fmt.Println() } // str是byte类型 for i, str := range []byte(s) { fmt.Printf("%d %x", i, str) fmt.Println() } // str是rune类型 for i, str := range []rune(s) { fmt.Printf("%d %c", i, str) fmt.Println() } }
Copy after login
slice slice
  • The bottom layer of slice is the array
  • slice It is a view of the array
  • slice can be extended backwards, but cannot be extended forwards
  • s[i] cannot exceed len(s), and backward expansion cannot exceed the underlying array cap( s)
  • Slice maintains three variables internally. The ptr pointer points to the first element of the slice, len specifies the length of the slice, and cap specifies the capacity of the slice.
  • When the slice is appended, if the capacity is insufficient, it will be doubled.
有如下 arr := [...]{0, 1, 2, 3, 4, 5, 6, 7} s1 := arr[2:6] s2 := s1[3:5] 则 s1值为[2,3,4,5], len(s1)=4, cap(s1)=6 s2值为[5,6], len(s2)=2, cap(s2)=3 slice底层是数组 slice可以向后扩展,不可以向前扩展 s[i]不可以超过len(s), 向后扩展不可以超越底层数组cap(s)
Copy after login
接着上题 arr := [...]{0, 1, 2, 3, 4, 5, 6, 7} s1 := arr[2:6] s2 := s1[3:5] s3 := append(s2, 10) s4 := append(s3, 11) s5 := append(s4, 12) 则 s1值为[2,3,4,5] s2值为[5,6] s3值为[5,6,10] s4值为[5,6,10,11] s5值为[5,6,10,11,12] arr值为[0, 1, 2, 3, 4, 5, 6, 10] 由于s4和时s5已经超过arr的cap,此时系统会生成一个新的数组,所以s4和s5是对新数组的view,即s4和s5 no longer view arr
Copy after login
  • If the cap is exceeded when adding elements, the system will reallocate a larger underlying array, and the original array will be copied. If no one uses the original array, it will be gc
  • Due to value transfer, the return value of append must be accepted
map
  • go language so Types all have default values
  • When the key of the map value does not exist, only the default value will be returned and no error will be reported. To determine whether the key exists, use key, ok := m["key"]
  • map uses a hash table, and the keys of the map must be comparable
  • Except for slice, map, and function The built-in types can be used as key
  • The struce type does not contain the above fields, or they can be used as key
struct
  • Only pointers can be used to change the structure content
  • nil pointers can also call methods
  • How to expand system types or other people’s types: inheritance through structures and aliasing through types
package main // 如何扩充系统类型或者别人的类型:通过结构体继承,通过类型起别名 type queue []int func (q *queue) push(v int) { *q = append(*q, v) } func (q *queue) pop() int { head := (*q)[0] *q = (*q)[1:] return head } func (q *queue) isEmpty() bool { return len(*q) == 0 } func main() { }
Copy after login
  • Value receiver vs pointer receiver,

  • The value receiver is unique to the Go language

  • To change the content, you must use a pointer receiver.

  • If the structure is too large, consider using a pointer receiver.

  • Value/pointer receivers can all call value/pointer calls

package main import "fmt" type node struct { value int left, right *node } func newNode(value int) *node{ return &node{ value: value, left: nil, right: nil, } } func (n node) setVal(val int) { n.value = val } func (n *node) setValue(vall int) { n.value = vall } func (n node) print() { fmt.Println(n.value) } func (n *node) travel() { if n == nil { return } fmt.Println(n.value) n.left.travel() n.right.travel() } func main() { var root node root = node{} root.left = &node{value:5} root.right = new(node) root.left.right = &node{4, nil, nil} root.right.left = newNode(7) // 调用指针方法,相当于引用传递,可以改变外部的值 root.left.setValue(100) fmt.Println(root.left.value) // 值传递,调用值方法,方法内部不能改变外部值 root.left.setVal(99) fmt.Println(root.left.value) // 先序遍历 root.travel() }
Copy after login
interface
  • Multi-purpose interface combination
defer
  • panic and return do not affect defer The call

For more programming-related knowledge, please visit:Programming Video! !

The above is the detailed content of Is go a high-level 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
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!