1, Go introduction

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

“Go is an open source programming language designed to make it easy to build simple, reliable, and efficient software.” (Definition from Go website golang.org)

Go, also known as Golang, was conceived in September 2007 and released in November 2009 by Google’s Robert Griesemer, Rob Pike, and Ken Thompson. The language and its accompanying toolset make compilation and execution expressive and efficient, and make it easy for programmers to write reliable, robust programs.

Go’s mascot is The Chipmunk (Gordon) and uses it as its logo, as shown below:

Go was developed in late 2007 by Robert Griesemer, Rob Pike, Ken Thompson, joined by Ian Lance Taylor, Russ Cox, and others, and finally opened source in November 2009, A stable version of Go 1 was released in early 2012. Go is now open to development and has an active community.

1.1 Origin of Go

The evolution of programming languages is similar to the evolution of biological species, in that successful languages reproduce, and these succeeding languages take advantages from their ancestors. Sometimes the “hybrid” of languages can be extraordinarily powerful; In rare cases, a significant linguistic feature can appear out of thin air without precedent. By looking at the effects of languages, we can learn a lot about why a language is the way it is and in which contexts it is suited.

The following figure shows which early programming languages had a significant impact on the design of Go.

Go is sometimes called a “C-like language,” or “the C language of the 21st century.” From C, Go inherits similar expression syntax, control flow structures, basic data types, parameter passing by value, and Pointers, but more importantly, it inherits C’s emphasis on programs that compile to efficient machine code and work naturally with the abstraction mechanisms provided by the operating system in which they operate.

But there are other ancestors in the Go family tree. One influential branch came from the Pascal language designed by Niklaus Wirth. Then the Modula-2 language inspired the concept of packages. The Oberon language then eliminates the distinction between module interface files and module implementation files. The second generation of Oberon-2 directly influenced the syntax of package import and declaration, as well as the declaration syntax of methods provided by the object-oriented features of Oberon.

Another ancestor of Go, which gave it important features that set it apart from other languages, It was inspired by the little-known basic document on concurrent research, Namely, communicating Sequential processes (CSP), published in 1978 by Tony Hoare of Bell LABS. In a CSP, a program is a set of parallel processes that run without shared state in between, using pipes to communicate and control synchronization. However, Tony Hoare’s CSP is only a description language for describing the basic concepts of concurrency, not a general-purpose programming language for writing executable programs.

Next, Rob Pike and others began trying to introduce CSP into actual programming languages. The first programming language they tried to introduce CSP features was Squeak (Mouse to Mouse Communication), a programming language that provided mouse and keyboard event handling, with pipes created statically. Then there is the improved Newsqueak language, which provides C-like syntax for statements and expressions and Pascal-like derivation syntax. Newsqueak is a pure functional language with garbage collection that again addresses keyboard, mouse, and window event management. But in Newsqueak, pipes are created dynamically and belong to the first class of values that can be stored in variables.

In the Plan9 operating system, these brilliant ideas were incorporated into a programming language called Alef. Alef tried to reinvent Newsqueak as a system programming language, but the lack of a garbage collection mechanism made concurrent programming a pain. Alef was followed by a programming language called Limbo, from which Go borrowed many of its features. Specific please refer to the Pike’s notes: talks.golang.org/2012/concur…).

Other features of Go come in bits and pieces from other programming languages; For example, ioTA syntax is borrowed from APL, lexical scopes and nested functions from Scheme (and many other languages). Of course, we can also find a lot of innovative design in Go. For example, Go slicing provides efficient random-access capability for dynamic arrays, which may be reminiscent of the underlying sharing mechanism of linked lists. There is also the newly invented defer statement of the Go language.

1.2 Characteristics of Go

  • Simple, fast and safe
  • Parallel, fun, open source
  • Memory management, array security, fast compilation

1.3 Use of Go

Go implements everything other languages can.

Currently, Go is mainly used in the following systems:

  • Server programming, Go is a good place to do things you used to do in C or C++, such as logging, data packaging, virtual machine processing, file systems, etc.

  • Distributed systems, database agents, etc., such as Etcd.

  • Network programming, which is currently the most widely used, including Web applications, API applications, download applications, and Go built-in NET/HTTP package basically we use the network functions are realized.

  • Database, developed by Google some time ago, Groupcache, part of Couchbase components, Tidb, Cockroachdb, Influxdb, etc.

  • Cloud platform, at present, many foreign cloud platforms are using Go development, CloudFoundy part of the construction, the former VMare technical director out of his own Apcera cloud platform.

  • Cloud native technologies such as Docker, Kubernetes, etc.

1.4 Go’s beauty

So, what does Go look like? We got a sneak peek at the beauty!

Let’s take Hello. Go for example and see what it looks like. (Go language source file extension is.go)

package main

import "fmt"

func main(a) {
    fmt.Println("Hello, World!")}Copy the code

2. Why do we learn to Go?

As far as I am concerned, I am mainly engaged in product research and development in the field of micro-services. I have always used Java language as the core programming language before, but as the market changes, Java sometimes becomes inadequate (some lightweight function modules are implemented, But Java is a little cumbersome). In addition, to meet the arrival of cloud native technology, learning Go has become inevitable.

Why do you want to learn Go? Here I refer to zhihu and online Dashen answers, talk about the advantages of Go language.

  • Go language features

    • Simple, fast and safe
    • Parallel, fun, open source
    • Memory management, array security, fast compilation
  • Go language usage

    Go is designed as a system programming language for large central servers with Web servers, storage clusters, and the like.

    Go is arguably more efficient than most other languages in the world of high performance distributed systems. It provides a huge amount of parallel support, which is great for game server development.

  • C/C + +

Low development efficiency and high requirements for developers; Libc is only backward compatible and difficult to operate and maintain.

  • Lua or Python

Dynamic language, lack of compilation process, low-level errors frequently; Lack of effective performance analysis and debugging tools.