Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Why go ?
1. Go ? Go. Go !
Jean-François Bustarret - 1/12/2015
2. Why Go ?
Where : Google
Who : Rob Pike, Ken Thompson et Robert Griesemer
Why : C++ has a few problems
● maintenance problems as the codebase grows/ages
● productivity problems
● in a lot of cases, performance gains do not justify the time spent
3. Go vs competitor languages
C/C++
Java Go
Python
Performance
Developer Productivity
4. Goal #1: simplicity
● start with C
● remove every difficult to use feature (e.g. pointer arithmetics)
● add a couple of new features (GC, concurrency, maps, …)
● clean the syntax
● standardize coding style
Goal
● easy to learn
● easy to read/maintain existing code
● easy to parse
5. What is Go ?
● a compiled language, statically typed, with GC
● opinionated
● sequential and not event-driven
● concurrency
○ goroutines (collaborative multiplexing) - small CPU overhead, 2Ko RAM used, all CPU cores
available
○ channels (communication rather than sharing of state with mutexes)
● not object-oriented - composition prefered to inheritance
type Reader struct {...}
type Writer struct {...}
type ReadWriter struct { // has all methods and properties from both
Reader
Writer
}
6. What is Go ?
● first-class functions (a function is a value like any other)
type ReadFn func(buffer []byte) (int, error) // function type
func doSomething(fn ReadFn) {...} // function parameter
fn := func(buffer []byte) (int, error) {...} // anonymous functions
● methods on types
type FileReader struct {...}
func (rw *FileReader) Read(buffer []byte) (int, error) {...}
rw := NewFileReader()
rw.Read(...)
7. What is Go ?
● implicit interfaces (duck typing)
package io
type Reader interface {
Read(buffer []byte) (int, error)
}
package os
type File struct {...}
// os.File implements io.Reader
func (f *File) Read(buffer []byte) (int, error) {...}
8. What is Go ?
● reading a JSON document from a file
// Open a file
fd, err := os.Open(filename)
// Decode json data (takes a io.Reader as a parameter)
json.NewDecoder(fd).Decode(...)
● compressed data ?
fd, err := os.Open(filename)
bz := bzip2.NewReader(fd)
json.NewDecoder(bz).Decode(...)
9. What is Go ?
● HTTP ?
resp, err := http.Get("http://example.com/data.json.bz2")
// resp.Body implements io.Reader
bz := bzip2.NewReader(resp.Body)
json.NewDecoder(bz).Decode(...)
● Also works with
○ transports : FTP, ...
○ encodings : Base64, XML, ...
○ archives : tar, zip, ...
○ other : pipes
11. Strengths (cont.)
Standard library
● network, encoding, compression, crypto, …
● written in Go
Concurrency
Compiles to a (near) static binary, little to no dependency on 3rd party libs
Language stability (very good forward compatibility)
12. Weaknesses
True weaknesses
● Templating web vs Python/Ruby/PHP
● No generics
○ no implementation identified with acceptable impact on language simplicity
● Vendoring
○ work in progress
False weaknesses
● Verbose error management
● Hiring Go developers is difficult
● Performances
13. Can Go be used for high performance ?
Cloudflare (CDN) : log analysis, alerting, statistics
● 4 million log lines/s - 400 TB/day (after compression)
● https://www.youtube.com/watch?v=LA-gNoxSLCE
Youtube : vitess (MySQL proxy // PgBouncer on steroids)
● > 1 million MySQL queries/s
● https://github.com/youtube/vitess
Google : dl.google.com (all Google downloads - Chrome, Earth, SDK Android, …)
● replaces C++ with Go, < ½ code, better performance
● http://talks.golang.org/2013/oscon-dl.slide
14. Who uses Go ? What for ?
Infrastructure : containers, distributed or service oriented platforms
● Docker, Packer, Kubernetes, etcd, Consul, CoreOS
● NoSQL : InfluxDB, CockroachDB
● Supervision : Prometheus
● Message queues : NSQd, NATS
Startups heavily using Go
● Youtube, Bitly, Hailo, SoundCloud, Iron.io, Digital Ocean, twitch, Heroku, ...
15. References
Go philosophy :
● http://jmoiron.net/blog/for-better-or-for-worse/
● http://talks.golang.org/2012/splash.slide
● http://dave.cheney.net/2015/03/08/simplicity-and-collaboration
Documentation : https://golang.org/doc/effective_go.html
Learn Go : https://tour.golang.org