-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
685 lines (595 loc) · 18.2 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Learning to Write Go</title>
<meta name="description" content="Learning to Write Golang without Repeating My Mistakes"/>
<meta name="author" content="Jeffrey Hulten"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=no"/>
<link rel="stylesheet" href="css/reveal.css"/>
<link rel="stylesheet" href="css/theme/default.css" id="theme"/>
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css"/>
<link rel="stylesheet" href="font/roboto_regular_macroman/stylesheet.css"/>
<link href='http://fonts.googleapis.com/css?family=Oxygen:400,700' rel='stylesheet' type='text/css'>
<style>
.goplay { background-color: rgb(255, 255, 255); width: 900px; height: 550px; max-height: none; max-width: none; }
.reveal div { font-family: 'robotoregular', sans-serif; }
.reveal h1, .reveal h2, .reveal h3, .reveal h4, .reveal h5, .reveal h6 {font-family: 'Oxygen', sans-serif; font-weight: 700;}
.reveal dt { font-family:Inconsolata,Monospace; font-weight:900; text-align: left; float: left;}
.reveal dd { font-weight:normal; text-align: right;}
.reveal code { font-family: Courier,Monospace; text-transform:none; letter-spacing: 0; }
.reveal blockquote { box-shadow:none; }
.reveal pre { box-shadow:none; }
.reveal pre code { max-height: 750px; font-size: 36px; line-height: normal; }
.reveal section img { border:0px; box-shadow:none; line-height: 120%; }
</style>
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'css/print/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
}
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>Learning to Write Go</h1>
<img src="whitepages.png" alt="Whitepages Logo"/>
<h2>Jeffrey Hulten</h2>
</section>
<section>
<h2>Who Am I</h2>
<p style="font-weight: bold;">
Jeffrey Hulten
</p>
<p>Engineering Manager</p>
<p>Developer Tools</p>
<p>Whitepages, Inc.</p>
</section>
<section>
<h2>What I'm Going to Cover</h2>
<p>Assuming you know something like Python, Java, Ruby...</p>
<ol>
<li>Using Packages</li>
<li>Types, Structs, and Interfaces</li>
<li>The Goroutine</li>
<li>Channels</li>
</ol>
</section>
<section>
<h2>Not For You? Parting Hint...</h2>
<p>Google for "golang", not "go".<br>
<a href="http://lmgtfy.com/?q=golang">http://lmgtfy.com/?q=golang</a>
</p>
</section>
<section>
<h2>Simplicity</h2>
<p>
Rich Hickey - Creator of Clojure
</p>
<a href="http://www.infoq.com/presentations/Simple-Made-Easy">http://www.infoq.com/presentations/Simple-Made-Easy</a><br/>
<img src="richhickey.jpeg" alt="Photo of Rich Hickey"/><br/>
<blockquote cite="http://www.infoq.com/presentations/Simple-Made-Easy">
We program with <b>constructs</b>[...]<br/>
but we are in a business of <b>artifacts</b>.
</blockquote>
<p>Go is a language for concurrency</p>
</section>
<section>
<h2>
<span>Hello, Playground!</span>
</h2>
<p>
<a href="http://play.golang.org/">http://play.golang.org/</a>
</p>
<iframe src="http://play.golang.org/" class="goplay"></iframe>
</section>
<section>
<pre><code class="go" data-trim>
package main
import "fmt"
func main() {
fmt.Println("Hello, playground")
}
</code></pre>
<section style="top:50px;">
<h3>
Declare the package for this file
</h3>
</section>
<section style="top:50px;">
<h3>
Import the <code>fmt</code> package (stdlib)
</h3>
</section>
<section style="top:50px;">
<h3>
Declares the <code>main</code> function to execute
</h3>
</section>
<section style="top:50px;">
<h3>
Calls <code>Println</code> from the <code>fmt</code> package
</h3>
</section>
</section>
<section>
<section>
<h2>Using Packages</h2>
</section>
<section>
<h2>Standard Packages</h2>
<iframe src="http://play.golang.org/p/ybBDpLBnLd" class="goplay"></iframe>
</section>
<section>
<h2>External Packages</h2>
<pre>
<code class="go" data-trim>
package main
import (
"fmt"
"code.google.com/p/gcfg"
)
type Config struct {
Section struct {
Name string
Flag bool
}
}
func main() {
var cfg Config
err := gcfg.ReadFileInto(&cfg, "myconfig.gcfg")
fmt.Println("The name is", cfg.Name)
}
</code>
</pre>
</section>
<section>
<h2>Packaging Gimmies and Gotchas</h2>
<ul>
<li>Does not pin versions</li>
<li>Vendoring is recommended</li>
<li>Binaries are statically linked</li>
<li>NPM/Bundler is insufficent (Go is Different)</li>
</ul>
<p><a href="http://nathany.com/go-packages/">http://nathany.com/go-packages/</a>
</section>
<section>
<h2>Private vs Public</h2>
<pre><code class="go" data-trim>
package mypkg
func thisIsPrivate() {}
func ThisIsPublic() {}
</code>
</pre>
</section>
</section>
<section>
<section>
<h2>Types</h2>
<p>Golang is statically typed</p>
<pre>
<code class="go" data-trim>
var I int
var myString string = "my string"
fileReader, err := os.Open("/tmp/filename")
</code>
</pre>
<a href="http://golang.org/ref/spec#Variable_declarations">http://golang.org/ref/spec#Variable_declarations</a>
</section>
<section>
<h2>Structs</h2>
<pre>
<code class="go" data-trim>
type TinyStruct struct {
IsTiny bool
}
t1 := TinyStruct{}
t2 := TinyStruct{true}
t3 := TinyStruct{IsTiny: false}
t3.IsTiny
</code>
</pre>
<a href="http://golang.org/ref/spec#Struct_types">http://golang.org/ref/spec#Struct_types</a>
</section>
<section>
<h2>Structs</h2>
<pre>
<code class="go" data-trim>
type MyStruct struct {
TinyStruct
A string
b uint32
Nested struct {
C io.Reader
}
}
var ms MyStruct
ms = MyStruct{}
ms.A = "one"
ms.IsTiny = true
if ms.TinyStruct.IsTiny {...}
</code>
</pre>
</section>
<section>
<h2>Structs</h2>
<pre><code class="go" data-trim>
type OtherStruct struct {
MStruct MyStruct
OtherField string
}
os := OtherStruct{MStruct : MyStruct{IsTiny: false}, OtherField : "thing"}
</code></pre>
</section>
<section>
<h2>Functions</h2>
<pre>
<code class="go" data-trim>
func FunctionName(argument string, arg1, arg2 int64) {...}
func FunctionName(values ...int) error {...}
func FunctionName()(namedReturn int) {...}
var f := func() {...}
</code>
</pre>
<a href="http://golang.org/ref/spec#Function_declarations">http://golang.org/ref/spec#Function_declarations</a>
</section>
<section>
<h2>Interfaces and Methods</h2>
<pre><code class="go" data-trim>
type Thinger interface {
DoThing() error
}
func (ms MyStruct)DoThing() error {
return nil
}
func (os *OtherStruct)DoThing() error {
return nil
}
func ProcessThinger(t Thinger) error {
return t.DoThing()
}
</code></pre>
<a href="http://golang.org/ref/spec#Interface_types">http://golang.org/ref/spec#Interface_types</a><br/>
<a href="http://golang.org/ref/spec#Method_declarations">http://golang.org/ref/spec#Method_declarations</a>
</section>
<section>
<h2>Empty Interface is an Any Type</h2>
<iframe src="http://play.golang.org/p/_qxA85gNjW" class="goplay"></iframe>
</section>
</section>
<section>
<section>
<h2>Goroutines</h2>
</section>
<section>
<h2>Sidenote: Concurrency vs Parallelism</h2>
<div>
<blockquote cite="http://blog.golang.org/concurrency-is-not-parallelism">
Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once.
</blockquote>
<cite>-- Andrew Gerrand</cite>
</div>
<p> More Information: Rob Pike on Concurrency vs Parallelism<br/>
<a href="http://vimeo.com/49718712">http://vimeo.com/49718712</a></p>
<aside class="notes">
Pike is one of the three co-creators of GoLang
</aside>
</section>
<section>
<h2>How to Create a Goroutine</h2>
<iframe src="http://play.golang.org/p/g2Z-BR6838" class="goplay"></iframe>
</section>
<section>
<h2>Call a standard function</h2>
<pre>
<code>go time.Sleep(100 * time.Hour)</code>
</pre>
</section>
<section>
<h2>Call a function variable</h2>
<pre><code class="go" data-trim>
f := func() {time.Sleep(100 * time.Hour)}
go f()
</code></pre>
</section>
<section>
<h2>Call an anonymous function</h2>
<pre>
<code class="go" data-trim>
go func() {time.Sleep(100 * time.Hours())}()
</code>
</pre>
</section>
<section>
<h2>Goroutine Gotchas</h2>
<ul>
<li>Goroutines do not block the main thread from exiting.</li>
<li>You must manage concurrent access. See <a href="http://golang.org/pkg/sync/#Mutex"><code>sync.Mutex</code></a></li>
<li>There is no one to return a value to. (Use channels.)</li>
</ul>
</section>
</section>
<section>
<section>
<h2>Channels</h2>
<ul>
<li>A type.</li>
<li>A strongly typed, bounded queue for passing data between goroutines.</li>
<li>Argument types can include direction (inbound vs. outbound).</li>
</ul>
<p>
<a href="http://blog.golang.org/pipelines">http://blog.golang.org/pipelines</a>
</p>
</section>
<section>
<h2>Make a Channel</h2>
<pre><code class="go" data-trim>
var ch chan int
ch = make(chan int)
</code></pre>
</section>
<section>
<h2>Size a Channel</h2>
<pre><code class="go" data-trim>
ch := make(chan int, 10)
</code></pre>
</section>
<section>
<h2>Send To a Channel</h2>
<pre><code class="go" data-trim>
ch := make(chan int, 1)
ch <- 1
ch <- 2
</code></pre>
</section>
<section>
<h2>Recieve From a Channel</h2>
<pre><code class="go" data-trim>
c := <-ch
</code></pre>
</section>
<section>
<h2>Recieve From a Channel with <code>range</code></h2>
<pre><code class="go" data-trim>
ch := make(chan int, 10)
ch <- 1
ch <- 2
ch <- 3
ch <- 4
for n := range ch {
fmt.Println(n * n)
}
</code></pre>
</section>
<section>
<h2>Recieve From a Channel with <code>select</code></h2>
<pre><code class="go" data-trim>
ch := make(chan int, 10)
done := make(chan bool)
ch <- 1
ch <- 2
done <- true
ch <- 4
select {
case <-done:
return
case n <- ch:
fmt.Println(n * n)
}
</code></pre>
</section>
<section>
<h2>Return a Channel</h2>
<pre><code class="go" data-trim>
func generate(nums ...int) <-chan int {
out := make(chan int)
go func() {
for _, n := range nums {
out <- n
}
close(out)
}()
return out
}
</code></pre>
</section>
<section>
<h2>Pass a Channel</h2>
<pre><code class="go" data-trim>
func sq(in <-chan int) <-chan int {
out := make(chan int)
go func() {
for n := range in {
out <- n * n
}
close(out)
}()
return out
}
</code></pre>
</section>
<section>
<h2>A Pipeline of Channels</h2>
<pre><code class="go" data-trim>
func square(in <-chan int) <-chan int {}
func generate(nums ...int) <-chan int {}
func main() {
for n := range square( square( generate( 2, 3, 4 ))) {
fmt.Println(n)
}
}
</code></pre>
</section>
</section>
<section>
<section>
<h2>Common Toolchain, Common Practices</h2>
<div>
<ul>
<li><code>go clean</code></li>
<li><code>go get</code></li>
<li><code>go fmt</code></li>
<li><code>go test</code></li>
<li><code>go build</code></li>
</ul>
</div>
</section>
<section>
<h2><code>go clean</code></h2>
<ul>
<li>Removes object files from package source directories.</li>
</ul>
<pre><code data-trim>
go clean [packages]
go clean github.com/goraft/raft
</code></pre>
</section>
<section>
<h2><code>go get</code></h2>
<ul>
<li>Downloads and installs packages and their dependencies.</li>
</ul>
<pre><code data-trim>
go get [-u] [packages]
go get code.google.com/p/gcfg
go get -u github.com/goraft/raft
</code></pre>
</section>
<section>
<h2><code>go fmt</code></h2>
<ul>
<li>Reformats the packages listed to the golang standard.</li>
<li>Many editors run <code>go fmt</code> on save.</li>
</ul>
<pre><code data-trim>
go fmt [-n] [-x] [packages]
</code></pre>
</section>
<section>
<h2><code>go build</code></h2>
<ul>
<li>Compiles the packages named by the import paths, along with their dependencies.</li>
<li>Does not install the resulting binaries.</li>
</ul>
<pre><code data-trim>
go build [-o output] [build flags] [packages]
go build ./...
</code></pre>
</section>
<section>
<h2><code>go test</code></h2>
<ul>
<li>Recompiles each package along with any files with names matching <code>*_test.go</code>.
<pre><code data-trim>
go test [-c] [-i] [build/test flags] [packages] [flags for test binary]
go test ./...
go test github.com/goraft/raft
</code></pre></li>
<li>Prints a summary of test results.
<pre>
<code data-trim>
ok archive/tar 0.011s
FAIL archive/zip 0.022s
ok compress/gzip 0.033s
...
</code>
</pre>
</li>
<li>Can contain test functions, benchmark functions, and example functions.</li>
</ul>
<p><a href="http://golang.org/pkg/testing/">http://golang.org/pkg/testing/</a>
</section>
<section>
<h2><code>go install</code></h2>
<ul>
<li>Compiles and installs packages and their dependencies.</li>
</ul>
<pre><code data-trim>
go install [build flags] [packages]
go install github.com/crosbymichael/skydock
</code></pre>
</section>
</section>
<section>
<h2>Top Three Hints</h2>
<ol>
<li class="fragment" data-fragment-index="0">Don't think in traditional objects. Add behavior (interfaces) instead.</li>
<li class="fragment" data-fragment-index="1">Try the standard library first.<br>Especially "<a href="http://golang.org/pkg/net/http/">net/http</a>".</li>
<li class="fragment" data-fragment-index="2">Learn to love channels.</li>
</ol>
</section>
<section>
<h2>Resources</h2>
<ul>
<li><a href="http://golang.org/doc/effective_go.html">http://golang.org/doc/effective_go.html</a></li>
<li><a href="http://golang.org/ref/spec">http://golang.org/ref/spec</a></li>
<li><a href="http://blog.golang.org/">http://blog.golang.org/</a></li>
<li><a href="http://www.reddit.com/r/golang">http://www.reddit.com/r/golang</a></li>
<li><a href="http://golang.org/doc/faq">http://golang.org/doc/faq</a></li>
<li><a href="https://groups.google.com/forum/#!forum/Golang-nuts">https://groups.google.com/forum/#!forum/Golang-nuts</a></li>
</ul>
</section>
<section>
<h2>Questions?</h2>
<p>jhulten@whitepages.com</p>
<p>twitter: @jhulten</p>
</section>
<section>
<h2>We are hiring!</h2>
<p>
<img src="whitepages.png" alt="Whitepages Logo"/>
</p><p>
<a href="http://jobvite.com/m?38ZeLgwR">http://jobvite.com/m?38ZeLgwR</a>
</p>
<p>
<img src="qrcode.png" alt="QR Code to Hiring Link"/>
</p>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
width: 1800,
height: 1000,
// Bounds for smallest/largest possible scale to apply to content
minScale: 0.2,
maxScale: 1.0,
theme: Reveal.getQueryHash().theme || 'solarized', // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none
// Parallax scrolling
// parallaxBackgroundImage: 'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg',
// parallaxBackgroundSize: '2100px 900px',
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>