aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.html
blob: e57746fc5eb63b53c55de2e93a5c10b20c17cc19 (plain) (blame)
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
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta
            name="viewport"
            content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
        />

        <title>reveal.js</title>

        <link rel="stylesheet" href="dist/reset.css" />
        <link rel="stylesheet" href="dist/reveal.css" />
        <link rel="stylesheet" href="dist/theme/blood.css" id="theme" />

        <!-- Theme used for syntax highlighted code -->
        <link
            rel="stylesheet"
            href="plugin/highlight/monokai.css"
            id="highlight-theme"
        />
    </head>
    <body>
        <div class="reveal">
            <div class="slides">
                <section>
                    <h2>Call by value<br />vs.<br />Call by reference</h2>
                    <small>Marvin Borner</small>
                </section>

                <section>
                    <h2>Call by value</h2>
                    <p class="fragment">Der Standard in den meisten Sprachen</p>
                    <pre class="fragment">
                    <code class="c# hljs cs" data-trim data-line-numbers="1-11|8|1-4,9|10|1-11"><script type="text/template">
                    private static void ErhoeheZahl(int zahl)
                    {
                        zahl += 42;
                    }

                    static void Main(string[] args)
                    {
                        int bla = 0;
                        ErhoeheZahl(bla);
                        Console.WriteLine(bla);
                    }</script></code></pre>
                    <small
                        ><code class="fragment console"
                            >[C#-Console] 0</code
                        ></small
                    >
                </section>

                <section>
                    <h2>Call by reference</h2>
                    <p class="fragment">Wird meist bewusst verwendet</p>
                    <p class="fragment">
                        Kann in C# mit dem
                        <code style="color: #ffff55">ref</code> keyword
                        umgesetzt werden
                    </p>
                    <pre class="fragment">
                    <code class="c# hljs cs" data-trim data-line-numbers="1-11|8|1-4,9|10|1-11"><script type="text/template">
                    private static void ErhoeheZahl(ref int zahl)
                    {
                        zahl += 42;
                    }

                    static void Main(string[] args)
                    {
                        int bla = 0;
                        ErhoeheZahl(ref bla);
                        Console.WriteLine(bla);
                    }</script></code></pre>
                    <small
                        ><code class="fragment console"
                            >[C#-Console] 42</code
                        ></small
                    >
                </section>

                <section>
                    <h3>Besonderheiten - Objekte</h3>

                    <section>
                        <pre class="fragment">
                        <code class="c# hljs cs" data-trim data-line-numbers="1-12|9|1-5,10|11|1-12"><script type="text/template">
                        private static void FuegeHinzu(List<int> liste)
                        {
                            liste.Add(4);
                            liste.Add(5);
                        }

                        static void Main(string[] args)
                        {
                            List<int> liste = new List<int>() { 1, 2, 3 };
                            FuegeHinzu(liste);
                            Console.WriteLine(string.Join(", ", liste));
                        }</script></code>
                        </pre>
                        <small
                            ><code class="fragment console"
                                >[C#-Console] 1, 2, 3, 4, 5</code
                            ></small
                        >
                    </section>

                    <section>
                        <pre>
                        <code class="c# hljs cs" data-trim data-line-numbers="1-12|9|1-5,10|11|1-12"><script type="text/template">
                        private static void UeberschreibeListe(List<int> liste)
                        {
                            liste = new List<int>();
                            liste.Add(42);
                        }

                        static void Main(string[] args)
                        {
                            List<int> liste = new List<int>() { 1, 2, 3 };
                            FuegeHinzu(liste);
                            Console.WriteLine(string.Join(", ", liste));
                        }</script></code>
                        </pre>
                        <small
                            ><code class="fragment console"
                                >[C#-Console] 1, 2, 3</code
                            ></small
                        >
                    </section>

                    <section>
                        <pre>
                        <code class="c# hljs cs" data-trim data-line-numbers="1-12|9|1-5,10|11|1-12"><script type="text/template">
                        private static void UeberschreibeListe(ref List<int> liste)
                        {
                            liste = new List<int>();
                            liste.Add(42);
                        }

                        static void Main(string[] args)
                        {
                            List<int> liste = new List<int>() { 1, 2, 3 };
                            FuegeHinzu(ref liste);
                            Console.WriteLine(string.Join(", ", liste));
                        }</script></code>
                        </pre>
                        <small
                            ><code class="fragment console"
                                >[C#-Console] 42</code
                            ></small
                        >
                    </section>
                </section>

                <section>
                    <h3>Besonderheiten - Arrays</h3>
                    <section>
                        <pre>
                        <code class="c# hljs cs" data-trim data-line-numbers="1-11|8|1-4,9|10|1-11"><script type="text/template">
                        private static void BearbeiteFeld(int[] felder)
                        {
                            felder[0] = 42;
                        }

                        static void Main(string[] args)
                        {
                            int[] felder = new int[] { 1, 2, 3 };
                            BearbeiteFeld(felder);
                            Console.WriteLine(felder[0]);
                        }</script></code>
                        </pre>
                        <small
                            ><code class="fragment console"
                                >[C#-Console] 42</code
                            ></small
                        >
                    </section>

                    <section>
                        <pre>
                        <code class="c# hljs cs" data-trim data-line-numbers="1-11|8|1-4,9|10|1-11"><script type="text/template">
                        private static void UeberschreibeFelder(int[] felder)
                        {
                            felder = new int[] { 4, 5, 6 };
                        }

                        static void Main(string[] args)
                        {
                            int[] felder = new int[] { 1, 2, 3 };
                            UeberschreibeFelder(felder);
                            Console.WriteLine(felder[0]);
                        }</script></code>
                        </pre>
                        <small
                            ><code class="fragment console"
                                >[C#-Console] 1</code
                            ></small
                        >
                    </section>

                    <section>
                        <pre>
                        <code class="c# hljs cs" data-trim data-line-numbers="1-11|8|1-4,9|10|1-11"><script type="text/template">
                        private static void UeberschreibeFelder(ref int[] felder)
                        {
                            felder = new int[] { 4, 5, 6 };
                        }

                        static void Main(string[] args)
                        {
                            int[] felder = new int[] { 1, 2, 3 };
                            UeberschreibeFelder(ref felder);
                            Console.WriteLine(felder[0]);
                        }</script></code>
                        </pre>
                        <small
                            ><code class="fragment console"
                                >[C#-Console] 4</code
                            ></small
                        >
                    </section>
                </section>

                <section>
                    <h2>Mehrere Rückgabewerte</h2>
                    <pre>
                        <code class="c# hljs cs" data-trim data-line-numbers="1-13|10|1-6,11|12|1-13"><script type="text/template">
                        private static void Rueckgabe(ref int a, ref int b, ref int c)
                        {
                            a = 1;
                            b = 2;
                            c = 3;
                        }

                        static void Main(string[] args)
                        {
                            int a = 0, b = 0, c = 0;
                            Rueckgabe(ref a, ref b, ref c);
                            Console.WriteLine(a + ", " + b + ", " + c);
                        }</script></code>
                        </pre>
                    <small
                        ><code class="fragment console"
                            >[C#-Console] 1, 2, 3</code
                        ></small
                    >
                </section>

                <section>
                    <section>
                        <h2>Vorteile von call by reference</h2>
                        <ul>
                            <li class="fragment">
                                Muss nicht extra kopiert werden (weniger
                                Overhead)
                            </li>
                            <ul>
                                <li
                                    style="list-style-type: none"
                                    class="fragment"
                                >
                                    &rarr; schneller
                                </li>
                            </ul>
                            <li class="fragment">
                                Eine Funktion kann mehrere Rückgabewerte
                                besitzen
                            </li>
                        </ul>
                    </section>

                    <section>
                        <h2>Nachteile von call by reference</h2>
                        <ul>
                            <li class="fragment">
                                Teilweise nicht sehr lesbar/verständlich
                            </li>
                            <li class="fragment">
                                Probleme mit Garbage Collectors und
                                Multi-Threading
                            </li>
                        </ul>
                    </section>
                </section>

                <section>
                    <h2>Andere Sprachen</h2>
                    <section>
                        <h3>C</h3>
                        <pre class="fragment">
                        <code class="c hljs" data-trim data-line-numbers="1-11|8|1-4,9|10|1-11"><script type="text/template">
                        static void bearbeite_zeiger(int *zeiger)
                        {
                            *zeiger = 42;
                        }

                        void main(int argc, char **argv)
                        {
                            int zahl = 0;
                            bearbeite_zeiger(&zahl);
                            printf("%d\n", zahl);
                        }</script></code>
                        </pre>
                        <small
                            ><code class="fragment console"
                                >[C-Console] 42</code
                            ></small
                        >
                    </section>

                    <section>
                        <h3>JavaScript</h3>
                        <pre>
                        <code class="js hljs" data-trim data-line-numbers="1-11|9|1-3,10|5-7,11|1-11"><script type="text/template">
                        function ersetzen(obj) {
                            obj = {}; // Verändert das originale Objekt nicht
                        }

                        function bearbeiten(obj) {
                            obj.key = "Aaah"; // Verändert das originale Objekt
                        }

                        const toll = { key: "hihi" };
                        ersetzen(toll); // obj.key => "hihi"
                        bearbeiten(toll); // obj.key => "Aaah"
                        </script></code>
                        </pre>
                    </section>
                </section>

                <section>
                    <h2>
                        Danke, dass Sie so leise und aufmerksam waren. Tschüss!
                    </h2>
                    <small>Marvin Borner</small>
                </section>
            </div>
        </div>

        <script src="dist/reveal.js"></script>
        <script src="plugin/notes/notes.js"></script>
        <script src="plugin/markdown/markdown.js"></script>
        <script src="plugin/highlight/highlight.js"></script>
        <script>
            // More info about initialization & config:
            // - https://revealjs.com/initialization/
            // - https://revealjs.com/config/
            Reveal.initialize({
                controls: false,
                hash: true,

                // Learn about plugins: https://revealjs.com/plugins/
                plugins: [RevealMarkdown, RevealHighlight, RevealNotes],
            });

            (() => {
                document.getElementsByTagName("pre").forEach((e) => {
                    if (e.firstChild.nodeType == 3) e.firstChild.remove();
                });

                document.getElementsByTagName("code").forEach((e) => {
                    if (e.nextSibling.nodeType == 3) e.nextSibling.remove();
                });
            })();
        </script>
    </body>
</html>