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
- Co-process? go run (' Test ')
- Go enforces the writing style of {}: if expression {
- Error handling:
- Defer Equivalent to finally? Notice the scope here, and defer didn't seem to use {} to enclose the whole (try) block before?
- Defer equals the execution of deferred statements, and its internal implementation automatically manages the problem of nested scopes?
- Go allows multiple values to be returned (like a tuple returned in Python)
- Go with combination, no inheritance, virtual function, virtual function overload
- The variable declaration in GO is first variable name, after type name (Pascal style, but not:)?
- Is the interface of Go duck typing?
- Go, 2 interfaces as long as they have the same method list (name, signature, order ??). ), then the equivalent
- ? 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
- Limbo language on Plan 9 is considered to be the predecessor of Go?
- Support Automatic GC? --that's just like the performance of java/c#.
- Richer built-in types:
- Slice
- Map
- Multiple return values
- 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)
- FN, ln, nn: = GetName ()
-
pattern Match (destructuring): _,ln,_: = GetName ()
- Error handling: Defer, panic, recover
- Anonymous functions and closures
- F: = func (x, y int) int {return x+y}
- Type: A struct similar to C (estimated to have borrowed some of Objective-c's practices here ...) )
- Type Bird struct {...}
- Func (b *bird) Fly () {...}//The wording of this sentence I can not understand a bit? Damn it
- Concurrent programming
- Resultchan: = Make (chan, int, 2)
- Go sum (.../* parameter slightly */, Resultchan)
- Func sum (..., Resultchan Chan int) {
-
... resultchan <-sum
- SUM1, sum2: = <-resultchan, the <-resultchan//channel object has only one symbol operation: <-, left represents take out, the right side means put in?
- Reflection: By the way, the syntax is too ugly, damn it.
- Cgo
- 1th Go Program:
- Package Main
- Import "FMT"
- Func Main () {
-
fmt. Println ("Hello, world!")
- Go run hello.go//direct operation;
- Go build hello.go &&./hello//compile run, which can be interpreted or compiled (this is the same as rust)
[Edit]Sequential Programming
- VAR v3 [10]int//Perverted array declaration syntax ~
- var v7 Map [string] int//string->int
- I: = 10//automatic type deduction?
- I,j = J,i
- Numeric Type: int uint int32 int64 float32 float64 complex64 complex128
- Const
- 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)
- String Byte/rune Error
- UIntPtr
- Different types of numbers can not be directly compared, that is, go does not do automatic type promotion ?
- String traversal: For I: = 0; I < Len (str); i++ {... str[i]}
- Unicode character traversal:
- For i, ch: = Range str {...}
- An array is a value type!
- Slices: var myslice []int = Myarray[:5]
-
mySlice2: = Make ([]int, 5) dynamically add and
-
subtract elements: Len (myslice) cap (myslice) Append copy
...
- Map
- Delete (MyMap, "key")//, the operation here is in the C language style, does not support the c++/java/c#. member function Access operations?
- Process Control:
- If Else
- Switch case
- For
- Goto
- Function
- 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!
- Closed Package
- Error handling
- P48 return nil, &patherror ("stat", name, err)//What is the wording of & here? Pass an object in a reference way?
- Defer func () {...} ()
- Func Panic (interface ())
- Func Recover () interface ()
[Edit]OOP
- Value semantics (default?) ) and referential Semantics (&)
- ? Go uses the * symbol, so is it a pointer in C + +? (I guess not, but it's a little weird)
- Initialization
- R1: = new (Rect)
- R2: = &rect ()
- 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 (!! )
- Visibility: Uppercase is public, lowercase is private
- (non-intrusive) interface
- 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)
- interface Query : slightly
- Type query: VT: = V. (type)
- Interface Combination
- Any type: interface ()
[Edit]Concurrent Programming
- Main main does not wait for Goroutine to exit directly will cause the thread to force the end?
- channel
Li style= "margin-bottom:0.1em" >select (Is this the study of Erlang?)
- timeout mechanism: Create an additional channel
- timeout := make (chan bool, 1)
- go func () {time. Sleep (1E9) timeout <-true} ()
- select {
-
- using channel transfer to implement pipelines?
- One-way Chan: When declared, add <-
- close: Close (CH)
- Synchronous
- Sync. Mutex sync. Rwmutex
- Sync. Once
[Edit]Network Programming
- Net. Dial? This method name is too ... The
- Net/http
- Net/rpc
- Gob
- Json
[Edit]Secure Programming
- Slightly
[Edit]Engineering Management
- Remote import: Neuropathy!
- Gopath
- Android support??? --Must be run under the ADB shell.
[Edit]Development Tools[Edit]Advanced Topics
- reflection
- type, Value
- language interaction
- cgo:import" C "
- Link symbol: Consists of the following information (note go without overloading)
- pakcage
- classtype
- method (eh? Link symbols allow/, *,. ?
- goroutine mechanism
- libtask?
- interface mechanism
[Edit]Appendix A
- 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)