summaryrefslogtreecommitdiff
path: root/erlang.html
blob: d3632743166e580c9f2c4aea0414f8d8a636fb0a (plain)
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
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="generator" content="pandoc">
  <meta name="author" content="Guido Günther">
  <meta name="dcterms.date" content="2016-05-09">
  <title>Wissenswertes über Erlang</title>
  <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, minimal-ui">
  <link rel="stylesheet" href="reveal.js/css/reveal.css"/>
  <style type="text/css">code{white-space: pre;}</style>
  <link rel="stylesheet" href="reveal.js/css/theme/black.css" id="theme">
  <!-- Printing and PDF exports -->
  <script>
    var link = document.createElement( 'link' );
    link.rel = 'stylesheet';
    link.type = 'text/css';
    link.href = window.location.search.match( /print-pdf/gi ) ? 'reveal.js/css/print/pdf.css' : 'reveal.js/css/print/paper.css';
    document.getElementsByTagName( 'head' )[0].appendChild( link );
  </script>
  <!--[if lt IE 9]>
  <script src="reveal.js/lib/js/html5shiv.js"></script>
  <![endif]-->
</head>
<body>
  <div class="reveal">
    <div class="slides">

<section>
    <h1 class="title">Wissenswertes über Erlang</h1>
    <h2 class="author">Guido Günther</h2>
    <h3 class="date">2016-05-09</h3>
</section>

<section id="who-am-i" class="slide level1">
<h1>Who am I</h1>
<ul>
<li>Free Software Hacker (Freelancing Software Developer)</li>
<li>Debian Developer since 2000</li>
<li>Contributed to libvirt-*, X11, Linux Kernel, GNOME, Calypso, …</li>
<li>FSFE Fellow and GNOME Foundation member</li>
<li>Rather new to Erlang</li>
</ul>
</section>
<section id="erl-what" class="slide level1">
<h1>Erl-what?</h1>
<ul>
<li>Developed at Ericsson in 1986</li>
<li>Open sourced 1998</li>
<li>Ericsson Language or Agner Krarup Erlang?</li>
<li><p>For telephone systems</p></li>
<li>Functional, concurrent programming language</li>
<li>Garbage collected runtime system</li>
<li><p>Erlang/OTP</p></li>
</ul>
</section>
<section id="erlang-features" class="slide level1">
<h1>Erlang, Features</h1>
<ul>
<li>Fault tolerant</li>
<li>Hot code replacements</li>
<li>Distributed</li>
<li>highly available - 12 years of uptime - nine 9s (30 ms / a)</li>
</ul>
</section>
<section id="projects" class="slide level1">
<h1>Projects</h1>
<ul>
<li>ejabberd, Riak, CouchDB, RabbitMQ</li>
<li>WhatsApp, GitHub, Facebook, …</li>
</ul>
</section>
<section id="you-lack-style---no-state" class="slide level1">
<h1>You lack style - no, state!</h1>
</section>
<section class="slide level1">

<h2 id="functional-language">Functional language</h2>
<p>f(x) = y</p>
</section>
<section class="slide level1">

<p>i = i + 3</p>
</section>
<section class="slide level1">

<p><del>i = i + 3</del></p>
</section>
<section class="slide level1">

<p>for (int i=0; i &lt; 3; i++) do_something(i);</p>
</section>
<section class="slide level1">

<p><del>for (int i=0; i &lt; 3; i++) do_something(i);</del></p>
</section>
<section class="slide level1">

<pre><code>1&gt; A=3.
3
2&gt; A=4.
** exception error: no match of right hand side value 4</code></pre>
</section>
<section class="slide level1">

<h2 id="no-means-no">No means No</h2>
<ul>
<li>No imperative programming</li>
<li>No global variables and state</li>
<li>No pointers</li>
<li>No variable reassignments</li>
</ul>
</section>
<section class="slide level1">

<ul>
<li>Yes, Higher Order Functions</li>
<li>Yes, Pattern Matching</li>
<li>Yes, Code Reloads</li>
<li>Yes, Lots of independent Processes</li>
</ul>
</section>
<section class="slide level1">

<h2 id="recursion-to-the-rescue">Recursion to the Rescue</h2>
<pre><code>loop(X) -&gt; loop(X, 0).

loop(X=0, Sum) -&gt; Sum;
loop(X, Sum)   -&gt; loop(X-1, Sum+X).</code></pre>
</section>
<section class="slide level1">

<h2 id="recursion-in-detail">Recursion in Detail</h2>
<pre><code>loop(3)   -&gt; loop(3, 0)
loop(3,0) -&gt; loop(3-1, 0+3)
loop(2,3) -&gt; loop(2-1, 3+2)
loop(1,5) -&gt; loop(1-1, 5+1)
loop(0,6) -&gt; 6

