-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
395 lines (365 loc) · 10.7 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Let's (learn) Go</title>
<meta name="description" content="Introducing the go programming language aka golang">
<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=1.0, user-scalable=no">
<link rel="stylesheet" href="res/css/reveal.min.css">
<link rel="stylesheet" href="res/css/theme/night.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="res/lib/css/zenburn.css">
<!--[if lt IE 9]>
<script src="res/lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body class="reveal tileflip">
<div class="reveal">
<div class="slides">
<section>
<h1>Let's (learn) Go</h1>
<a href="http://www.flickr.com/photos/yukop/6779040884/"><img src="images/go_coffe.jpg" alt="go coffe" title="Go Logo"></a><br>
<a href="http://creativecommons.org/licenses/by-sa/3.0/"><img src="images/cc-by-sa-88x31.png" alt="cc-by"></a>
</section>
<section>
<section>
<h1>What is Go... ?</h1>
<a href="https://en.wikipedia.org/wiki/File:Citizen_G%27kar.JPG"><img src="images/gkar.jpg" alt="G'kar"></a>
<br>
<small>Andreas Katsulas R.I.P</small>
</section>
<section>
<ul>
<li>Statically compiled programming language</li>
<li>Cross Platform</li>
<li>Strong type language</li>
<li>Garbage collection based</li>
<li>Objected Oriented like, using Struct Properties</li>
<li>Support Concurrent computing development</li>
<li>Influenced by many programming languages such as C ...</li>
<li class="fragment">... and <strong>Pascal</strong><br><img src="images/elephant_in_room_800_clr_6740.png" alt="elephant in a room"></li>
</ul>
</section>
<section>
<h1>Ah yes</h1>
<h1>But what is the ...</h1>
<h1>and what is Go ?</h1>
</section>
</section>
<section>
<section>
<h2>Basic Code</h2>
<pre><code data-trim class="go">
// We use packages to make order
package main
// We can import libraries
import (
// Using fmt for print commands
"fmt"
)
// Main function ...
func main() {
// External functions starts with capital letter
fmt.Println("Hello, World")
}
</code></pre>
<br><h2>Output</h2>
<pre><code data-trim class="bash">
$ go build hello.go
$ ./hello
Hello, World
$
</code></pre>
</section>
<section>
<h2>Variables</h2>
<pre><code data-trim class="go">
// predefine variables
var (
var1 int
var2, var3 string
)
var1 = SomeFunction()
// variable on usage
var4 := SomeFunction()
// array -> predefined as 0
arr := [10]int{}
// array with values
arr2 := [2]string{"go", "lang"}
// compiler compute
fibonacci := [...]int{1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144}
</code></pre>
<pre><code data-trim class="go">
// slices are cool
scifi := []string{"babylon 5", "star trek", "doctor who"}
// maps (hash/associative array)
doctor_colors := map[string]string{"rose" : "blonde", "tardis" : "blue", "pond" : "ginger"}
// multiple value
answer, err := funcWithError()
// Ignore the error return
answer, _ = functionWithError()
</code></pre>
</section>
<section>
<h2>Functions</h2>
<pre><code data-trim class="go">
import (
"errors"
"fmt"
)
func helloWorld() {
fmt.Println("Hello World")
}
func LifeUniverseAndEverything() int {
return 42
}
func GuessAge(age int) (bool, error) {
if age < 0 { return false, errors.New("Age is lower then 0") }
if age == 100 { return true, nil }
return false, nil
}
</pre></code>
<pre><code data-trim class="go">
func main() {
fmt.Println(GuessAge(42))
fmt.Println(GuessAge(100))
fmt.Println(GuessAge(-1))
}</code></pre>
Output:
<pre><code data-trim>
false <nil>
true <nil>
false Age is lower then 0
</code></pre>
</section>
<section>
<h2>Types</h2>
<pre><code data-trim class="go">
// alias
type Weight float64
// Method (The OOP style of Go)
func (w Weight) String() string {
return fmt.Sprintf("%.2f kg", float64(w))
}
func main() {
var w Weight = 42.15
fmt.Println(w.String())
}
</code></pre>
Output:
<pre><code data-trim>
42.15 kg
</code></pre>
</section>
<section>
<h2>Struct</h2>
<pre><code data-trim class="go">
type TV_Show struct {
name string // Show name
genre string // Show genre
channel int // Channel on TV
air int64 // timestamp when it will be aired
rerun bool // is it a re-run ?
season string // number of season
episode string // number of episode
}
</code></pre>
</section>
<section>
<h2>Unofficial OOP</h2>
<pre><code data-trim class="go">
// type TV_Show struct ...
func (show TV_Show) Show() string {
return fmt.Sprintf("%s - S(%s) E(%s)", show.name, show.season, show.episode)
}
func main() {
var show TV_Show
show.name = "Star Trek - Creation of Data"
show.episode = "1b"
show.season = "Pilot"
fmt.Println(show.Show())
}
</code></pre>
Output:
<pre><code data-trim class="no-highlight">
Star Trek - The next generation - S(Pilot) E(1b)
</code></pre>
</section>
</section>
<section>
<h1>Basic Flows</h1>
<a href="http://commons.wikimedia.org/wiki/File:Water_flows_over_dam_on_the_Waren_Burn_at_Twizell_Mill_-_geograph.org.uk_-_780768.jpg"><img src="images/flows.jpg" alt="water flow"></a>
</section>
<section>
<section>
<h2>Parallel and Concurrency </h2>
<br>
<ul>
<li class="fragment">Setting code to execute in parallel, without touching threads or processes</li>
<li class="fragment">Create more then one execution at "the same time"</li>
<li class="fragment">Wait for tasks if needed</li>
<li class="fragment">Measure tasks execution time</li>
</ul>
<br><br><br>
<span class="fragment"><strong>go</strong> with <strong>channels</strong>
<br><br>
<a href="http://commons.wikimedia.org/wiki/File:Generic-remote-control-shallow-focus.jpg"><img src="images/remote_control.jpg" alt="remote control"></a>
</span>
</section>
<section>
<h2>Concurrency</h2>
<pre><code data-trim class="go">
package main
import (
"fmt"
"time"
)
func say(s string) {
for i := 0; i < 5; i++ {
time.Sleep(100 * time.Millisecond)
fmt.Println(s)
}
}
func main() {
go say("world")
say("hello")
}
</code></pre>
Output:
<pre><code data-trim class="no-highlight">
hello
world
hello
world
hello
world
hello
world
hello
</code></pre>
</section>
<section>
<h2>Channels</h2>
<pre><code data-trim class="go">
package main
import "fmt"
func sum(a []int, c chan int) {
sum := 0
for _, v := range a {
sum += v
}
c <- sum // send sum to c
}
func main() {
a := []int{7, 2, 8, -9, 4, 0}
c := make(chan int)
go sum(a[:len(a)/2], c)
go sum(a[len(a)/2:], c)
x, y := <-c, <-c // receive from c
fmt.Println(x, y, x+y)
}
</code></pre>
Output:
<pre><code data-trim class="no-highlight">
17 -5 12
</code></pre>
</section>
<section>
<h2>Buffered Channels</h2>
<pre><code data-trim class="go">
package main
import "fmt"
func main() {
c := make(chan int, 2)
c <- 1
c <- 2
fmt.Println(<-c)
fmt.Println(<-c)
}
</code></pre>
Output:
<pre><code data-trim class="no-highlight">
1
2
</code></pre>
</section>
<section>
<strong>Waiting on channels</strong>
<pre><code data-trim class="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
}
}
}
</code></pre>
<pre><code data-trim class="go">
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>
<pre><code data-trim class="no-highlight">
0
1
1
2
3
5
8
13
21
34
quit
</code></pre>
</section>
</section>
<section>
<section>
<h2>Anyone still alive here ?</h2>
<a href="http://commons.wikimedia.org/wiki/File:Pictofigo_-_Idea.png">
<img src="images/idea.png" alt="idea"></a>
</section>
</section>
</div>
</div>
<script src="res/lib/js/head.min.js"></script>
<script src="res/js/reveal.min.js"></script>
<script>
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'res/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'res/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'res/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'res/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'res/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'res/plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
// { src: 'res/plugin/search/search.js', async: true, condition: function() { return !!document.body.classList; } }
// { src: 'res/plugin/remotes/remotes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>