-
1.
Introduction to Go
AND WHY IT’S AWESOME
-
2.
About me
SWE at Google
Open source
Kubernetes written in Go
https://github.com/kubernetes/kubernetes
-
3.
Today you’ll learn
What is Go?
Why Go?
Basic Syntax
Features
-
4.
A little background
about Go...
-
5.
History
Started at Google
Released, open-sourced in 2009
New, modern
20161945
C
1972
Python
1991
Java
JavaScript
1995
Go
2009
https://golang.org/
-
6.
Why Go?
Google internal needs
★ Efficient large scale programming
★ Distributed systems
★ Speed of compilation
★ Multicore, networked hardware
http://xkcd.com/
-
7.
Go is…
Fast compilation time
Concurrent
Garbage-collected
Modern with support for networked and
multi-core computing
General-purpose
Compiled
Statically typed like C, Java
Feels as easy, lightweight as JS, Python
-
8.
Design Principles
Simplicity concepts easy to understand
Orthogonality concepts mix cleanly
Readability comprehensible with little context
-
9.
Companies Using Go
http://stackshare.io/go/in-stacks
-
10.
Some basic syntax
-
11.
Hello World
-
12.
Functions
-
13.
Object-oriented?
-
14.
Yes and no...
Composition over inheritance
★ No type hierarchy
★ No class
★ No generics
-
15.
Simple Type System
Statically typed, with type inference
-
16.
Types and methods
You can define methods on any type I mean ANY
-
17.
Interfaces
An interface type defines a set of methods
-
18.
More on Go features
-
19.
Concurrency
UNIX: processes connected by pipes
$ find ~/go/src/pkg | grep _test.go$ | xargs wc -l
Go: goroutines connected by channels, concurrency made easy to use
-
20.
Concurrency: goroutines
Lightweight threads
-
21.
Concurrency: channels
Channels are a typed pipe for
★ Synchronization
★ Communication
-
22.
Concurrency philosophy
The efficiency of an asynchronous model written in a synchronous style
Connect goroutines with channels -- simpler, maintainable code
-
23.
Tooling
gofmt reformats code
goimports updates import lines
golint prints style mistakes
godoc documentation of packages and symbols
go vet vets the package
go get download and install packages and dependencies
go test automates testing the packages
no more tabs vs. spaces!
no more “import not used”, or “import not found”
-
24.
Rich library support
Comprehensive standard library
150+ packages
Many great external libraries
120, 000+ packages
https://godoc.org/
-
25.
What’s Go good for?
-
26.
Go: a general-purpose language
Not just a “systems language”
Unexpected interest from users of scripting languages
Diverse uses across the community
★ Scientific computing
★ Web applications
★ Graphics and sound
★ Network tools
★ … and much more
-
27.
Demo:
a simple web app
-
28.
Recap: Go is
Fast compilation time
Concurrent
Garbage-collected
Modern with support for networked and
multi-core computing
General-purpose
Compiled
Statically typed like C, Java
Feels as easy, lightweight as JS, Python
-
29.
What’s next
A Tour of Go tour.golang.org
The Go Playground play.golang.org
Documentation golang.org/doc
Go Wiki github.com/golang/go/wiki
https://golang.org/
Description: Go (又稱 Golang) 是 Google 在 2009 年推出的程式語言。go 以好讀、好寫、執行效率高為主打,也很適合拿來開發 web services。除了 Google 之外,許多公司,包括 Uber、Medium、Docker 等也使用 Go 來開發產品。究竟 Go 有什麼魅力?想知道更多,歡迎來參加這次的讀書會!
http://stackshare.io/go/in-stacks
A bit like C
To run it https://play.golang.org/p/eEZMXonMhA
main package: make this program executable (main function is the program entry point)
fmt: a package
Public vs. private
Succinct wording (not as verbose as Java… System.io.println)
Dependency made easy
https://golang.org/doc/code.html
To build & install the program (and its dependencies): $ go install path/to/dir
Then run the binary under $GOPATH/bin/<binary-name>
To test a program compiles: $ go build path/to/dir
To build, install, and run: $ go run path/to/file
Notice that the type comes after the variable name.
Why? https://blog.golang.org/gos-declaration-syntax
Go is statically typed, but type inference saves repetition.
A struct is a type which contains named fields
Go “objects” are just values. There is no “box”.
Attracted by an easy, reliable language that performs well.
Web app: Concurrency, http package, libraries around it
Docker: talking to OS (interface between OS and Go, syscall)
A simple web app demo