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

Discovering Go

Discovering Go

My experiences of learning Go, and why I think it's a great tool to learn.

Joe Roberts

February 25, 2015
Tweet

More Decks by Joe Roberts

Other Decks in Programming

Transcript

  1. Go

  2. Statically typed animal := "gorilla" animal = false cannot use

    false (type bool) as type string in assignment
  3. Unused variables package main func main() { greeting := "hello"

    } Won’t compile! greeting declared and not used
  4. package main import ( "fmt" "net/http" ) func handler(w http.ResponseWriter,

    r *http.Request) { fmt.Fprintf(w, "Hello world!") } func main() { http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) } Web
  5. Error handling import "net/http" func handler(w http.ResponseWriter, r *htttRequest) {

    err := doSomethingThatMightFail() if err != nil { w.WriteHeader(http.StatusInternalServerError) } }
  6. Channels func main() { messages := make(chan string) go func()

    { messages <- "ping" }() msg := <-messages fmt.Println(msg) }
  7. “When writing the Go function, I started at the top

    and typed until I got to the bottom. And that was it. There aren’t very many ways to write this function in Go. I expect that most Go programmers, given the same set of helper functions, would have written it almost identically. Because of gofmt, I don’t even make formatting decisions.” - Rob Napier
  8. Now