A little bit of Go language

It’s been a long time since I updated, the main reason is that I’m more used to writing notes locally, not uploading (it’s definitely not because I’m too lazy to typesetting!), and I’m going to speed up the process of finding a summer internship recently, so the update will continue to follow the fate, and I’ll post it when I’m free Here are some of my own notes, let’s take a look

Basic Features:

  • Go not only guarantees the safety and performance of statically compiled languages, but also achieves the efficiency of development and maintenance of dynamic languages
  • Inherited many concepts from C, including expression syntax, control structure, basic data type, call parameter passing value/pointer, etc.;
  • The concept of package is introduced to organize the program structure. A file in go language must belong to a package and cannot exist alone;
  • Introduced a garbage collection mechanism to avoid memory leaks
  • Natural concurrency, the language level supports concurrency, and can realize large concurrent processing (goroutine)
  • Absorbed the pipeline communication mechanism, the unique pipeline channel of go language
  • Functions can return multiple values
  • New innovations: slicing slices, delayed execution of defer, etc.
  • A line of go can't exceed 80 characters at most, and the extra characters should be replaced with commas to the next line
  • Interface-Oriented Programming instead of Object-Oriented Programming
  • In the go language, identifiers are used to identify function names, type names, method names, etc. If the first letter of the identifier is capitalized, it means that the content of the identifier is visible to the outside (that is, it can be passed through the import package to access the first letter of the first letter of the identifier in this package)

Compilation note:

  • The difference between go build and go run:

    go build: The executable file is compiled first. During the compilation process, the library files that the program depends on will be included in the executable file, so the executable file will also be typed a lot. We can copy the .exe file to no Run on the machine of the go development environment

    go run: can only be run on a machine with a go development environment

  • Every file in go must belong to a package

  • Go is compiled line by line, so only one statement can be written in a line

  • Variables defined by go or imported packages cannot be compiled if they have not been used

  • tab, achieve indentation and move to the back by default, shift+tab moves to the left as a whole

  • gofmt -w test.go auto-indent

Go project architecture:

  • bin: Stores the compiled binary files.
  • pkg: Store precompiled object files to speed up subsequent compilation of programs.
  • src: stores all .go files or source code. When writing Go applications, packages and libraries, they are generally $GOPATH/src/github.com/foo/barstored in the path of .

Guess you like

Origin blog.csdn.net/SFDWU3QVG/article/details/129637206