Golang ---- Go Chapter Overview

2.1 What is the program

Program: is a complete set of instructions

2.2 Why is Go Language

Google's Go language is created by language.

2.3 go language birth story

Here Insert Picture Description

Here Insert Picture Description

Existing programming language: 1. 2. style is not uniform enough computing power to handle large 3. concurrency is not good enough

Here Insert Picture Description

Features 2.4 Go language

Go language to ensure the safety and performance can achieve statically compiled language, but also to achieve a dynamic language development and maintenance of high efficiency, using an expression language to describe the Go, Go = c + Python, both the C language description of a static language program run rate, while maintaining the rapid development of dynamic Python development language.

  1. We inherited a lot of ideas from the C language, including expression syntax, control structures, basic data types, parameter call parameters by value, pointer or the like;

  2. Introducing the concept of packet structure used to organize the program, a file in Go must belong to a package, but not alone;

  3. Garbage collection, memory, automatic recovery, developers do not need management;

  4. Natural concurrent (Key Features) can achieve high concurrent processing;

  5. Absorbing pipe communication mechanism, a language-specific conduit Go Channel;

  6. Function can return multiple values

  7. New innovations: for example, slice slice, and so defer to delay execution

2.5 development tool (I use GoLand, have written before cracking method)
Here Insert Picture Description

2.6 How to Go program development

Here Insert Picture Description

Description: linux under development go and windows development is basically the same. When just run the executable file name in a manner ./

Explain the difference, the two kinds of execution process

(1) If we first compiled executable file, then we can copy the executable file to the machine does not go development environment, you can still run;

(2) If you go run go directly to the source code upon us, then again if another machine so run, also need to go development environment, or can not perform;

(3) then compile time, the compiler will run the program again dependent library file that contains an executable file, so a lot bigger executable file.

2.7 Description Compile and run

(1) With the source go file, binary file may be identified by the compiler to be compiled into a machine;

(2) in the source file directory, through go build on hello.go file is compiled, you can specify the name of the executable file generated, under the windows must be .exe suffix;

(3) If the program does wrong, without any prompting, there will be an executable file in the current directory (the windows are .exe suffix);

(4) If the program errors, compile-time, being given the wrong in that line.

2.8 Go program development Precautions

(1) go to the source file "go" for the extension;

Performing an inlet (2) go program is main () function;

(3) go strictly case-sensitive;

(4) go process consists of a statement, the statement does not require each the semicolon;

(5) go line by line compiler is compiled, only one line written statement, otherwise they will be wrong;

Variable or import of (6) go definition language pack if not used, the code will not compile;

Indispensable (7) braces in pairs.

2.9 Go language escape character (escape char)

(1) \ t: a tab stop, to achieve alignment function;

(2) \ n: line feed;

(3) \: a \;

(4) *: a *;

(5) \ r: a carriage return (output current from the front row, covering everything)

2.10 golang development of common problems and solutions

(1) the file name or path error;

(2) The most common mistake is grammatical errors ( "1" and "l"). go requires you to write code in accordance with the rules of grammar, if you program in violation of the rules of grammar, such as: forget the large Luo good, quotes, or misspelled word, Go compiler will report a syntax error, request: try to look the compiler error message quoted.

Notes 2.11

(1) line comments

(2) Block comment

Specification code specification 2.12

2.12.1 The official recommended line comment
2.12.2 have the right indentation and blank

Operation using a tab, indent implemented, default integrally move right, using shift + tab integrally moved to the left;

使用gofmt 来进行格式化;gofmt -v 

运算符两边习惯性各加一个空格,比如2 + 5 * 4

President conventions: the longest line of no more than 80 characters, use the wrap over the display, try to keep the elegant format.

Published 27 original articles · won praise 1 · views 1206

Guess you like

Origin blog.csdn.net/qq_40484416/article/details/103234117