Go lang introduction
Upcoming SlideShare
Loading in...5
×
 

Go lang introduction

on

  • 2,382 views

go lang

go lang

Statistics

Views

Total Views
2,382
Views on SlideShare
2,382
Embed Views
0

Actions

Likes
2
Downloads
21
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Go lang introduction Go lang introduction Presentation Transcript

    • Go Lang Introduction yangwm http://t.sina.com.cn/yangwm
    • A response to Google’s internal needs: - efficient large scale programming - speed of compilation - distributed systems - multicore hardware - networked computing
    • GO: New Experimental Concurrent Garbage Collected Systems Language
    • 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)) }
    • 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)
    • interfaces: type SortInterface interface { Len() int Less(i, j int) bool Swap(i, j int) }
    • 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.
    • Parallel computation is easy: var a string func f() { a = "hello, world" } func main() { go f() println(a) }
    • 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) }
    • 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) }
    • 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() }
    • thank you