Intro to GO
Bangkok GO Meetup 2014
English>?
Still learning thai
My Level of thai
Survey the Audience
● Who a hip language, Ruby / Javascript
● Who uses Java / C#
● Has anyone played with GO?
Whats this talk about
● Instant Messenger Server in GO
● Why we chose go
● Basics about go
● How to get started with GO
Who am I ?
Small consulting firm Hyperworks
*Built Bloomberg.com
*Real time ad servers
*Ecommerce sites (gucci,reebok etc)
*Thomson Reuters Messenger Client/Server
What we’re we using
● Instant Messaging Server / Client
● Backend 100% GO
● 300k user base of financial traders!
● 20 Megabits of sustained traffic
Why GO?
C++
● Dying
● Hard to hire people
● Nothing new happening
● Not cool
Java
● Slow to code
● Very verbose
● Need a much larger team
C#
● Hate windows on a server
GO
● Lightweight concurrency
● Fast development cycle
● Hip with the kids
About GO
●
●
●
●
●
●

Google’s programming language
Garbage collected
Author is Rob Pike (Inventor of unix)
Fast Compilations
Fast Runtime
Easy to learn
Go is like C/C#/Java
Hello World (Aka a webserver)
import (
"fmt"
"http"
)
func handler(c *http.Conn, r *http.Request) {
fmt.Fprintf(c, "Hello, %s.n", r.URL.Path[1:])
}
func main() {
http.ListenAndServe(":8080", http.HandlerFunc(handler))
}
Lambdas
For javascript/ruby devs
valueToCloseOver := "My name is HAL."
anon := func(s string) string {
return "Hiya, " + name + ". " + valueToCloseOver
}
anotherFunction(anon)
Go Routines
● Lightweight threads
● Easy concurrency
● Like Erlang, communicate instead of sharing
memory
Channels
● Container for messages between go routines
● Concorrent safe
Code samples
c := make(chan int) // Allocate a channel.
// Start the sort in a goroutine; when it completes, signal on the channel.
go func() {
list.Sort()
c <- 1 // Send a signal; value does not matter.
}()
doSomethingForAWhile()
<-c // Wait for sort to finish; discard sent value.
No inheritance
● Interfaces over inheritance
● Duck typing
● Composition
Example interface code
type Stringer interface {
String() string
}
var value interface{} // Value provided by caller.
switch str := value.(type) {
case string:
return str
case Stringer:
return str.String()
}
Things not so good
● Windows support
● Small number of libraries
● Community still small but growing
How to get started
● http://play.golang.org/
● http://golang.org/doc/
Q/A
Thanks!

Btw We’re Hiring !

Intro to GO (Bangkok Launchpad 2014)