Go: How I learned to stop worrying and love the gopher

Go: How I learned to stop worrying and love the gopher

An introduction / overview of the Go programming language targeted at python developers who are curious about Go.

B9fb24a54b73b53b06c90c3b78244190?s=128

epequeno

May 09, 2012
Tweet

Transcript

  1. Go Go How I learned to stop worrying and love

    the gopher
  2. My background My background • Python • Web design /

    development • Not compiled languages
  3. I know what you're thinking....

  4. A new new language you say?

  5. A new new language you say? cool story bro. cool

    story bro.
  6. "Go is not meant To innovate Programming theory. It’s meant

    to Innovate programming practice." -- Samuel Tesla
  7. "Why would you have a Language that is Not theoretically

    exciting? Because, it's very useful." -- Rob Pike paraphrased by Roger Peppe
  8. Brought to you by... https://secure.flickr.com/photos/oreillyconf/4818477327/ Rob Pike Unix, Plan9, Google

    Ken Thompson Yeah, that Ken Thompson +
  9. Quick stats: • Version 1 is now 43 43 days

    days old • Compiled language • Faster than Python • Garbage collection • Slower* than C *debatable • Production ready More details: • Officially announced Nov. 2009 • BSD license • Strong, static typing • Cross-platform
  10. Execution time Where does Go fit in? Gets out of

    your way
  11. Gets out of your way Execution time Python is really

    easy to read and write but execution time ins't always the best. Concurrency is available with tools like tornado but is not a “baked in” feature of the language. Python
  12. Execution time As I see it, but I've never actually

    written any C code so, this placement is probably totally wrong. Python Gets out of your way
  13. Execution time To me, Go is as clear and sensible

    as python but with performance characteristics closer to C. “C for the 21st century” - golang.org Python Gets out of your way
  14. “Before Go, a developer had to choose between fast execution

    but slow and not efficient building (like C++), efficient compliation (but not so fast execution like .NET or Java), or ease of programming (but slower execution, like the dynamic languages): Go is an attempt to combine all three wishes: efficient and thus fast compilation, fast execution, ease of programming.” – Ivo Balbaert The Way to Go
  15. Hello Go package main import ( “fmt” “math” ) func

    main() { fmt.Println(“Hello ひらが” ) fmt.Println(math.Pi) } Note the distinct lack of semi-colons
  16. No headers package main import ( “fmt” “math” ) func

    main() { fmt.Println(“Hello ひらが” ) fmt.Println(math.Pi) } Each file is part of a package (namespace)
  17. KISS package main import ( “fmt” “math” ) func main()

    { fmt.Println(“Hello ひらが” ) fmt.Println(math.Pi) } Pragmatism In action
  18. Don't fight it package main import ( “fmt” “math” )

    func main() { fmt.Println(“Hello ひらが” ) fmt.Println(math.Pi) } Must have main() function; Takes no arguments
  19. Syntax package main import ( “fmt” “math” ) func main()

    { fmt.Println(“Hello ひらが” ) fmt.Println(math.Pi) } OOP syntax (Go isn't really OO though)
  20. UTF-8 Everywhere package main import ( “fmt” “math” ) func

    main() { fmt.Println(“Hello ひらが” ) fmt.Println(math.Pi) } Unicode out of the box
  21. So, what's the big deal then?

  22. So, what's the big deal then? Concurrency Concurrency

  23. Do not communicate by sharing memory; instead, share memory by

    Communicating. Communicating. --Effective Go
  24. Goroutines and channels Goroutines are lightweight (around 4kb) functions running

    in the same address space. Not exactly the same as threads, coroutines or processes. func Announce(message string) { go func() { fmt.Println(message) }() } Conceptually similar to the & command in Unix to run a process in the background. Channels are how goroutines “talk” to each other, only one goroutine will ever have access to the data at any given time. c := make(chan int) go func() { list.Sort() c <- 1 }() doSomethingForAWhile() <-c In this example we make a channel of integers, call list.Sort() as a goroutine and when It's done, send the signal to c. We can call other functions while we wait for sort to finish. Once we get the signal, we can discard it.
  25. Go makes multi-core / parallel / concurrent programming TRIVIAL TRIVIAL

  26. Goal: Get to the web web as fast as you

    can
  27. Goal: Get to the web web as fast as you

    can • Ruby has Sinatra
  28. Goal: Get to the web web as fast as you

    can • Ruby has Sinatra • Python has web.py
  29. Goal: Get to the web web as fast as you

    can • Ruby has Sinatra • Python has web.py • Go has web.go web.go
  30. “web.go web.go is the simplest way to write web applications

    in the Go programming language. It's ideal for writing simple, performant backend web services. “ https://github.com/hoisie/web • Routing to url handlers based on regular expressions • Secure cookies • Support for fastcgi and scgi • Web applications are compiled to native code. This means very fast execution and page render speed • Efficiently serving static files
  31. Conclusion Multiple cores? Parallelism? Compiling? Concurrency? Web apps? ARM? Databases?

    Networking? Systems???
  32. Conclusion Multiple cores? Parallelism? Compiling? Concurrency? Web apps? ARM? Databases?

    Networking? Systems??? Stop worrying worrying. The gopher's got you covered.
  33. Resources - Main site http://golang.org/ - In-browser, guided sandbox http://tour.golang.org

    - Step by step through samples http://golang.org/doc/codewalk/ - Community pakages http://godashboard.appspot.com/ - Books http://go-lang.cat-v.org/books Bindings for couch, mongo, riak, mysql, redis, even bitcoin.
  34. Who is using Go? - Stathat -- http://blog.golang.org/2011/12/building-stathat-with-go.html - Google

    Thanksgiving doodle -- http://www.google.com/logos/2011/thanksgiving.html - Heroku - Cannonical - Atlassian - SmugMug Many others at http://go-lang.cat-v.org/
  35. Image References • Gohper images from golang.org • http://cdn-ak.f.st-hatena.com/images/fotolife/d/debiandebian/20100410/20100410114455.png •

    http://www.unixica.com/images/thompson.jpeg • http://1.bp.blogspot.com/-ti6s2UsV8no/Tdn82ozbggI/AAAAAAAAABM/AS4-YcQWfgo/s1600/gopher.jpg%20border= • http://farm8.staticflickr.com/7209/6779040884_3f7bfeaf89_z.jpg • http://27.media.tumblr.com/tumblr_kt2ejqry4W1qz5wuco1_500.jpg Oh yeah. If you were curious:
  36. Fonts from LOMT • League Gothic •Ostrich Sans • Junction

  37. Presented to Presented to May 10, 2012 May 10, 2012

    Slides available @ j.mp/go_satlug