Your SlideShare is downloading. ×
0
Go lang introduction
Go lang introduction
Go lang introduction
Go lang introduction
Go lang introduction
Go lang introduction
Go lang introduction
Go lang introduction
Go lang introduction
Go lang introduction
Go lang introduction
Go lang introduction
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Go lang introduction

2,008

Published on

go lang

go lang

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,008
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
37
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  1. Go Lang Introduction yangwm http://t.sina.com.cn/yangwm
  2. A response to Google’s internal needs: - efficient large scale programming - speed of compilation - distributed systems - multicore hardware - networked computing
  3. GO: New Experimental Concurrent Garbage Collected Systems Language
  4. A complete (if simple) web server: import ( "fmt" "http" ) func handler(c *http.Conn, r *http.Request) { fmt.Fprintf(c, "Hello, %s.n", r.URL.Path[1:]) } func main() { http.ListenAndServe(":8080", http.HandlerFunc(handler)) }
  5. concepts: * Go's concurrency is strongly influenced by Communicating Sequential Processes (Hoare, 1978) * Go has types and interfaces, but no inheritance. It is arguably more object-oriented than previously mentioned languages, being closer to the original Smalltalk meaning (1970s)
  6. interfaces: type SortInterface interface { Len() int Less(i, j int) bool Swap(i, j int) }
  7. Concurrent: * In traditional concurrent programs, you communicate by sharing memory. In Go, you share memory by communicating. * Threads and locks are concurrency primitives; CSP is a concurrency model.
  8. Parallel computation is easy: var a string func f() { a = "hello, world" } func main() { go f() println(a) }
  9. via lock: var l sync.Mutex var a string func f() { a = "hello, world" l.Unlock() } func main() { l.Lock() go f() l.Lock() println(a) }
  10. via channel: var c = make(chan int, 10) var a string func f() { a = &quot;hello, world&quot; c <- 0 } func main() { go f() <- c println(a) }
  11. via once: var a string var once sync.Once func setup() { println(&quot;invoke setup()&quot;) a = &quot;hello, world&quot; } func doprint() { once.Do(setup) print(a) } func twoprint() { go doprint() go doprint() }
  12. thank you

×