2011 july-nyc-gtug-go

  • 906 views
Uploaded on

A quick talk about why I like Go. …

A quick talk about why I like Go.

Note that the bit about Go on Google App Engine requiring

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
906
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
17
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Why do I like Go? Ikai Lan - @ikai plus.ikailan.com NYC GTUG July 27, 2011Wednesday, July 27, 2011
  • 2. About the speaker • Developer Relations at Google based out of San Francisco, CA • I work on Google App Engine! • Google+: plus.ikailan.com • Twitter: @ikaiWednesday, July 27, 2011
  • 3. Why Go? • Fast, modern language • Strongly typed, very flexible interfaces • Functions as first class objects • Ridiculously fast compilation times • Concurrency baked in • ToolingWednesday, July 27, 2011
  • 4. Fast, modern languages • Standard library: JSON, websockets, web server; more • Garbage collection • Multiple return values • UnicodeWednesday, July 27, 2011
  • 5. Strongly typed • ... but feels like a dynamic languages • // Combo statement - We can infer type here, so no Java style type declaration redundancy s := “This is a String”Wednesday, July 27, 2011
  • 6. Flexible interfaces // This is an interface declaration type myInterface interface { set(i int) } // This is a Type declaration. Note that it is a type, not a class type myType struct { i int } // This is how we define a function where myType is a receiver // With an instance of myType we can call myType.set(123) func (p *myType) set(i int) { p.i = i } // Because myType defines a function with the signature set(int i) method, // we can use it anywhere myInterface is accepted! func setToThousand(x myInterface) { myInterface.set(1000) }Wednesday, July 27, 2011
  • 7. First class functions package main import "fmt" // Make a function that returns a new function func makeAdd(increment int) (counter func(int) int) { return func(v int) int { return v + increment; } } func main() { fmt.Printf("value of makeAdd(100)(1) is %vn", makeAdd(100)(1)); fmt.Printf("value of makeAdd(200)(2) is %vn", makeAdd(200)(2)); } // Outputs: // value of makeAdd(100)(1) is 101 // value of makeAdd(200)(2) is 202Wednesday, July 27, 2011
  • 8. Concurrency baked in • goroutines - prefix a go in front of a method and it will run concurrently! Similar to appending & in *nix systems • channels - blocking or buffered queues for cross process communicationWednesday, July 27, 2011
  • 9. Goroutines and package main Channels import ( "fmt" "time" ) func doLotsOfWork(until int, ch chan int) { c := 0 for i := 0; i < until; i++ { c += i time.Sleep(1000) } ch <- c } func main() { ch := make(chan int) // First the work off into the background go doLotsOfWork(5, ch) // Do more work here while we wait for this process to complete // Block until doLotsOfWork sends data back on this channel i := <- ch fmt.Printf("Final value: %vn", i) }Wednesday, July 27, 2011
  • 10. It runs on App Engine! • Currently requires whitelisting • Experimental status • Goroutines allow for concurrency within request; concurrent requests coming • Demo app: http://moustach-io.appspot.com/ • Source: https://code.google.com/p/ appengine-go/source/browse/example/Wednesday, July 27, 2011
  • 11. MustachioWednesday, July 27, 2011
  • 12. Questions? • Go (golang.org) - worth a look • Google+: plus.ikailan.com • Twitter: @ikaiWednesday, July 27, 2011