3 + 2 + 1 = 6</code></pre>
</section>
<section class="slide level1">

<h2 id="head-to-wall-tail">Head to <del>Wall</del> Tail</h2>
<pre><code>A = [this, is, a, list].
[H|T] = A.</code></pre>
</section>
<section class="slide level1">

<pre><code>rev(L) -&gt; rev(L, []).

rev([],    N) -&gt; N;
rev([H|T], N) -&gt; rev(T, [H] ++ N).</code></pre>
</section>
<section class="slide level1">

<pre><code>rev([a,b,c,d])       -&gt; rev([a,b,c,d],      [])

rev([a|[b,c,d]], []) -&gt; rev([b,c,d], [a] ++ [])

rev([b|[c,d]],  [a]) -&gt; rev([c,d],  [b] ++ [a])

rev([c|[d]],  [b,a]) -&gt; rev([d],  [c] ++ [b,a])

rev([d|[],  [c,b,a]) -&gt; rev([], [d] ++ [c,b,a])

rev([],   [d,c,b,a]) -&gt; [d,c,b,a]</code></pre>
</section>
<section class="slide level1">

<h2 id="more-pattern-matching">More pattern matching</h2>
<pre><code>A = {this, is, a, tuple}.
{_, _, _, B} = A.</code></pre>
</section>
<section class="slide level1">

<pre><code>&gt; B.
tuple
&gt; _.
* 1: variable &#39;_&#39; is unbound</code></pre>
</section>
<section class="slide level1">

<h3 id="fun-with-funs">Fun with Funs</h3>
<pre><code>F = fun (X) -&gt; X*X end.
&gt; F(3).
&gt; F(ok).</code></pre>
</section>
<section class="slide level1">

<pre><code>&gt; F(3). 
9
&gt; F(ok).
** exception error: an error occurred when evaluating an arithmetic expression
     in operator  */2
       called as ok * ok</code></pre>
</section>
<section class="slide level1">

<h2 id="success-typing">Success, Typing!</h2>
<p>Dialyzer</p>
<pre><code>-spec foobar(atom()) -&gt; [atom()].
foobar(App) -&gt; …</code></pre>
</section>
<section id="processes-which-processes" class="slide level1">
<h1>Processes, which Processes</h1>
</section>
<section class="slide level1">

<h2 id="spawning-a-process">Spawning a process</h2>
<pre><code>F = fun(X) -&gt; io:format(&quot;~p~n&quot;, [X]) end.
times(X, Args, C) -&gt; ...

spawn(l, times, [F,  &quot;I&#39;m a process&quot;, 3]).</code></pre>
</section>
<section class="slide level1">

<pre><code>spawn(l, times, [F,  &quot;I&#39;m a process&quot;, 3]),
spawn(l, times, [F, &quot;I&#39;m a process too&quot;, 3]).</code></pre>
</section>
<section class="slide level1">

<h2 id="concurrency-for-free">Concurrency for free!</h2>
<pre><code>&quot;I&#39;m a process&quot;
&quot;I&#39;m a process too&quot;
&quot;I&#39;m a process&quot;
&quot;I&#39;m a process too&quot;
&lt;0.53.0&gt;
&quot;I&#39;m a process&quot;
&quot;I&#39;m a process too&quot;</code></pre>
</section>
<section class="slide level1">

<h2 id="shared-nothing">Share(d) nothing</h2>
<pre><code>start_pong(Pid) -&gt; …
pong(Pid) -&gt; …

&gt; P = l:start_pong(self()).
&gt; P ! { ping, &quot;foo&quot; }.
&gt; P ! giveup.</code></pre>
</section>
<section class="slide level1">

<pre><code>&gt; R = fun () -&gt; receive M -&gt; M end end.</code></pre>
</section>
<section class="slide level1">

<pre><code>&gt; R().
{pong,&quot;hallo1&quot;}
&gt; R().
{pong,&quot;hallo2&quot;}</code></pre>
</section>
<section class="slide level1">

<h2 id="let-it-crash">Let it crash</h2>
<pre><code>2&gt; P ! {ping, 3}.
{ping,3}
3&gt; 
=ERROR REPORT==== 8-May-2016::15:13:30 ===
Error in process &lt;0.34.0&gt; with exit value:
{badarg,[{io,format,[&lt;0.25.0&gt;,&quot;pong: Received ping &#39;~s&#39;~n&quot;,[3]],[]},
         {l,pong,1,[{file,&quot;l.erl&quot;},{line,57}]}]}</code></pre>
</section>
<section class="slide level1">

<pre><code>2&gt; P ! whatever
Unknwown message asfasdf, giving up</code></pre>
</section>
<section class="slide level1">

<h2 id="linking-processes">Linking processes</h2>
<pre><code>&gt; process_flag(trap_exit, true).
&gt; P = l:start_pong2(self()).
3&gt; P ! sadfsadf.
Unknwown message sadfsadf, giving upsadfsadf
4&gt; receive X -&gt; X end.
{&#39;EXIT&#39;,&lt;0.35.0&gt;,reason}</code></pre>
</section>
<section class="slide level1">

<h2 id="distributed-nodes">Distributed nodes</h2>
<pre><code>$ erl -sname ping
$ erl -sname pong

register(spawn(...))</code></pre>
</section>
<section class="slide level1">

<p>On pong</p>
<pre><code>&gt; P = l:start_pong3().</code></pre>
<p>On ping</p>
<pre><code>&gt; {pong, pong@bogon} ! {ping, &quot;hello&quot;, self()}.
&gt; {pong, pong@bogon} ! {ping, &quot;hello&quot;, self()}.
&gt; receive X -&gt; X end.
{pong,&quot;hello&quot;}</code></pre>
</section>
<section class="slide level1">

<pre><code>erlang:node().
erlang:nodes().</code></pre>
</section>
<section class="slide level1">

<h2 id="hot-code-replacements">Hot code replacements</h2>
<pre><code>version() -&gt; …
c(l).</code></pre>
</section>
<section id="otp" class="slide level1">
<h1>OTP</h1>
<p>Open Telecommunication Platform</p>
</section>
<section class="slide level1">

<h2 id="batteries-inclued">Batteries inclued</h2>
<ul>
<li>EUnit</li>
<li>Mnesia</li>
<li>HTTP/SNMP/…</li>
<li>…</li>
</ul>
</section>
<section class="slide level1">

<h2 id="behaviours">Behaviours</h2>
<ul>
<li>gen_{server,fsm,event}</li>
<li>supervisor</li>
<li>application</li>
</ul>
</section>
<section id="debugging" class="slide level1">
<h1>Debugging</h1>
</section>
<section class="slide level1">

<h2 id="tracing-processes-messges">Tracing Processes, Messges, …</h2>
<pre><code>erl -sname observer -hidden  -run observer</code></pre>
</section>
<section class="slide level1">

<h2 id="tracing-functions">Tracing functions</h2>
<pre><code>dbg:start().
dbg:tracer().
% trace messages (m)
dbg:p(pong, m).  </code></pre>
</section>
<section id="the-greater-erlang-universe" class="slide level1">
<h1>The greater Erlang Universe</h1>
<ul>
<li>REST: <a href="https://github.com/webmachine/webmachine">Webmachine</a></li>
<li>JSON: <a href="https://github.com/davisp/jiffy">jiffy</a></li>
<li>YAML: <a href="https://github.com/processone/p1_yaml">p1_yaml</a></li>
<li>Build, run, test: <a href="https://github.com/erlang/rebar3">Rebar3</a></li>
<li>… your favorite erlang app goes here …</li>
</ul>
</section>
<section id="extending-erlang" class="slide level1">
<h1>Extending Erlang</h1>
</section>
<section class="slide level1">

<h2 id="nifs---gesundheit">NIFs - Gesundheit!</h2>
<p>Native Implemented Functions</p>
</section>
<section class="slide level1">

<h2 id="c-nodes">C-Nodes</h2>
</section>
<section id="see-also" class="slide level1">
<h1>See also</h1>
<ul>
<li><a href="http://elixir-lang.org/">Elixir</a></li>
<li><a href="http://lfe.io/">LFE(Lisp flavored Erlang)</a></li>
<li><a href="http://erlangonxen.org/">Erlang on Xen</a></li>
</ul>
</section>
<section id="further-reading" class="slide level1">
<h1>Further Reading</h1>
<ul>
<li><a href="http://learnyousomeerlang.com/">Learn you some erlang</a> - buy the book!</li>
<li>On Debian <a href="">/usr/share/doc/erlang-doc</a></li>
<li>Everywhere else: https://www.erlang.org/docs</li>
</ul>
</section>
<section id="questions" class="slide level1">
<h1>Questions?</h1>
</section>
    </div>
  </div>

  <script src="reveal.js/lib/js/head.min.js"></script>
  <script src="reveal.js/js/reveal.js"></script>

  <script>

      // Full list of configuration options available at:
      // https://github.com/hakimel/reveal.js#configuration
      Reveal.initialize({
        // Vertical centering of slides
        center: true,
        // Transition style
        transition: 'fade', // none/fade/slide/convex/concave/zoom

        // Optional reveal.js plugins
        dependencies: [
          { src: 'reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
          { src: 'reveal.js/plugin/zoom-js/zoom.js', async: true },
          { src: 'reveal.js/plugin/notes/notes.js', async: true }
        ]
      });
    </script>
    </body>
</html>