-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
706 lines (485 loc) · 25.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
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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Functional Programming Propaganda</title>
<meta name="description" content="Description of why concepts popular in FP help reduce defects">
<meta name="author" content="Nick Peterson">
<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">
<script src="//code.jquery.com/jquery-1.8.0.js"></script>
<script src="//code.jquery.com/ui/1.8.23/jquery-ui.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/solarized.css" id="theme">
<link type="text/css" rel="stylesheet" href="fsharp.formatting/styles/style.css" />
<link type="text/css" rel="stylesheet" href="fsharp.formatting/styles/deedle.css" />
<link type="text/css" rel="stylesheet" href="css/custom.css" />
<script src="fsharp.formatting/styles/tips.js" type="text/javascript"></script>
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- 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">
<div class="tip" id="fs1">val add : x:int -> y:int -> int<br /><br />Full name: index.add</div>
<div class="tip" id="fs2">val x : int</div>
<div class="tip" id="fs3">val y : int</div>
<div class="tip" id="fs4">val addFive : (int -> int)<br /><br />Full name: index.addFive</div>
<div class="tip" id="fs5">type EmailAddress = string<br /><br />Full name: index.EmailAddress</div>
<div class="tip" id="fs6">Multiple items<br />val string : value:'T -> string<br /><br />Full name: Microsoft.FSharp.Core.Operators.string<br /><br />--------------------<br />type string = System.String<br /><br />Full name: Microsoft.FSharp.Core.string</div>
<div class="tip" id="fs7">type CustomerName = string<br /><br />Full name: index.CustomerName</div>
<div class="tip" id="fs8">type ContactInfo = EmailAddress * CustomerName<br /><br />Full name: index.ContactInfo</div>
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section >
<h1>Complexity!</h1>
<p>...I couldn't think of a catchy title.</p>
</section>
<section >
<h3>Who Am I?</h3>
<ul>
<li>Reads too much Hackernews</li>
<li>Programming Language Snob</li>
<li>Enjoy Databases more than is healthy.</li>
</ul>
<p><img src="images/nickpeterson.jpeg" alt="Nick Peterson" />
Me in natural habitat.</p>
</section>
<section >
<h3>Where is this talk headed?</h3>
<p>I like to know it's a rollercoaster before I get in line.</p>
<ul>
<li>Defects</li>
<li>Complexity</li>
<li>Quality</li>
</ul>
</section>
<section >
<h3>What is a Defect?</h3>
<blockquote>
<p>A shortcoming, imperfection, or lack.</p>
</blockquote>
<p>When we say, 'Defect Free Software'. We're using a shorthand for saying that we want our software without shortcomings or imperfections.</p>
</section>
<section >
<h3>Where do software defects come from?</h3>
<ul>
<li><p><strong>Complexity</strong> produces software defects</p></li>
<li>If something is simple to learn and understand, it tends to be simple to alter.</li>
<li>If something is complex to learn and understand, it tends to be complex to alter.</li>
</ul>
</section>
<section >
<section >
<h3>Complexity</h3>
<blockquote>
<p>'Controlling complexity is the essence of computer programming.' -Brian Kernighan</p>
</blockquote>
<p>Types of Complexity:</p>
<ul>
<li><strong><em>Essential Complexity</em></strong>: Directly related to the problem, absolutely necessary to solve the problem.</li>
<li><strong><em>Accidental Complexity</em></strong>: Not related to the problem, generally comes from tools.</li>
</ul>
<p>If you changed your entire architecture,
essential complexity would remain unaltered,
but accidental complexity may vary significantly.</p>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<h3>Some Real World Examples:</h3>
<h4>Accidental Complexity</h4>
<ul>
<li>Null Checks</li>
<li>Required Syntax</li>
<li>Memory Management</li>
</ul>
<h4>Essential Complexity</h4>
<ul>
<li>Balancing Financial Transactions</li>
<li>Commission Calculation Engine</li>
<li>Scheduling machines to run at optimal throughput..</li>
</ul>
</section>
</section>
<section >
<h3>Quality</h3>
<p>Software with no defects that is still 'fit to purpose', is high quality software.</p>
<p>Since reducing complexity lowers the defect rate, doing so while remaining 'fit to purpose' must raise quality.</p>
<p>Basically, if you can remove complexity without removing capability, quality increases.</p>
</section>
<section >
<h3>Tests</h3>
<blockquote>
<p>Cease dependence on inspection to achieve quality. Eliminate the need for massive inspection by building quality into the product in the first place. -William E. Deming</p>
</blockquote>
<ul>
<li>Testing finds defects in our software.</li>
<li>The defects probably exist because of complexity.</li>
<li>Testing is a way of measuring quality, not creating it.</li>
<li>Focus on decreasing complexity rather than increasing tests to deal with complexity</li>
<li>Tests are a way to mitigate areas of high complexity that are essential.</li>
</ul>
</section>
<section >
<h3>Complexity vs Ease</h3>
<ul>
<li>Often we think of tools (languages, libraries, frameworks, programs), as reducing complexity.</li>
</ul>
<p>That's not really true though, for instance. Database servers are extremely complex, and bring with them many things that we'll never have need for.</p>
<p>We've added massive complexity in return for ease.</p>
</section>
<section >
<h3>Complexity vs Ease cont.</h3>
<p>This applies to almost all tools. Often tooling we use is combating the symptoms of complexity without treating the root cause, complexity itself.</p>
<p>Linters are great tools for enforcing a consistent style of coding, but it's very use is often a sign that the tool in question (in this case a programming language) is allowing people to use it in undesirable ways?</p>
<p>To be clear, I'm not arguing against linters, just pointing out that they're mitigating a problem caused by other things.
</section>
<section >
<h3>Simplify Essential Complexity.</h3>
<p>There are many ways to attempt this,
but it falls mostly outside of the scope of this talk</p>
<p>I encourage anyone here not intimately familiar with Domain Driven Design
to look into it. Notice the word complexity in the tagline of the book?
Not a coincidence...</p>
<p><img src="images/DDD.jpg" alt="Domain Driven Design" /></p>
</section>
<section >
<h3>Reducing Accidental Complexity</h3>
<ul>
<li>Reduce lines of code</li>
<li>Reduce number of tools used to solve a problem</li>
</ul>
<p>Great paper on this subject to look into it 'Out of the Tar Pit' by Ben Moseley and Peter Marks. They trace software complexity through great minds like Brooks and Dijkstra.</p>
</section>
<section >
<h3>Terse, High-Level Languages Can Help Lower Accidental Complexity</h3>
<ul>
<li>LISP derivatives (Clojure, Racket, Scheme)</li>
<li>ML derivatives (Standard ML, Ocaml, F#)</li>
<li>BEAM Langauges (Erlang, Elixir)</li>
<li>Other notables (Scala, Rust, Prolog, APL)</li>
</ul>
<p>Often able to describe a solution in less lines of code, with less ceremony.</p>
<p>What about C#?</p>
</section>
<section >
<section >
<h3>Low Complexity Possible Through C#?</h3>
<p>In some ways, C# is much less complex than certain languages</p>
<p>C# is easily less complex than two extremely common languages:</p>
<ul>
<li>C++ (has template macros, ability to inline C, manual memory management...)</li>
<li>Javascript (although this is becoming less true..)</li>
</ul>
<p>But there are still 'features' of C# that makes it less easy to quickly reason about. They add incidental complexity, let's look at some examples...</p>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<p>Is the following true or false?</p>
<table class="pre"><tr><td><pre lang="cs"><span class="k">var</span> cust1 <span class="o">=</span> <span class="k">new</span> Customer(99, <span class="s">"J Smith"</span>);
<span class="k">var</span> cust2 <span class="o">=</span> <span class="k">new</span> Customer(99, <span class="s">"J Smith"</span>);
cust1.Equals(cust2);
</pre></td></tr></table>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<p>Who Knows?</p>
<ul>
<li>If Customer has implemented IEquatable it could be true.</li>
<li>The point is you have to delve into Customer to understand what this code will do.</li>
<li>Is there any chance cust1 and cust2 are actually different in reality?</li>
<li>Ideally comparisons by value would be the default.</li>
</ul>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<p>What does this print?</p>
<table class="pre"><tr><td><pre lang="cs"><span class="k">var</span> cust <span class="o">=</span> <span class="k">new</span> Customer();
Console.WriteLine(cust.Address.Country);
</pre></td></tr></table>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<p>Depends if the Address property is null or not. Hopefully the constructor initialized Address and the Country property.</p>
<p>The point is that objects can exist in an invalid state.</p>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<p>What does this output?</p>
<table class="pre"><tr><td><pre lang="cs"><span class="k">var</span> repo <span class="o">=</span> <span class="k">new</span> CustomerRepository();
<span class="k">var</span> customer <span class="o">=</span> repo.GetById(42);
Console.WriteLine(customer.Id);
</pre></td></tr></table>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<p>Well, the value of customer could be:</p>
<ul>
<li>A regular, initialized Customer (fingers crossed!).</li>
<li>A default Customer object.</li>
<li>Customer could be null.</li>
<li>The ID could be null.</li>
<li>An Exception could be thrown.</li>
</ul>
<p>Wouldn't it be nice if we didn't have to worry about null?</p>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<p>Will this return an int?</p>
<table class="pre"><tr><td><pre lang="cs"><span class="k">try</span> {
Int32.Parse(<span class="s">"ABCxxx"</span>);
}
<span class="k">catch</span> (Exception ex) {
<span class="c">//exception code</span>
}
</pre></td></tr></table>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<p>No, obviously it will throw an exception.</p>
<p>What is an improvement? How about:</p>
<table class="pre"><tr><td><pre lang="cs"><span class="k">int</span> result <span class="o">=</span> 0;
<span class="k">bool</span> parsed <span class="o">=</span> <span class="k">false</span>;
parse <span class="o">=</span> Int32.TryParse(<span class="s">"ABCxxx"</span>, <span class="k">out</span> result);
</pre></td></tr></table>
<p>Now my code always returns true/false (no exceptions), and I can check the bool before using the output integer.</p>
<p>I've made the possible cases explicit, and the code easier to understand because it isn't full of exception handling code.</p>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<h3>Imperative Statements</h3>
<p>Imagine if SQL didn't exist and every 'query' resulted in statements like:</p>
<table class="pre"><tr><td><pre lang="cs"><span class="k">foreach</span> (Customer c <span class="k">in</span> Customers)
{
<span class="k">decimal</span> sum <span class="o">=</span> 0.00;
<span class="k">foreach</span> (Order o <span class="k">in</span> Orders)
{
<span class="k">if</span> (o.CustomerId <span class="o">=</span><span class="o">=</span> c.CustomerId)
{
sum <span class="o">+</span><span class="o">=</span> o.Total
}
}
}
</pre></td></tr></table>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<h3>Statements VS Expressions</h3>
<p>Almost all operations in C# use statements. Some things like LINQ are expressions, what's the difference?</p>
<ul>
<li>Statements manipulate state -> cause side effects to produce a result.</li>
<li>Expressions can be composed of other expressions -> produce a value.</li>
</ul>
<p>Statements usually assign their result to a variable, which can change over time.</p>
<p>Lets look at some C# with statements, then replace some of the statements with expressions.</p>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<h3>For Loop:</h3>
<table class="pre"><tr><td><pre lang="cs"><span class="k">int</span> i;
<span class="k">int</span> length;
<span class="k">var</span> numArray <span class="o">=</span> <span class="k">new</span> <span class="k">int</span>[] { 1, 2, 3 };
<span class="k">int</span> sum;
length <span class="o">=</span> numArray.Length;
<span class="k">for</span> (i <span class="o">=</span> 0; i <span class="o"><</span> length; i+<span class="o">+</span>)
{
sum <span class="o">+</span><span class="o">=</span> numArray[i];
}
</pre></td></tr></table>
<aside class="notes">
Note the placeholder variables, what is their initial value?<br/>
explicit control of length/iteration, could run forever.<br/>
</aside>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<h3>Foreach Loop:</h3>
<table class="pre"><tr><td><pre lang="cs"><span class="k">var</span> numArray <span class="o">=</span> <span class="k">new</span> <span class="k">int</span>[] { 1, 2, 3 };
<span class="k">int</span> sum <span class="o">=</span> 0;
<span class="k">foreach</span> (<span class="k">var</span> i <span class="k">in</span> numArray)
{
sum <span class="o">+</span><span class="o">=</span> i;
}
</pre></td></tr></table>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<h3>LINQ Expression</h3>
<table class="pre"><tr><td><pre lang="cs"><span class="k">var</span> numArray <span class="o">=</span> <span class="k">new</span> <span class="k">int</span>[] { 1, 2, 3 };
<span class="k">var</span> sum <span class="o">=</span> array.Sum();
</pre></td></tr></table>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<h3>More on Expressions</h3>
<ul>
<li>Expressions are composable, you can place an expression into another expression.</li>
<li>Statements use side effects to produce results, but C# doesn't guarantee the return type.</li>
<li>The move from statements to expressions removes possibilities for errors.</li>
<li>Wouldn't it be nice if the entire language used expressions?</li>
</ul>
</section>
</section>
<section >
<h3>Immutable Data Types</h3>
<p>C# encourages the use of mutability almost everywhere.</p>
<p>That means it's really easy to create changes, but difficult to track down
the source of a change. As soon as you start contending with
concurrency or parallelism, it can become a nightmare.</p>
<p>Wouldn't it be nice if your language pushed you down the right path from day one?</p>
</section>
<section >
<h3>High Order Functions</h3>
<p>Treating functions as a value is useful.</p>
<p>Allows use to pass functions to other functions.
Or return a function from another function.</p>
<p>C# actually does allow this, but it isn't very idiomatic.</p>
<p>Also, most libraries don't do it, so you fight against the tide.</p>
</section>
<section >
<h3>Currying and Partial Application</h3>
<p>Allows you to partially specify parameters to a function.
It produces a new function with those parameters statically set.</p>
<p>imagine a function like the following</p>
<table class="pre"><tr><td class="lines"><pre class="fssnip">
<span class="l">1: </span>
</pre>
</td>
<td class="snippet"><pre class="fssnip">
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs1', 1)" onmouseover="showTip(event, 'fs1', 1)" class="f">add</span> <span onmouseout="hideTip(event, 'fs2', 2)" onmouseover="showTip(event, 'fs2', 2)" class="i">x</span> <span onmouseout="hideTip(event, 'fs3', 3)" onmouseover="showTip(event, 'fs3', 3)" class="i">y</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs2', 4)" onmouseover="showTip(event, 'fs2', 4)" class="i">x</span> <span class="o">+</span> <span onmouseout="hideTip(event, 'fs3', 5)" onmouseover="showTip(event, 'fs3', 5)" class="i">y</span>
</pre>
</td>
</tr>
</table>
<p>This function is called 'add' and takes 2 parameters, x and y.
It then sums them and returns the new value. We could also add this
definition.</p>
<table class="pre"><tr><td class="lines"><pre class="fssnip">
<span class="l">1: </span>
</pre>
</td>
<td class="snippet"><pre class="fssnip">
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs4', 6)" onmouseover="showTip(event, 'fs4', 6)" class="f">addFive</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs1', 7)" onmouseover="showTip(event, 'fs1', 7)" class="f">add</span> <span class="n">5</span>
</pre>
</td>
</tr>
</table>
<p>We partially filled in a call to 'add' with the first parameter set to 5.</p>
<p>Now we can call addFive without creating a new duplicate definition.</p>
</section>
<section >
<section >
<h3>Algebraic Types</h3>
<p>In C#, types are either built into the langauge as keywords, or defined as classes.</p>
<p>Unfortunately, they have pretty high ceremony, and combining them results in a lot more code.</p>
<p>Algebraic types allows one to add or multiple 'types' (not values) together to produce
new types.</p>
<p>consider these types:</p>
<table class="pre"><tr><td class="lines"><pre class="fssnip">
<span class="l">1: </span>
<span class="l">2: </span>
<span class="l">3: </span>
</pre>
</td>
<td class="snippet"><pre class="fssnip">
<span class="k">type</span> <span onmouseout="hideTip(event, 'fs5', 8)" onmouseover="showTip(event, 'fs5', 8)" class="t">EmailAddress</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs6', 9)" onmouseover="showTip(event, 'fs6', 9)" class="t">string</span>
<span class="k">type</span> <span onmouseout="hideTip(event, 'fs7', 10)" onmouseover="showTip(event, 'fs7', 10)" class="t">CustomerName</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs6', 11)" onmouseover="showTip(event, 'fs6', 11)" class="t">string</span>
<span class="k">type</span> <span onmouseout="hideTip(event, 'fs8', 12)" onmouseover="showTip(event, 'fs8', 12)" class="t">ContactInfo</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs5', 13)" onmouseover="showTip(event, 'fs5', 13)" class="t">EmailAddress</span> <span class="o">*</span> <span onmouseout="hideTip(event, 'fs7', 14)" onmouseover="showTip(event, 'fs7', 14)" class="t">CustomerName</span>
</pre>
</td>
</tr>
</table>
<p>contactInfo is the equivalent of a C# tuple that has two properties,
one of type emailAddress and one of type customerName.</p>
</section>
<section author="Nick Peterson" description="Description of why concepts popular in FP help reduce defects" theme="solarized" title="Functional Programming Propaganda" transition="default">
<h3>Algebraic Types Continued..</h3>
<p>But we could also 'sum' types together to make types that can be either one or the other.</p>
<table class="pre"><tr><td class="lines"><pre class="fssnip">
<span class="l">1: </span>
<span class="l">2: </span>
<span class="l">3: </span>
</pre>
</td>
<td class="snippet"><pre class="fssnip">
<span class="k">type</span> <span onmouseout="hideTip(event, 'fs8', 15)" onmouseover="showTip(event, 'fs8', 15)" class="i">ContactInfo</span> <span class="o">=</span>
|<span class="i">Complete</span> <span class="k">of</span> <span class="i">emailAddress</span> <span class="o">*</span> <span class="i">customerName</span>
|<span class="i">Incomplete</span> <span class="k">of</span> <span class="i">emailAddress</span>
</pre>
</td>
</tr>
</table>
<p>Now we have a type that could be either Complete or Incomplete, and we can make code respond accordingly.</p>
</section>
</section>
<section >
<h3>Pattern Matching</h3>
<p>So we have a ContactInfo type, how does using that look in practice?</p>
<p>Match Expression:</p>
<table class="pre"><tr><td class="lines"><pre class="fssnip">
<span class="l">1: </span>
<span class="l">2: </span>
<span class="l">3: </span>
</pre>
</td>
<td class="snippet"><pre class="fssnip">
<span class="k">match</span> <span class="i">contact</span> <span class="k">with</span>
| <span class="i">Complete</span> <span class="i">email</span>,<span class="i">name</span> <span class="k">-></span> <span class="i">sendEmail</span> <span class="i">email</span> <span class="i">name</span>
| <span class="i">Incomplete</span> <span class="i">email</span> <span class="k">-></span> <span class="i">sendEmail</span> <span class="i">email</span> <span class="s">"Sir or Madame"</span>
</pre>
</td>
</tr>
</table>
<p>We tested for the type of the contact and then reacted accordingly.</p>
</section>
<section >
<h3>References:</h3>
<p>An introduction to F# for Object-Oriented, enterprise developers.</p>
<ul>
<li><a href="http://www.fsharpforfunandprofit.com">F# For Fun And Profit</a></li>
</ul>
<p>Rich Hickey (creator of Clojure) conference talks</p>
<ul>
<li><a href="https://www.youtube.com/watch?v=f84n5oFoZBc">Hammock Driven Development</a></li>
<li><a href="http://www.infoq.com/presentations/Value-Values">The Value of Values</a></li>
<li><a href="http://www.infoq.com/presentations/Simple-Made-Easy">Simple Made Easy</a></li>
</ul>
<p>You will never read a more fun intro to a programming language.</p>
<ul>
<li><a href="http://learnyouahaskell.com/">Learn You A Haskell For Great Good</a></li>
</ul>
<p>A clojure variant of Learn You A Haskell For Great Good</p>
<ul>
<li><a href="http://www.braveclojure.com/">Clojure For The Brave And True</a></li>
</ul>
</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,
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>