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.”
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."
#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.
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:
Go language has the following shortcomings:
golang advanced syntax
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() } }
有如下 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)
接着上题 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
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() { }
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() }
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!