-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
813 lines (737 loc) · 25.6 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
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>FP.py</title>
<meta name="description" content="An Introduction to Functional Programming in Python">
<meta name="author" content="Elliot Cameron">
<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="css/reveal.css">
<link rel="stylesheet" href="css/custom.css">
<link rel="stylesheet" href="css/theme/night.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- 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 ) ? 'css/print/pdf.css' : 'css/print/paper.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 customized">
<section id="intro">
<section>
<h1>FP.py</h1>
<h3>An Introduction to Functional Programming in Python</h3>
<p>
<small>by <a href="http://3noch.github.io">Elliot Cameron</a> / <a href="https://github.com/3noch">3noch</a></small>
</p>
<p>
<small>Follow along<br><a href="http://3noch.github.io/fp.py">3noch.github.io/fp.py</a></small>
</p>
<p>
<small><em>Note:</em> Alt+Click on an element to zoom in.</small>
</p>
<p>
Ask questions!
</p>
</section>
<section>
<h2>Objective</h2>
<div class="fragment">
<img src="img/wrong.jpg">
<a class="reference" ahref="http://www.lambdalounge.org.uk/">ref</a>
</div>
</section>
<section>
<h2>Objective</h2>
<h3>Not</h3>
<p>
<ul>
<li>to convince you to write all your Python code in FP style.</li>
</ul>
</p>
<h3>To</h3>
<p>
<ul>
<li>broaden your perspective on programming in general,</li>
<li>increase your appreciation for alternative ways of approaching a problem,</li>
<li>help you write better code.</li>
</ul>
</p>
</section>
</section>
<section>
<section>
<h2>Who?</h2>
<p class="fragment">
<img src="img/ranking.png" style="width: 40%; height: auto">
<a class="reference" href="http://www.sitepoint.com/best-programming-language-learn-2014-mid-year-update/">ref</a>
<br>
FP is starting to gain momentum
</p>
</section>
<section>
<h2>It's weird</h2>
<h3>and scary</h3>
<p>
<pre>
<code class="haskell" data-trim>
type Seconds = Int
secs :: Int -> Seconds; secs = (* 1000000)
wait :: Seconds -> IO (); wait = threadDelay . secs
schedule :: Seconds -> IO () -> IO ThreadId; schedule s a = forkIO $! wait s >> a
(<>) :: ByteString -> ByteString -> ByteString; (<>) = B.append
(//) :: a -> (a -> b) -> b; x // f = f x
(|>) :: IO () -> IO () -> IO (); a |> b = forkIO a >> b
infixr 0 =>>; (=>>) :: Monad m => m a -> (a -> m b) -> m a
a =>> f = do r <- a; _ <- f r; return r
type ErrorIO = IO
att :: IO a -> IO (Maybe a); att a = tryWith (const $! return Nothing) (Just <$> a)
tryRun :: IO () -> IO (); tryRun a = tryWith (\x -> do print x; wait 2) a
(???) :: ErrorIO a -> [IO a] -> IO a; e ??? as = foldr (?>) e as
where x ?> y = x `X.catch` (\(_ :: X.SomeException) -> y)
</code>
</pre>
<a class="reference" href="https://github.com/corsis/PortFusion/blob/master/src/Main.hs">ref</a>
</p>
</section>
<section>
<h2>But beware the <a href="http://lmgtfy.com/?q=Blub+Paradox&l=1">Blub Paradox</a></h2>
<div class="fragment">
<q>"I don't understand your way, so mine must be better."</q>
<img src="img/amish.jpg">
<a class="reference" href="http://www.toledoblade.com/image/2001/05/06/800x_b1_cCM_z/Amish-in-an-English-world-4.jpg">ref</a>
</div>
</section>
<section>
<h2>Discern</h2>
<h3 class="fragment">There are <em>two</em> ways to be puzzled</h3>
<table class="comparison">
<tr>
<td class="fragment">
\[ \begin{aligned}
\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
\nabla \cdot \vec{\mathbf{B}} & = 0 \end{aligned}
\]
</td>
<td class="fragment">
<img src="img/rube.jpg">
</td>
</tr>
<tr>
<td class="caption fragment">
he knows something I don't
</td>
<td class="caption fragment">
he doesn't know what he's doing (and neither do I)
</td>
</tr>
</table>
</section>
</section>
<section id="myths">
<section>
<h2>Myth 1<span class="fragment">: FP is Hard</span></h2>
<div class="fragment">
<h3>hard to what?</h3>
<table>
<tr class="fragment">
<td><strong>learn</strong></td><td>probably only if you're already used to something else*</td>
</tr>
<tr class="fragment">
<td><strong>read</strong></td><td>same deal*</td>
</tr>
<tr class="fragment">
<td><strong>test</strong></td><td>to the contrary, FP tends to be much easier to test*</td>
</tr>
<tr class="fragment">
<td><strong>debug</strong></td><td>to the contrary, expressions are the easiest types of things to debug*</td>
</tr>
</table>
<p style="text-align: left"><small>* courteously suspend disbelief if possible</small></p>
</div>
</section>
<section>
<h2>Myth 2<span class="fragment">: FP is Slow</span></h2>
<div class="fragment">
<h4>not necessarily...</h4>
<img src="img/speed.png">
<a class="reference" href="http://benchmarksgame.alioth.debian.org/u32/compare.php?lang=ghc&lang2=python3">ref</a>
</div>
</section>
<section>
<h2>Myth 3<span class="fragment">: FP is for Idealists</span></h2>
<div class="fragment">
<h4>prove it</h4>
<img src="img/lang-analysis.jpg" style="width: 60%; height: auto">
<blockquote>
To become a competent realist you must start with ideals.
<br>
<small>- Anonymous</small>
</blockquote>
</div>
</section>
</section>
<section id="history">
<section>
<h2>How we got here</h2>
<h4>We live in the imperative dynasty:<br>object-oriented and procedural are both imperative</h4>
<img src="img/directions.png" style="width: 70%; height: auto">
<a class="reference" href="http://www.mapquest.com/?q2=357718324+type:mqid#e55d2ef3dd8453a2788d7198">ref</a>
<br>
driving directions depend on your current position
</section>
<section>
<h2>The Father of Imperative Thinking</h2>
<img src="img/alan.jpg" style="width: 30%; height: auto">
<a class="reference" href="http://en.wikipedia.org/wiki/Alan_Turing#/media/File:Alan_Turing_photo.jpg">ref</a>
<p>Alan Turing: Invented the "Turing Machine" (1936)</p>
</section>
<section>
<h2>The Father of Functional Thinking</h2>
<img src="img/alonzo.jpg" style="width: 30%; height: auto">
<a class="reference" href="http://en.wikipedia.org/wiki/Alonzo_Church#/media/File:Alonzo_Church.jpg">ref</a>
<p>Alonzo Church: Formulated λ-calculus (1928-1929) and Turing's Ph.D. Advisor</p>
</section>
<section>
<h3>Next turn: Maps</h3>
<img src="img/road-map.jpg" style="width: 85%; height: auto">
<a class="reference" href="http://upload.wikimedia.org/wikipedia/commons/1/16/1929_New_England_road_map.jpg">ref</a>
<br>
maps do not depend on your current position
</section>
</section>
<section id="principle1">
<section>
<h2>Principle 1<span class="fragment">: <span style="text-decoration: underline">Function</span></span><span class="fragment">al</span></h2>
<h3 class="fragment">math and pure functions</h3>
</section>
<section>
<h3>Math 101: Functions</h3>
<table class="comparison">
<tr>
<td>
<img src="img/vertical-line-test.png" style="background-color: white; width: 80%; height: auto">
<a class="reference" href="http://en.wikipedia.org/wiki/Vertical_line_test#/media/File:Vertical_line_test.png">ref</a>
</td>
<td>
For every input there is precisely one output.
<td>
</tr>
<tr>
<td class="caption">
The Vertical Line Test
</td>
<td></td>
</tr>
</table>
</section>
<section>
<h3>a.k.a. Referential Transparency</h3>
<h4>and why FP is sometimes called "value-oriented programming"</h4>
<dl>
<dt>referential transparency</dt>
<dd>
<em>ref·er·en·tial trans·par·en·cy</em>
<blockquote style="font-size: 80%">
An expression is said to be <u>referentially transparent</u> if it can be replaced with its value without changing the behavior of a program (in other words, yielding a program that has the same effects and output on the same input). The opposite term is <u>referential opaqueness</u>.
<br><br>
While in mathematics all function applications are referentially transparent, in programming this is not always the case. The importance of referential transparency is that it allows the programmer and the compiler to reason about program behavior.
<a class="reference" href="http://en.wikipedia.org/wiki/Referential_transparency_(computer_science)">ref</a>
</blockquote>
</dd>
</dl>
</section>
<section>
<h4>Example: Python's <code>ord</code> function</h4>
<img src="img/ascii-table.png" style="width:70%; height: auto">
<p>
<code>ord("P")</code> can be replaced with <code>80</code> in every case, and vice versa, without any change to a program's behavior.
</p>
</section>
<section>
<h3>Observe:</h3>
<table class="comparison">
<tr>
<td>
<pre>
<code class="python" data-trim>
def double(x):
return x * 2
def get_last_name(full_name):
return full_name.partition(" ")[2]
def get_penultimate(items):
return (items[-2]
if len(items) > 1
else None)
</code>
</pre>
</td>
<td>
Python Functions? Yes
<br>
Math Functions? Yes
</td>
</tr>
<tr>
<td>
<pre>
<code class="python" data-trim>
def get_random():
return random.randint(1, 10)
global_state = 5
def get_next_state(steps):
global global_state
global_state += steps
return global_state
def save_file(contents):
with open("file.txt", "w") as file_handle:
file_handle.write(contents)
def change_arg(arg):
arg = arg + 1
def hello_world():
print("Hello world")
</code>
</pre>
</td>
<td>
Python Functions? Yes
<br>
Math Functions? No
</td>
</tr>
</table>
</section>
<section>
<h3>How to Break Referential Transparency</h3>
<h4>and why FP is also sometimes called "programming without assignment"</h4>
<ul>
<li>The arch-nemesis of referential transparency is <em>mutable state</em>.</li>
<li>If you want referential transparency, you must give up
<ul>
<li class="fragment"><strike>assignment</strike></li>
<li class="fragment">including <strike>side-effects</strike>.</li>
</ul>
</ul>
<pre class="fragment">
<code class="python" data-trim>
global_state = 5
def get_next_state(steps):
global global_state
global_state += steps # <-- NOPE!
return global_state
def save_file(contents):
with open("file.txt", "w") as file_handle:
file_handle.write(contents) # <-- NOPE!
def change_arg(arg):
arg = arg + 1 # <-- NOPE!
def hello_world():
print("Hello world") # <-- NOPE!
</code>
</pre>
</section>
<section>
<h3>"Impossible!"</h3>
<p class="fragment">
Oh but it is. Turing and Church proved that Turing machines and λ-calculus are equivalent models of computation!
</p>
<h3 class="fragment">"But how?"</h3>
<p class="fragment">
More on that later.
</p>
</section>
<section>
<h3>Why Bother?</h3>
<h4>why referential transparency matters</h4>
<ul>
<li>
Optimizes the programmer's abilities
<ul>
<li>Deterministic</li>
<li>Unaffected by <em>ordering</em> or time</li>
<li>Simple to understand</li>
<li>Easy to refactor</li>
<li>Easy to abstract / modularize</li>
<li>Easy to compose (think Legos)</li>
<li>Easy to isolate and test</li>
<li>Easy to verify by proofs</li>
</ul>
</li>
<li>
Optimizes the machine's abilities
<ul>
<li>Memoization</li>
<li>Common subexpression elimination</li>
<li>Lazy evaluation</li>
<li>Parallelization</li>
<li>Easy to verify by static analysis</li>
</ul>
</li>
</ul>
</section>
</section>
<section id="principle2">
<section>
<h2>
Principle 2<span class="fragment">: <u>Function</u><span class="fragment">s of Higher Order</span>
</h2>
<div class="fragment">
<h3>first-class and higher-order functions</h3>
<img src="img/whoa.jpg">
<a class="reference" href="https://s-media-cache-ak0.pinimg.com/originals/2e/f7/fd/2ef7fd432d5fc9ecbf86e3add52ada46.jpg">ref</a>
</div>
</section>
<section>
<h3>Higher-order Functions</h3>
<h4 class="fragment">are functions that give or take functions</h4>
<div class="fragment">
<p>
(f ∘ g)(x) = f(g(x))
</p>
<img src="img/russian-doll.jpg" style="width: 40%; height: auto">
<a class="reference" href="http://en.wikipedia.org/wiki/Matryoshka_doll#/media/File:Russian-Matroshka2.jpg">ref</a>
<p>
<strong>Exercise:</strong> What are some higher-order functions in math?
</p>
</div>
</section>
<section>
<h3>First-class Functions</h3>
<h4 class="fragment">are boring</h4>
<div class="fragment">
<p>
"First-class" means you can pass it around just like anything else (numbers, strings, objects).
</p>
<pre>
<code class="python" data-trim>
# map takes another function
last_names = map(lambda full_name: full_name.partition(" ")[2], names)
# filter does too
capitalized_names = filter(lambda name: name[0] == name[0].upper(), last_names)
def compose(f, g): # takes two functions
return lambda x: f(g(x)) # gives a new function
</code>
</pre>
</div>
</section>
<section>
<h2>That's it: 2 Principles</h2>
<h3 class="fragment">What happens when we apply them?</h3>
</section>
</section>
<section id="application1">
<section>
<h2>Application 1<span class="fragment">: Immutable Data</span></h2>
<div class="fragment">
<img src="img/immutable.jpg" style="width: 80%; height: auto">
<a class="reference" href="http://bodil.org/ten-minute-clojure/#/10">ref</a>
</div>
</section>
<section>
<img src="img/kay.jpg">
<a class="reference" href="https://lh6.googleusercontent.com/proxy/ywPUp7dCkdmdnAVHi-N_LUwHPeROBunJLOGSLcSjBHRzQcZElEQNPnLXxFclj4EBaAUL-YUwnzmRk1hg8wJmmyw7kWo=w506-h285-n">ref</a>
</section>
<section>
<h3>Don't change, copy</h3>
<pre>
<code class="python" data-trim>
# no
age = 30
if date > birth_date:
age += 1
# yes
age = 30
corrected_age = age + 1 if date > birth_date else age
</code>
</pre>
</section>
<section>
<h3>Isn't that horribly slow?</h3>
<h4 class="fragment">it depends</h4>
<ul>
<li class="fragment">
<p>
Some algorithms actually go faster with immutable structures,
<br>especially ones that can run in parallel.
</p>
</li>
<li class="fragment">
Optimizations exist to make immutable data work efficiently:
<ul>
<li>Sharing*</li>
<li>Path copying*</li>
<li>etc.</li>
</ul>
<p>* Available to Python through a library.</p>
</li>
<li class="fragment">
In many average cases, forgoing mutation is much easier than you might think.
</li>
</ul>
</section>
</section>
<section id="application2">
<section>
<h2>Application 2<span class="fragment">: No Loops</span></h2>
<pre class="fragment">
<code class="python" data-trim>
the_sum = 0
for i in range(10):
the_sum += i # NOPE!
</code>
</pre>
<div class="fragment">
<h4>Use recursion instead</h4>
<pre class="fragment">
<code class="python" data-trim>
def get_sum(values, start=0):
if not values:
return start
the_rest = values[1:] # why is this ok?
return get_sum(the_rest, start + values[0])
the_sum = get_sum(range(10)) # 45
# or
get_sum = lambda values, start=0: get_sum(values[1:], start + values[0]) if values else start
the_sum = get_sum(range(10)) # 45
# or
the_sum = sum(range(10)) # 45
</code>
</pre>
</div>
</section>
<section>
<h3>Recursion is Bad in Python</h3>
<p>
Python doesn't implement any optimizations for recursion, so recursion bloats your stack really fast, runs very slowly, and can easily hit the recursion limit.
</p>
<pre class="fragment">
<code class="python" data-trim>
get_sum(range(1000000)) # takes forever
</code>
</pre>
<h4 class="fragment">But not to fear, we can</h4>
<ul>
<li class="fragment">use a library to help, or</li>
<li class="fragment">realize that...</li>
</ul>
</section>
<section>
<h3>All Loops Can Be Broken Down</h3>
<div class="fragment">
<p>
<code>sum</code> is an example of a particular <em>type</em> of loop: <strong>fold</strong>.
</p>
</div>
<h4 class="fragment">All loops can be written in terms of</h4>
<ul>
<li class="fragment">maps</li>
<li class="fragment">filters</li>
<li class="fragment">
folds (also called "reduce")
<br>
<small class="fragment">in fact, <em>fold</em> is really all you need</small>
</li>
</ul>
<pre class="fragment">
<code class="python" data-trim>
map(lambda x: x * 2, range(10)) # [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
filter(lambda x: x < 5, range(10)) # [0, 1, 2, 3, 4]
reduce(lambda x, y: x + y, range(10), 0) # 45
# mixup
map(lambda x: x * 2, filter(lambda x: x < 5, range(10))) # [0, 2, 4, 6, 8]
# or
[x * 2 for x in range(10) if x < 5] # [0, 2, 4, 6, 8]
</code>
</pre>
<p class="fragment">
We can rely on these tools to skip the need for explicit recursion.
</p>
</section>
</section>
<section id="application3">
<section>
<h2>Application 3<span class="fragment">: Partial Application and Currying</span></h2>
<h4 class="fragment">and why every function really only has one argument</h4>
<div class="fragment">
<img src="img/curry.jpg">
<a class="reference" href="https://wiki.haskell.org/Haskell_Brooks_Curry">ref</a>
<br>
Haskell Brooks Curry
</div>
</section>
<section>
<h3>Partial Application</h3>
<h4>fill in the holes</h4>
<h5 class="fragment">What happens when you don't provide all the arguments?</h5>
<pre class="fragment">
<code class="python" data-trim>
def add_them(a, b):
return a + b
add_them(2)
# TypeError: add_them() takes exactly 2 arguments (1 given)
</code>
</pre>
<h5 class="fragment">Why not build the result in phases?</h5>
<pre class="fragment">
<code class="python" data-trim>
from functools import partial
partial(add_them, 2)
# <functools.partial at 0x322bf48>
partial(add_them, 2)(3) # 5
</code>
</pre>
</section>
<section>
<h3>Currying</h3>
<h4>not directly supported, but don't need it</h4>
<ul>
<li>
<p>
Currying treats every function as a single-argument function.
<br>
Given its one input, it returns a new function that takes the next one.
</p>
</li>
<li>
<p>
Currying is very nice, but not essential.
<br>
In Python, we can use libraries to give us some of these features.
</p>
</li>
</ul>
</section>
</section>
<section id="application4">
<section>
<h2>Application 4<span class="fragment">: Core and Crust</span></h2>
<h4 class="fragment">designing entire apps with FP</h4>
<div class="fragment">
<img src="img/core-crust.jpg" style="width: 50%; height: auto">
<a class="reference" href="http://www.sciencedaily.com/releases/2013/10/131010142750.htm">ref</a>
</div>
</section>
<section>
<h3>Pure Core / Thin Effectful Crust</h3>
<img src="img/wheel.jpg">
<p class="fragment">
Push as much "impure" code into the crust, including:
</p>
<ul>
<li class="fragment">human interaction</li>
<li class="fragment">file I/O</li>
<li class="fragment">networking</li>
<li class="fragment">time</li>
</ul>
</section>
<section>
<h3>Dependency Injection / Parametric Design</h3>
<p>
Avoiding mutation essentially forces you to build parametric components,
<br>
i.e. pieces that require their dependencies before they can be used.
</p>
</section>
</section>
<section>
<section>
<h2>Application 5<span class="fragment">: Verifiable Correctness</span></h2>
<h4 class="fragment">testing expressions</h4>
<div class="fragment">
<img src="img/wave.jpg" style="width: 60%; height: auto">
<a class="reference" href="http://commons.wikimedia.org/wiki/File:Oscilloscope_Triangle_Wave.jpg">ref</a>
</div>
</section>
<section>
<h3>Why Expressions Rock for Testing</h3>
<ul>
<li>Time is in your hands: start, stop, fast-forward, rewind</li>
<li>Zooming: see parts working at any layer</li>
<li>Property-based: you can write your tests in terms of properties instead of inputs</li>
<li>Proofs: you can write formal proofs</li>
</ul>
</section>
</section>
<section id="scratch">
<h2>Lots more...</h2>
<h3>we're only just getting started</h3>
<ul>
<li>Algebraic data types</li>
<li>Pattern matching</li>
<li>Lazy data structures (infinite lists, etc.)</li>
<li>Functors, Monads, etc.</li>
<li>Concurrency / Parallelism</li>
</ul>
</section>
<section id="others">
<h2>Don't believe me?</h2>
<h3>try asking</h3>
<ul>
<li>Edsger Dijkstra</li>
<li>Joel Spolsky</li>
<li>Uncle Bob Martin (author of Clean Code, etc.)</li>
<li>of course, many others</li>
</ul>
</section>
<section id="disclaimer">
<h2>Disclaimer</h2>
<p>
Don't confuse your experience of functional programming in Python with functional programming in general.
</p>
<p>
Python's design is not intentionally supportive of FP, so the experience suffers to some degree.
</p>
<p>
<a href="http://stackoverflow.com/a/1017937/503377">more on <em>why</em> this is the case</a>
</p>
</section>
<section id="every-day">
<h2>Every-day life</h2>
<p>
<a href="https://github.com/kachayev/fn.py">fn.py</a> is a great start.
</p>
<p>
Go forth and code.
</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 at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
math: {
// mathjax: 'http://cdn.mathjax.org/mathjax/latest/MathJax.js',
config: 'TeX-AMS_HTML-full'
},
// Optional reveal.js plugins
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/math/math.js', async: true }
]
});
</script>
</body>
</html>