-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
430 lines (376 loc) · 17.3 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Flow and static types for JavaScript</title>
<meta name="description" content="Conference headline">
<meta name="author" content="Your Name">
<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">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/futurice.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<style>
li { height: auto; line-height: 1.4; margin-bottom: 0.5em !important; }
.align-center { text-align: center; }
</style>
<!-- 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]-->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-34919939-1', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section data-background="img/bg01.png" class="futurice-front1">
<img class="futulogo" src="img/futulogo.png">
<h1>Flow</h1>
<p>and static types for JavaScript</p>
<p style="color: #aaa; margin-top: 1em;">Frontend Weeklies, 2014-12-05</p>
</section>
<section data-background="img/bg03.png" class="futurice-front1">
<h2 style="color:white">Background</h2>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<ul>
<li>We are sloppy programmers</li>
<li>We work with weak types and language quirks</li>
<li>We rely on tools and conventions to keep our sanity</li>
<li>We hate writing documentation</li>
</ul>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<p>Maintaining large JavaScript codebases takes effort</p>
<ul style="margin-top:1em">
<li>Lots of stupid unit tests</li>
<li>Extensive code reviews</li>
<li>Meticulous focus on conventions</li>
</ul>
</section>
<section data-background="img/bg03.png" class="futurice-front1">
<h2 style="color:white">Static Types</h2>
<p style="color:white">some options</p>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Dart</h2>
<ul>
<li>OO</li>
<li>Optional static types</li>
<li>Checked/production mode to toggle runtime checking</li>
<li>Generics</li>
<li>Compile to JS, run in Dartium, or use in Dart VM</li>
<li>Futures, Streams</li>
<li>async/await (also coming to ES7, see Scala/C# for examples)</li>
</ul>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<pre><code>import 'dart:io';
import 'dart:async';
void printDailyNewsDigest() {
File file = new File("dailyNewsDigest.txt");
Future future = file.readAsString();
future.then((content) {
print(content);
});
}</code></pre>
<p class="align-center"><a href="https://www.dartlang.org/docs/tutorials/futures/">www.dartlang.org/docs/tutorials/futures/</a></p>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>AtScript</h2>
<ul>
<li>Coming to AngularJS 2.0</li>
<li>Type annotations</li>
<li>Metadata annotations</li>
<li>Runtime type checking (DI needs it)</li>
<li>Compile to ES5 or Dart</li>
</ul>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<pre><code>@Component({selector: 'foo'})
class MyComponent {
@Inject()
constructor(server:Server) {}
}</code></pre>
<p class="align-center"><a href="http://www.2ality.com/2014/10/typed-javascript.html">www.2ality.com/2014/10/typed-javascript.html</a></p>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>TypeScript</h2>
<ul>
<li>JavaScript superset (aiming to be superset of ES6 in 2.0)</li>
<li>(Optional) type annotations</li>
<li>Generics</li>
<li>Interfaces/structural types</li>
<li>OO stuff</li>
<li>Compile time type checking</li>
</ul>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<pre><code class="typescript">interface Person {
firstname: string;
lastname: string;
}
function greeter(person : Person) {
return "Hello, " + person.firstname + " " + person.lastname;
}
var user = {firstname: "Jane", lastname: "User"};
document.body.innerHTML = greeter(user);</code></pre>
<p class="align-center"><a href="http://www.typescriptlang.org/Tutorial">www.typescriptlang.org/Tutorial</a></p>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>.d.ts files</h2>
<pre><code class="typescript">declare module Rx {
export interface Observable<T> {
(dueTime: Date, scheduler?: IScheduler): Observable<T>;
delay(dueTime: number, scheduler?: IScheduler): Observable<T>;
throttle(dueTime: number, scheduler?: IScheduler): Observable<T>;
timeInterval(scheduler?: IScheduler): Observable<TimeInterval<T>>;
timestamp(scheduler?: IScheduler): Observable<Timestamp<T>>;
sample(interval: number, scheduler?: IScheduler): Observable<T>;
sample<TSample>(sampler: Observable<TSample>, scheduler?: IScheduler): Observable<T>;
timeout(dueTime: Date, other?: Observable<T>, scheduler?: IScheduler): Observable<T>;
timeout(dueTime: number, other?: Observable<T>, scheduler?: IScheduler): Observable<T>;
}
}</code></pre>
<p class="align-center"><a href="http://definitelytyped.org/">definitelytyped.org</a></p>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<blockquote cite="http://baishakhir.github.io/uploads/fse2014-lang_study.pdf">
"However, in practice, we notice that developers often—for
50% of all variables—use the `any` type, thus making
TypeScript dynamic and weak"
</blockquote>
<p style="text-align:center;font-size:0.8em">
<a href="http://baishakhir.github.io/uploads/fse2014-lang_study.pdf">baishakhir.github.io/uploads/fse2014-lang_study.pdf</a>
</p>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Flow</h2>
<ul>
<li>JavaScript type checker</li>
<li>Built in OCaml (Steve Yegge must be smiling)</li>
<li>Built to scale to large codebases</li>
<li>Focus on type inference</li>
<li>Gradual type system</li>
<li>jsx compiler used for type erasure (i.e. only compile time type checking)</li>
<li>Attempts to be close to the normal JS workflow</li>
</ul>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<pre><code>/* @flow */
function foo(x) {
return x * 10;
}
foo('Hello, world!');</code></pre>
<pre><code>$> cd flow/examples/01_HelloWorld
$> flow check</code></pre>
<pre><code>01_HelloWorld/hello.js:7:5,17: string
This type is incompatible with
01_HelloWorld/hello.js:4:10,13: number</code></pre>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Flow</h2>
<ul>
<li>Optional (except in module exports) TypeScript type annotations</li>
<li>Tuples</li>
<li>Structural types</li>
<li>Subtyping (extends, prototypes)</li>
<li>Polymorphic classes and functions (generics)</li>
</ul>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Flow</h2>
<ul>
<li>Union types</li>
<li>Maybe types (nullable types)</li>
<li>Declarations (not compatible with .d.ts files ATM)</li>
<li>Supports React's propTypes</li>
</ul>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Generics</h2>
<pre><code>function id(x) {
return x;
}</code></pre>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Generics</h2>
<pre><code>function id<T>(x: T): T {
return x;
}</code></pre>
<p class="align-center">See <a href="https://github.com/tonymorris/parametricity">Parametricity</a> by <a href="https://twitter.com/dibblego">@dibblego</a> for an explanation why generic functions are awesome</p>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Maybe Types</h2>
<pre><code>/* @flow */
var o = null;
print(o.x);</code></pre>
<pre><code>file.js:3:7,9: property x
Property cannot be accessed on possibly null value
file.js:2:9,12: null</code></pre>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Maybe Types</h2>
<pre><code>/* @flow */
function length(x) {
return x.length;
}
var total = length('Hello') + length(null);</code></pre>
<pre><code>03_Null/nulls.js:4:10,17: property length
Property cannot be accessed on possibly null value
03_Null/nulls.js:7:38,41: null</code></pre>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Maybe Types</h2>
<pre><code>/* @flow */
function length(x) {
if (x !== null) {
return x.length;
} else {
return 0;
}
}
var total = length('Hello') + length(null);</code></pre>
</section>
<section data-background="img/bg03.png" class="futurice-front1">
<h2 style="color:white">Example: ES6 Promises</h2>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>The API</h2>
<pre><code>declare class Promise {
constructor(callback);
then(onFulfill, onReject);
catch(onReject);
static cast(object);
static resolve(object);
static reject(error);
static all(promises);
static race(promises);
}</code></pre>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Let's add some annotations</h2>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Generics</h2>
<pre><code>declare class Promise<R> {
constructor(callback): void; // void instead of Promise<R> in Flow core?
then<U>(onFulfill, onReject): Promise<U>;
}</code></pre>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Functions</h2>
<pre><code>declare class Promise<R> {
constructor(callback: (resolve: (result: R) => void,
reject: (error: any) => void) => void): void;
// why any instead of Error in Flow core?
then<U>(onFulfill, onReject): Promise<U>;
}</code></pre>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Union types</h2>
<pre><code>declare class Promise<R> {
constructor(callback: (resolve: (result: R) => void,
reject: (error: any) => void) => void): void;
then<U>(onFulfill?: (value: R) => Promise<U> | U,
onReject?: (error: any) => Promise<U> | U): Promise<U>;
}</code></pre>
<p class="align-center">Note map vs. monadic bind (flatMap) in the then handler!</p>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Full annotated API</h2>
<pre><code>declare class Promise<R> {
constructor(callback: (resolve: (result: R) => void,
reject: (error: any) => void) => void): void;
then<U>(onFulfill?: (value: R) => Promise<U> | U,
onReject?: (error: any) => Promise<U> | U): Promise<U>;
catch<U>(onReject?: (error: any) => U): Promise<U>;
static cast<T>(object?: T): Promise<T>;
static resolve<T>(object?: T): Promise<T>;
static reject(error?: any): Promise<any>;
static all<T>(promises: Array<Promise<T>>): Promise<Array<T>>;
static race<T>(promises: Array<Promise<T>>): Promise<T>;
}</code></pre>
<p class="align-center"><a href="https://github.com/facebook/flow/blob/master/lib/core.js">github.com/facebook/flow/blob/master/lib/core.js</a></p>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Summary</h2>
<ul>
<li>Early warnings are good</li>
<li>Static types help in maintaining and refactoring code</li>
<li>Up-to-date documentation</li>
<li>Avoiding stupid unit tests</li>
<li>Good type inference is crucial for adoption</li>
</ul>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Future</h2>
<ul>
<li>Linting taken to the next level</li>
<li>Optional type annotations are considered for ES7, but introducing them is very difficult</li>
<li>AtScript, TypeScript, and Flow developers are working together \o/</li>
</ul>
</section>
<section data-background="img/bg02.png" class="futurice-front1">
<h2>Resources</h2>
<ul>
<li><a href="https://www.dartlang.org/">www.dartlang.org</a></li>
<li><a href="http://www.typescriptlang.org/">www.typescriptlang.org</a></li>
<li><a href="http://flowtype.org/">http://flowtype.org/</a></li>
<li><a href="http://www.2ality.com/2014/10/typed-javascript.html">Statically typed JavaScript via Microsoft TypeScript, Facebook Flow and Google AtScript</a> by <a href="https://twitter.com/rauschma">@rauschma</a></li>
<li><a href="https://github.com/tonymorris/parametricity">Parametricity</a> by <a href="https://twitter.com/dibblego">@dibblego</a> (link to pdf not working anymore)</li>
<li><a href="https://docs.google.com/document/d/11YUzC-1d0V1-Q3V0fQ7KSit97HnZoKVygDxpWzEYW0U/mobilebasic">AtScript Primer</a></li>
</ul>
</section>
<section data-background="img/bg08.png" class="futurice-front1">
<h2 class="align-center"style="color:white">Thanks!</h2>
<p class="align-center"><a href="https://twitter.com/kpuputti">@kpuputti</a></p>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: false,
progress: true,
history: true,
center: true,
transition: 'linear',
// 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>