$30 off During Our Annual Pro Sale. View Details »

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. Go
    Go
    How I learned to stop worrying and
    love the gopher

    View Slide

  2. My background
    My background

    Python

    Web design / development

    Not compiled languages

    View Slide

  3. I know what you're
    thinking....

    View Slide

  4. A new
    new language
    you say?

    View Slide

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

    View Slide

  6. "Go is not meant
    To innovate
    Programming
    theory. It’s meant
    to Innovate
    programming practice."
    -- Samuel Tesla

    View Slide

  7. "Why would you have a
    Language that is
    Not theoretically
    exciting? Because,
    it's very useful."
    -- Rob Pike paraphrased
    by Roger Peppe

    View Slide

  8. Brought to you by...
    https://secure.flickr.com/photos/oreillyconf/4818477327/
    Rob Pike
    Unix, Plan9, Google
    Ken Thompson
    Yeah, that Ken Thompson
    +

    View Slide

  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

    View Slide

  10. Execution time
    Where does
    Go fit in?
    Gets out of your way

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

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

    View Slide

  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)

    View Slide

  17. KISS
    package main
    import (
    “fmt”
    “math”
    )
    func main() {
    fmt.Println(“Hello ひらが” )
    fmt.Println(math.Pi)
    }
    Pragmatism
    In action

    View Slide

  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

    View Slide

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

    View Slide

  20. UTF-8 Everywhere
    package main
    import (
    “fmt”
    “math”
    )
    func main() {
    fmt.Println(“Hello ひらが” )
    fmt.Println(math.Pi)
    }
    Unicode out of
    the box

    View Slide

  21. So, what's the big
    deal then?

    View Slide

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

    View Slide

  23. Do not communicate by
    sharing memory; instead,
    share memory by
    Communicating.
    Communicating.
    --Effective Go

    View Slide

  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.

    View Slide

  25. Go makes
    multi-core / parallel /
    concurrent programming
    TRIVIAL
    TRIVIAL

    View Slide

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

    View Slide

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

    Ruby has Sinatra

    View Slide

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

    Ruby has Sinatra

    Python has web.py

    View Slide

  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

    View Slide

  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

    View Slide

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

    View Slide

  32. Conclusion
    Multiple cores? Parallelism? Compiling? Concurrency?
    Web apps? ARM? Databases? Networking? Systems???
    Stop worrying
    worrying.
    The gopher's got
    you covered.

    View Slide

  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.

    View Slide

  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/

    View Slide

  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:

    View Slide

  36. Fonts from LOMT

    League Gothic
    ●Ostrich Sans

    Junction

    View Slide

  37. Presented to
    Presented to
    May 10, 2012
    May 10, 2012
    Slides available @ j.mp/go_satlug

    View Slide