-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
Β·162 lines (147 loc) Β· 6.79 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
<!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>Functional Programming in Python π</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/black.css">
<!-- Theme used for syntax highlighting of code -->
<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>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>Functional Programming in Python π</section>
<section>
<h2>About me</h2>
<p>Riccardo aka <a href="https://twitter.com/entropiae">@entropiae</a></p>
<p>Python in the streets<br>Erlang/Elixir (currently) in the sheets</p>
</section>
<section id="fragments">
<section>
<h2>Functional programming? π€</h2>
<p class="fragment">
(almost) every developer has its own idea about functional programming.
</p>
</section>
<section>
First-class functions
<aside class="notes">Permits to treat functions as data, passed to other functions</aside>
</section>
<section>
Higher-order functions
<aside class="notes">Functions whose accept other functions as arguments, return functions</aside>
</section>
<section>
Recursion instead of iteration
<p class="fragment">Focus on Tail Call Optimization</p>
<p class="fragment"><a href="http://neopythonic.blogspot.it/2009/04/final-words-on-tail-calls.html">(not available in Python π₯)</a>
</p>
</section>
<section>
Immutable data structures
</section>
<section>
Lazy evaluation
<pre>
<code data-trim data-noescape>len([1, 1/0, '3']) == 3</code>
</pre>
</section>
<section>
Emphasis on <b>what</b> is done, not on <s>how</s> is done
</section>
</section>
<section id="fragments">
<section>
<h2>Ok ok, functions.</h2>
</section>
<section>
(Mathematical) functions
</section>
<section>
Pure functions
<p class="fragment">No side effects</p>
<p class="fragment">Perfectly pure, almost useless</p>
<p class="fragment"><i>Practicality beats purity.</i></p>
</section>
<section>
Referential transparency
<p class="fragment">Memoization</p>
</section>
<section>
No order constraint
<p class="fragment">Full support for Multi{core, cpu, node} archs</p>
<p class="fragment">Compiler optimization</p>
</section>
</section>
<section>
<section><h2>Python as a functional programming language?</h2></section>
<section>Python is not, by design, a FP language</section>
<section>
However..
<p class="fragment">..coz everything is an object..</p>
<p class="fragment">..we have first-class functions! π</p>
</section>
<section>
1994: higher-order functions were introduced in Python
</section>
<section>
map: transform a collection
<pre><code data-trim data-noescape>map(lambda x: x + 1, [1, 2, 3]) == [2, 3, 4]</code></pre>
</section>
<section>
filter: remove elements from a collection
<pre><code data-trim data-noescape>filter(lambda x: x % 2 == 0, [1, 2, 3]) == [2]</code></pre>
</section>
<section>
reduce: recursively apply an operation on a collection
<pre><code data-trim data-noescape>reduce(lambda x, y: x + y, [1, 2, 3]) == 6</code></pre>
<p class="fragment">The cornestone of higher-order functions</p>
</section>
<section>
map() and filter() could be replaced with a list comprehension
<p class="fragment"><i>There should be one - and preferably only one - obvious way to do it.</i></p>
<p class="fragment">GvR doesn't like them π</p>
</section>
<section>
It was proposed to remove them from Python 3
</section>
<section>
More functions were build on these building blocks
<p class="fragment">functools, itertools</p>
</section>
</section>
<section>
<section>And now for something completely different</section>
<section>
Pietro will show us some code samples βοΈ
</section>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// More info https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
history: true,
// More info https://github.com/hakimel/reveal.js#dependencies
dependencies: [
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
]
});
</script>
</body>
</html>