Go language study notes (1) Let's do it

Join the Golang learning QQ group to learn and progress together, start a family, start a career and work ^-^ Group number: 96933959

Introduction

    Go is a static strongly typed, compiled, concurrent programming language developed by Google with garbage collection. It is sometimes referred to as Golang for ease of search and identification.

    Robert Grishmore, Rob Pike and Ken Thompson started designing the Go language in September 2007, with Ian Lance Taylor and Russ Cox joining the project later. The Go language is developed based on the Inferno operating system. The Go language was officially announced in November 2009 and became an open source project, and was implemented on Linux and Mac OS X platforms, and later added the implementation under Windows. Go 1 stable version was released in early 2012.

    Go development is now fully open and has an active community.

 

    The syntax of Go language is close to that of C language, but the declaration of variables is different. Go language supports garbage collection function. Go's parallel model is based on Tony Hall's Communicating Sequential Processes (CSP). Other languages ​​that have adopted a similar model include Occam and Limbo, but it also has features of Pi operations, such as channel transport. Open Plugin support in version 1.8, which means that some functions can now be dynamically loaded from the Go language.

    Compared with C++, the Go language does not include functions such as exception handling, inheritance, generics, assertions, virtual functions, etc., but adds language-level support for features such as slices, concurrency, pipelines, garbage collection, and interfaces. Google is still debating whether it should support generics, and it's still very open, but on the language's FAQ list, it's negative about the existence of assertions, while also defending itself for not providing type inheritance.

    Unlike Java, Go has built-in associative arrays (also known as hashes or dictionaries), just like string types.

I have a few Alibaba Cloud lucky coupons to share with you. There will be special surprises for purchasing or upgrading Alibaba Cloud products with the coupons! Take all the lucky coupons for the products you want to buy! Hurry up, it's about to be sold out.

 

language features

1. Garbage Collection

  1. Memory is automatically reclaimed, and developers no longer need to manage memory 
  2. Only need to allocate new memory, no need to release

2. Natural concurrency

  1. Support concurrency from the language level, very simple
  2. Goroutine, lightweight thread, it is possible to create thousands of goroutines

  3. Implementation based on CSP (Communicating Sequential Process) model

3. channel

  1. Pipe, similar to pipe in unix/linux
  2. Communication between multiple goroutines through channels

  3. support any type

  4. The close built-in function is used to close the channel

4. Goroutine

    The main function of the Go language is its easy-to-use parallel design. This method is called Goroutine. Through Goroutine, your program can run in an asynchronous manner without worrying about a function causing the program to interrupt. Therefore, the Go language is also very suitable. Internet service.

    A goroutine is a thread-like concept (but a goroutine is not a thread). Threads belong to the system level. Generally speaking, creating a new thread consumes more resources and is not easy to manage. Goroutine is like a lightweight thread, but we call it concurrency. A Go program can run more than tens of thousands of Goroutines, and these performances are native-level, and can be closed and ended at any time. There can be multiple Goroutines in a core. With the GOMAXPROCS parameter, you can limit how many system threads Gorotuine can occupy to avoid running out of control.

    Goroutine applications can also be seen from time to time in the built-in official packages. For example, the function used to monitor network services in net/http actually creates a Goroutine that runs continuously.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325310790&siteId=291194637