2011 June - Singapore GTUG presentation. App Engine program update + intro to Go
2011 july-nyc-gtug-go
-
Upload
ikailan -
Category
Technology
-
view
914 -
download
0
description
Transcript of 2011 july-nyc-gtug-go
![Page 1: 2011 july-nyc-gtug-go](https://reader035.fdocuments.in/reader035/viewer/2022081907/54bb81da4a79598e0b8b457f/html5/thumbnails/1.jpg)
Ikai Lan - @ikaiplus.ikailan.com
NYC GTUGJuly 27, 2011
Why do I like Go?
Wednesday, July 27, 2011
![Page 2: 2011 july-nyc-gtug-go](https://reader035.fdocuments.in/reader035/viewer/2022081907/54bb81da4a79598e0b8b457f/html5/thumbnails/2.jpg)
About the speaker
• Developer Relations at Google based out of San Francisco, CA
• I work on Google App Engine!
• Google+: plus.ikailan.com
• Twitter: @ikai
Wednesday, July 27, 2011
![Page 3: 2011 july-nyc-gtug-go](https://reader035.fdocuments.in/reader035/viewer/2022081907/54bb81da4a79598e0b8b457f/html5/thumbnails/3.jpg)
Why Go?
• Fast, modern language
• Strongly typed, very flexible interfaces
• Functions as first class objects
• Ridiculously fast compilation times
• Concurrency baked in
• Tooling
Wednesday, July 27, 2011
![Page 4: 2011 july-nyc-gtug-go](https://reader035.fdocuments.in/reader035/viewer/2022081907/54bb81da4a79598e0b8b457f/html5/thumbnails/4.jpg)
Fast, modern languages
• Standard library: JSON, websockets, web server; more
• Garbage collection
• Multiple return values
• Unicode
Wednesday, July 27, 2011
![Page 5: 2011 july-nyc-gtug-go](https://reader035.fdocuments.in/reader035/viewer/2022081907/54bb81da4a79598e0b8b457f/html5/thumbnails/5.jpg)
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
![Page 6: 2011 july-nyc-gtug-go](https://reader035.fdocuments.in/reader035/viewer/2022081907/54bb81da4a79598e0b8b457f/html5/thumbnails/6.jpg)
Flexible interfaces// This is an interface declarationtype myInterface interface { set(i int)}
// This is a Type declaration. Note that it is a type, not a classtype 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
![Page 7: 2011 july-nyc-gtug-go](https://reader035.fdocuments.in/reader035/viewer/2022081907/54bb81da4a79598e0b8b457f/html5/thumbnails/7.jpg)
First class functionspackage main import "fmt"
// Make a function that returns a new functionfunc 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 %v\n", makeAdd(100)(1)); fmt.Printf("value of makeAdd(200)(2) is %v\n", makeAdd(200)(2)); }
// Outputs:// value of makeAdd(100)(1) is 101// value of makeAdd(200)(2) is 202
Wednesday, July 27, 2011
![Page 8: 2011 july-nyc-gtug-go](https://reader035.fdocuments.in/reader035/viewer/2022081907/54bb81da4a79598e0b8b457f/html5/thumbnails/8.jpg)
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 communication
Wednesday, July 27, 2011
![Page 9: 2011 july-nyc-gtug-go](https://reader035.fdocuments.in/reader035/viewer/2022081907/54bb81da4a79598e0b8b457f/html5/thumbnails/9.jpg)
Goroutines and Channels
package main 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: %v\n", i)}
Wednesday, July 27, 2011
![Page 10: 2011 july-nyc-gtug-go](https://reader035.fdocuments.in/reader035/viewer/2022081907/54bb81da4a79598e0b8b457f/html5/thumbnails/10.jpg)
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
![Page 11: 2011 july-nyc-gtug-go](https://reader035.fdocuments.in/reader035/viewer/2022081907/54bb81da4a79598e0b8b457f/html5/thumbnails/11.jpg)
Mustachio
Wednesday, July 27, 2011
![Page 12: 2011 july-nyc-gtug-go](https://reader035.fdocuments.in/reader035/viewer/2022081907/54bb81da4a79598e0b8b457f/html5/thumbnails/12.jpg)
Questions?
• Go (golang.org) - worth a look
• Google+: plus.ikailan.com
• Twitter: @ikai
Wednesday, July 27, 2011