Go language Programming (old reading notes)

Source: Internet
Author: User
Tags switch case

Go Language Programming
Directory[Hide]
  • 1 preface
  • 2 beginner Go language
  • 3 sequential programming
  • 4 OOP
  • 5 Concurrent Programming
  • 6 Network programming
  • 7 Secure programming
  • 8 Project Management
  • 9 Development Tools
  • Ten Advanced topics
  • Appendix A
[Edit]Preface
  1. Co-process? go run (' Test ')
  2. Go enforces the writing style of {}: if expression {
  3. Error handling:
    1. Defer Equivalent to finally? Notice the scope here, and defer didn't seem to use {} to enclose the whole (try) block before?
      1. Defer equals the execution of deferred statements, and its internal implementation automatically manages the problem of nested scopes?
    2. Go allows multiple values to be returned (like a tuple returned in Python)
  4. Go with combination, no inheritance, virtual function, virtual function overload
  5. The variable declaration in GO is first variable name, after type name (Pascal style, but not:)?
  6. Is the interface of Go duck typing?
    1. Go, 2 interfaces as long as they have the same method list (name, signature, order ??). ), then the equivalent
  7. ? Avoiding too many {} nesting in Go can be a strategy-making it look more like a scripting language, giving programmers a sense of "lightness" in writing code ...
[Edit]first knowledge of Go language
  1. Limbo language on Plan 9 is considered to be the predecessor of Go?
  2. Support Automatic GC? --that's just like the performance of java/c#.
  3. Richer built-in types:
    1. Slice
    2. Map
  4. Multiple return values
    1. Func getName (FirstName, LastName, nickname string) {
      //Because the return value here also gives the name, so you can assign a value and then empty return! (Python does not seem to be so flexible, depend on)
    2. FN, ln, nn: = GetName ()
      pattern Match (destructuring): _,ln,_: = GetName ()
  5. Error handling: Defer, panic, recover
  6. Anonymous functions and closures
    1. F: = func (x, y int) int {return x+y}
  7. Type: A struct similar to C (estimated to have borrowed some of Objective-c's practices here ...) )
    1. Type Bird struct {...}
    2. Func (b *bird) Fly () {...}//The wording of this sentence I can not understand a bit? Damn it
  8. Concurrent programming
    1. Resultchan: = Make (chan, int, 2)
    2. Go sum (.../* parameter slightly */, Resultchan)
    3. Func sum (..., Resultchan Chan int) {
      ... resultchan <-sum
    4. SUM1, sum2: = <-resultchan, the <-resultchan//channel object has only one symbol operation: <-, left represents take out, the right side means put in?
  9. Reflection: By the way, the syntax is too ugly, damn it.
  10. Cgo
  11. 1th Go Program:
    1. Package Main
    2. Import "FMT"
    3. Func Main () {
      fmt. Println ("Hello, world!")
  12. Go run hello.go//direct operation;
    1. Go build hello.go &&./hello//compile run, which can be interpreted or compiled (this is the same as rust)
[Edit]Sequential Programming
  1. VAR v3 [10]int//Perverted array declaration syntax ~
  2. var v7 Map [string] int//string->int
  3. I: = 10//automatic type deduction?
  4. I,j = J,i
  5. Numeric Type: int uint int32 int64 float32 float64 complex64 complex128
  6. Const
  7. True false Iota (the beginning of each const starts from 0, each occurrence automatically increases by 1?). Used to define enumerations, but go does not support enum keywords)
  8. String Byte/rune Error
  9. UIntPtr
  10. Different types of numbers can not be directly compared, that is, go does not do automatic type promotion ?
  11. String traversal: For I: = 0; I < Len (str); i++ {... str[i]}
  12. Unicode character traversal:
    1. For i, ch: = Range str {...}
  13. An array is a value type!
    1. Slices: var myslice []int = Myarray[:5]
      mySlice2: = Make ([]int, 5) dynamically add and
      subtract elements: Len (myslice) cap (myslice) Append copy
      ...
  14. Map
    1. Delete (MyMap, "key")//, the operation here is in the C language style, does not support the c++/java/c#. member function Access operations?
  15. Process Control:
    1. If Else
    2. Switch case
    3. For
    4. Goto
  16. Function
    1. The member function is too strange to be written: func (file *file) Read (b []byte) (n int, err Error)//Note that there is no other language such as this, the self and other keywords!
  17. Closed Package
  18. Error handling
    1. P48 return nil, &patherror ("stat", name, err)//What is the wording of & here? Pass an object in a reference way?
    2. Defer func () {...} ()
    3. Func Panic (interface ())
    4. Func Recover () interface ()
[Edit]OOP
  1. Value semantics (default?) ) and referential Semantics (&)
    1. ? Go uses the * symbol, so is it a pointer in C + +? (I guess not, but it's a little weird)
  2. Initialization
    1. R1: = new (Rect)
    2. R2: = &rect ()
  3. The combination is inherited: type Derived struct{
    Base//can also be written in *base, so ... --equivalent to the virtual base class in C + +?
    ...//*log. Logger: Methods that can be injected directly into other classes? But the logger class obviously cannot access the data members of the current class (!! )
  4. Visibility: Uppercase is public, lowercase is private
  5. (non-intrusive) interface
    1. The syntax here seems a bit like the objective-c ... Note Declare type IFile interface {...} , the inside read, write does not need to take (f *file) (this reference)
    2. interface Query : slightly
    3. Type query: VT: = V. (type)
    4. Interface Combination
    5. Any type: interface ()
[Edit]Concurrent Programming
  1. Main main does not wait for Goroutine to exit directly will cause the thread to force the end?
  2. channel
      Li style= "margin-bottom:0.1em" >select (Is this the study of Erlang?)
    1. timeout mechanism: Create an additional channel
      1. timeout := make (chan bool, 1)
      2. go func () {time. Sleep (1E9) timeout <-true} ()
      3. select {
    2. using channel transfer to implement pipelines?
    3. One-way Chan: When declared, add <-
    4. close: Close (CH)
  3. Synchronous
    1. Sync. Mutex sync. Rwmutex
    2. Sync. Once
[Edit]Network Programming
    1. Net. Dial? This method name is too ... The
    2. Net/http
    3. Net/rpc
      1. Gob
    4. Json
[Edit]Secure Programming
    1. Slightly
[Edit]Engineering Management
    1. Remote import: Neuropathy!
    2. Gopath
    3. Android support??? --Must be run under the ADB shell.
[Edit]Development Tools[Edit]Advanced Topics
    1. reflection
      1. type, Value
    2. language interaction
      1. cgo:import" C "
    3. Link symbol: Consists of the following information (note go without overloading)
      1. pakcage
      2. classtype
      3. method (eh? Link symbols allow/, *,. ?
    4. goroutine mechanism
      1. libtask?
    5. interface mechanism
[Edit]Appendix A
    1. Common package: FMT io bufio strconv OS Sync flag Encoding/json http

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Go language Programming (old reading notes)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.