Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

epequeno

May 09, 2012
Tweet

Other Decks in Programming

Transcript

  1. My background My background • Python • Web design /

    development • Not compiled languages
  2. "Go is not meant To innovate Programming theory. It’s meant

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

    exciting? Because, it's very useful." -- Rob Pike paraphrased by Roger Peppe
  4. 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
  5. 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
  6. 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
  7. 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
  8. “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
  9. Hello Go package main import ( “fmt” “math” ) func

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

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

    { fmt.Println(“Hello ひらが” ) fmt.Println(math.Pi) } Pragmatism In action
  12. 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
  13. Syntax package main import ( “fmt” “math” ) func main()

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

    main() { fmt.Println(“Hello ひらが” ) fmt.Println(math.Pi) } Unicode out of the box
  15. Do not communicate by sharing memory; instead, share memory by

    Communicating. Communicating. --Effective Go
  16. 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.
  17. Goal: Get to the web web as fast as you

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

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

    can • Ruby has Sinatra • Python has web.py • Go has web.go web.go
  20. “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
  21. Conclusion Multiple cores? Parallelism? Compiling? Concurrency? Web apps? ARM? Databases?

    Networking? Systems??? Stop worrying worrying. The gopher's got you covered.
  22. 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.
  23. 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/
  24. 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:
  25. Presented to Presented to May 10, 2012 May 10, 2012

    Slides available @ j.mp/go_satlug