-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
260 lines (213 loc) · 10.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!DOCTYPE html><html lang="en"><head><title>Golang</title><meta charset="utf-8"><meta http-equiv="x-ua-compatible" content="ie=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="bower_components/reveal-js/css/reveal.min.css"><link rel="stylesheet" href="bower_components/reveal-js/css/theme/moon.css"><link rel="stylesheet" href="bower_components/github-fork-ribbon-css/gh-fork-ribbon.css"><link rel="stylesheet" href="bower_components/highlightjs/styles/default.css"><link rel="stylesheet" href="src/styles/theme.css"><link rel="stylesheet" href="src/styles/common.css"><style>.reveal section img {
background: none;
border: none;
box-shadow: none;
max-height: 35vh;
padding: 20px;
}
.split {
display: flex;
}
.split .left, .split .right {
flex-grow: 1;
}
.reveal section .filename {
margin-bottom: 5px;
font-style: italic
}
.reveal section sup {
font-size: 0.7em;
}
.reveal section pre {
margin-left: 1%;
margin-right: 1%;
width: 98%;
}
.reveal pre code {
max-height: none;
}
.float-left {
float: left;
}
.float-right {
float: right;
}</style></head><body><a href="https://github.com/purplecode/lightning-talk-golang" title="Fork me on Github" class="github-fork-ribbon right-top"></a><div class="reveal"><div class="slides"><section><h1>Go Programming Language</h1><h3>Introduction</h3></section><section><img src="src/images/logo.png"><br><a href="https://blog.golang.org/gopher">https://blog.golang.org/gopher</a></section><section><style>#modules {
max-height: 60vh;
height: 60vh;
}</style><img id="modules" src="src/images/modules.png"><small>@source: <a href="http://www.modulecounts.com/">www.modulecounts.com</a></small></section><section><h2>Go (Golang)</h2><ul><li>open source programming language</li><li>created at Google (2007, Robert Griesemer, Rob Pike, and Ken Thompson)</li><li>compiled, statically typed</li><li>garbage collection, structural typing</li><li>CSP-style<sup>*</sup> concurrent programming features</li></ul><br><br><small class="float-left">* communicating sequential processes</small></section><section><h2>Naming dispute</h2><a href="https://en.wikipedia.org/wiki/Go_(programming_language)#Naming_dispute">Go </a>vs <a href="https://en.wikipedia.org/wiki/Go!_(programming_language)">Go!</a></section><section><h2>Hello World</h2><pre><code class="hljs go">package main
import "fmt"
func main() {
fmt.Println("Hello, World")
}
</code></pre></section><section><h2>Tooling</h2><ul><li>go get - simple package manager</li><li>go test</li><li>go build</li><li>go clean</li><li>go run</li><li>gofmt - formatter</li><li>golint - linter</li><li>godoc - documentation</li><li>go vet - static analyzer</li></ul></section><section><h2>Pros & Sugar</h2><ul><li>fast compilation time</li><li>garbage collection</li><li>initialization through type inference (x := 0 not int x = 0;)</li><li>built-in concurrency primitives: light-weight processes (goroutines), channels, and the select statement</li><li>multiple return values, (result, err) pair as convention</li></ul></section><section><h2>Cons*</h2><ul><li>lack of mature libraries</li><li>no compile-time generics (code duplication)</li><li>no language extensibility (like operator overloading)</li><li>overhead of garbage collection</li><li>no inheritance</li><li>no assertions</li><li>no pointer arithmetic</li><li>no implicit type conversions (by compiler)</li></ul></section><section><h2>Companies using</h2><br><div class="split"><div class="left"><ul><li>Docker</li><li>Ethereum</li><li>Google</li><li>Dropbox</li><li>CloudFlare</li><li>SoundCloud</li></ul></div><div class="right"><ul><li>Cloud Foundry</li><li>CoreOS</li><li>Couchbase</li><li>MongoDB</li><li>Uber</li></ul></div></div><br><br><small>@source: <a href="https://en.wikipedia.org/wiki/Go_(programming_language)">https://en.wikipedia.org/wiki/Go_(programming_language)</a></small></section><section><h2>Types</h2><br><div class="split"><div class="left"><ul><li>byte, int64, float32, etc.</li><li>boolean</li><li>string (immutable)</li><li>arrays</li><li>hash tables</li></ul></div><div class="right"><ul><li>channels</li><li>pointers</li><li> custom types (struct)<pre><code class="hljs go">type Circle struct {
radius float64
}
type ipv4addr uint32
</code></pre></li></ul></div></div></section><section><h2>Functions</h2><pre><code class="hljs go">func addFactory(valueToAdd int) func(int) {
return func(value int) {
fmt.Println("%d + %d = %d", value, valueToAdd, value + valueToAdd)
return value + valueToAdd
}
}
</code></pre></section><section><h2>Interfaces</h2><div class="split"><div class="left"><pre><code class="hljs go">type geometry interface {
area() float64
}
type rect struct {
width, height float64
}
type circle struct {
radius float64
}
func (r rect) area() float64 {
return r.width * r.height
}
func (c circle) area() float64 {
return math.Pi * c.radius * c.radius
}</code></pre></div><div class="right"><pre><code class="hljs go">func measure(g geometry) {
fmt.Println(g.area())
}
func main() {
r := rect{width: 3, height: 4}
c := circle{radius: 5}
measure(r)
measure(c)
}
</code></pre></div></div></section><section><h2>Composition</h2><pre><code class="hljs go">type Person struct {
name string
age int
}
func (p Person ) hello() {
fmt.Printf("Hi, I am %s. I am %d.\n", p.name, p.age)
}
type PersonWithPhone struct {
Person
number int
}
func main() {
a := Person{name: "Alice", age: 12}
a.hello()
b := PersonWithPhone{Person{"Bob", 15}, 123456}
b.age += 10
b.hello()
}
</code></pre></section><section><h2>Concurrency: goroutines</h2><ul><li>primary concurrency construct, a type of light-weight process</li><li>language specification does not specify how goroutines should be implemented</li><li>like threads, but cheaper (smaller stacks)</li><li>current implementations: multiplex goroutines onto a smaller set of operating system threads</li></ul></section><section><h2>Concurrency: channels</h2><pre><code class="hljs go">func fibonacci(c, quit chan int) {
x, y := 0, 1
for {
select {
case c <- x:
x, y = y, x+y
case <-quit:
fmt.Println("quit")
return
}
}
}
func main() {
c := make(chan int)
quit := make(chan int)
go func() {
for i := 0; i < 10; i++ {
fmt.Println(<-c)
}
quit <- 0
}()
fibonacci(c, quit)
}</code></pre><small>@source: <a href="https://tour.golang.org/concurrency/6">https://tour.golang.org/concurrency/6</a></small></section><section><h2>Defer</h2><pre><code class="hljs go">func CopyFile(dstName, srcName string) (written int64, err error) {
src, err := os.Open(srcName)
if err != nil {
return
}
defer src.Close()
dst, err := os.Create(dstName)
if err != nil {
return
}
defer dst.Close()
return io.Copy(dst, src)
}</code></pre><small>@source: <a href="https://blog.golang.org/defer-panic-and-recover">https://blog.golang.org/defer-panic-and-recover</a></small></section><section><h2>Defer</h2><pre><code class="hljs go">func a() {
i := 0
defer fmt.Println(i)
i++
return
} // 0</code></pre><pre><code class="hljs go">func b() {
for i := 0; i < 4; i++ {
defer fmt.Print(i)
}
} // "3210":</code></pre><pre><code class="hljs go">func c() (i int) {
defer func() {
i++
}()
return 1
} // 2</code></pre><small>@source: <a href="https://blog.golang.org/defer-panic-and-recover">https://blog.golang.org/defer-panic-and-recover</a></small></section><section><h2>Panic & recover</h2><div class="split"><pre class="left"><code class="hljs go">func main() {
f()
fmt.Println("Returned normally from f.")
}
func f() {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered in f", r)
}
}()
fmt.Println("Calling g.")
g(0)
fmt.Println("Returned normally from g.")
}
func g(i int) {
if i > 3 {
fmt.Println("Panicking!")
panic(fmt.Sprintf("%v", i))
}
defer fmt.Println("Defer in g", i)
fmt.Println("Printing in g", i)
g(i + 1)
}</code></pre><pre class="right"><code class="hljs go">Calling g.
Printing in g 0
Printing in g 1
Printing in g 2
Printing in g 3
Panicking!
Defer in g 3
Defer in g 2
Defer in g 1
Defer in g 0
Recovered in f 4
Returned normally from f.
</code></pre></div><small>@source: <a href="https://blog.golang.org/defer-panic-and-recover">https://blog.golang.org/defer-panic-and-recover</a></small></section><section><h2>Packages</h2><ul><li>each package has a path ("compress/bzip2", "golang.org/x/net/html") and a name (e.g., bzip2 or html)</li><li>references to other packages' must always be prefixed with the other package's name</li><li>package exposes only the capitalized names (io.Reader is public, bzip2.reader is not)</li><li>package paths often look like partial GitHub urls for compatibility (github.com/gorilla/mux)</li></ul></section><section><h2>Project structure</h2><pre><code class="hljs">export GOPATH=$HOME/work
export PATH=$PATH:$GOPATH/bin
bin/
hello # command executable
pkg/
linux_amd64/
github.com/golang/example/
stringutil.a # package object
src/
github.com/golang/example/
.git/ # repository metadata
hello/
hello.go # command source
stringutil/
reverse.go # package source
reverse_test.go # test source
</code></pre></section><section><h2>Go package management</h2><br><ol><li>Repeatable builds</li><li>Isolated environments</li><li>Community consensus</li></ol><br><br><a href="https://github.com/golang/go/wiki/PackageManagementTools">https://github.com/golang/go/wiki/PackageManagementTools</a><br><a href="http://jbeckwith.com/2015/05/29/dependency-management-go/">http://jbeckwith.com/2015/05/29/dependency-management-go/</a></section><section><h2>Testing</h2><pre><code class="hljs go">func TestTimeConsuming(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
//
t.Fail()
//
t.Error("I'm in a bad mood.")
}
</code></pre></section><section><h2>Live demo</h2><br><a href="https://github.com/docker/docker">https://github.com/docker/docker</a></section><section><h2>This is all for now...</h2></section><section><h2>Thanks!</h2></section></div></div><script src="bower_components/reveal-js/lib/js/head.min.js"></script><script src="bower_components/reveal-js/js/reveal.js"></script><script>Reveal.initialize({
progress: true,
slideNumber: false,
history: true,
dependencies: [
{
src: 'bower_components/highlightjs/highlight.pack.min.js',
async: true,
callback: function () {
hljs.initHighlightingOnLoad();
}
}
]
});</script></body></html>