This repository has been archived by the owner on Sep 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
4027 lines (3947 loc) · 181 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
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Austin.RB - Ruby to Elixir</title>
<meta name="description" content="Ruby to Elixir at Austin.RB">
<meta name="author" content="Luke Imhoff">
<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/theme/black.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">
<section>
<h1>Austin.RB</h1>
<h2>Ruby to Elixir</h2>
<p>2015-08-03</p>
<p>Luke Imhoff</p>
<table>
<tbody>
<tr>
<th>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" width="14px" height="10px" viewBox="0 0 14 10" enable-background="new 0 0 14 10" xml:space="preserve">
<g>
<path d="M7,7L5.268,5.484L0.316,9.729C0.496,9.896,0.739,10,1.007,10h11.986c0.267,0,0.509-0.104,0.688-0.271L8.732,5.484L7,7z"></path>
<path d="M13.684,0.271C13.504,0.103,13.262,0,12.993,0H1.007C0.74,0,0.498,0.104,0.318,0.273L7,6L13.684,0.271z"></path>
<polygon points="0,0.878 0,9.186 4.833,5.079 "></polygon>
<polygon points="9.167,5.079 14,9.186 14,0.875 "></polygon>
</g>
</svg>
</th>
<td>luke_imhoff@rapid7.com</td>
<td>Kronic.Deth@gmail.com</td>
</tr>
<tr>
<th>
<svg version="1.1" class="github-icon-svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<path fill-rule="evenodd" clip-rule="evenodd" fill="#C2C2C2" d="M7.999,0.431c-4.285,0-7.76,3.474-7.76,7.761
c0,3.428,2.223,6.337,5.307,7.363c0.388,0.071,0.53-0.168,0.53-0.374c0-0.184-0.007-0.672-0.01-1.32
c-2.159,0.469-2.614-1.04-2.614-1.04c-0.353-0.896-0.862-1.135-0.862-1.135c-0.705-0.481,0.053-0.472,0.053-0.472
c0.779,0.055,1.189,0.8,1.189,0.8c0.692,1.186,1.816,0.843,2.258,0.645c0.071-0.502,0.271-0.843,0.493-1.037
C4.86,11.425,3.049,10.76,3.049,7.786c0-0.847,0.302-1.54,0.799-2.082C3.768,5.507,3.501,4.718,3.924,3.65
c0,0,0.652-0.209,2.134,0.796C6.677,4.273,7.34,4.187,8,4.184c0.659,0.003,1.323,0.089,1.943,0.261
c1.482-1.004,2.132-0.796,2.132-0.796c0.423,1.068,0.157,1.857,0.077,2.054c0.497,0.542,0.798,1.235,0.798,2.082
c0,2.981-1.814,3.637-3.543,3.829c0.279,0.24,0.527,0.713,0.527,1.437c0,1.037-0.01,1.874-0.01,2.129
c0,0.208,0.14,0.449,0.534,0.373c3.081-1.028,5.302-3.935,5.302-7.362C15.76,3.906,12.285,0.431,7.999,0.431z"></path>
</svg>
</th>
<td>
<a href="https://github.com/limhoff-r7" target="_blank">@limhoff-r7</a>
</td>
<td>
<a href="https://github.com/KronicDeth" target="_blank">@KronicDeth</a>
</td>
</tr>
<tr>
<th>
<svg version="1.1" class="twitter-icon-svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<path fill="#C2C2C2" d="M15.969,3.058c-0.586,0.26-1.217,0.436-1.878,0.515c0.675-0.405,1.194-1.045,1.438-1.809
c-0.632,0.375-1.332,0.647-2.076,0.793c-0.596-0.636-1.446-1.033-2.387-1.033c-1.806,0-3.27,1.464-3.27,3.27
c0,0.256,0.029,0.506,0.085,0.745C5.163,5.404,2.753,4.102,1.14,2.124C0.859,2.607,0.698,3.168,0.698,3.767
c0,1.134,0.577,2.135,1.455,2.722C1.616,6.472,1.112,6.325,0.671,6.08c0,0.014,0,0.027,0,0.041c0,1.584,1.127,2.906,2.623,3.206
C3.02,9.402,2.731,9.442,2.433,9.442c-0.211,0-0.416-0.021-0.615-0.059c0.416,1.299,1.624,2.245,3.055,2.271
c-1.119,0.877-2.529,1.4-4.061,1.4c-0.264,0-0.524-0.015-0.78-0.046c1.447,0.928,3.166,1.469,5.013,1.469
c6.015,0,9.304-4.983,9.304-9.304c0-0.142-0.003-0.283-0.009-0.423C14.976,4.29,15.531,3.714,15.969,3.058z"></path>
</svg>
</th>
<td></td>
<td>
<a href="https://twitter.com/KronicDeth" target="_blank">@KronicDeth</a>
</td>
</tr>
</tbody>
</table>
<aside class="notes">
I am a Senior Software Engineer on the Metasploit Architecture team at Rapid7. In my spare
time, I maintain IntelliJ Elixir, the Elixir plugin for Jetbrains IDEs like IntelliJ and
Rubymine.
</aside>
</section>
<section>
<h1>Outline</h1>
<ol>
<li>
<a href="#/overview">Overview</a>
</li>
<li>
<a href="#/installation">Installation</a>
</li>
<li>
<a href="#/interactive">Interactive</a>
</li>
<li>
<a href="#/types">Types</a>
</li>
<li>
<a href="#/control-flow">Control Flow</a>
</li>
<li>
<a href="#/pattern-matching">Pattern Matching</a>
</li>
<li>
<a href="#/project">Project</a>
</li>
<li>
<a href="#/code">Code</a>
</li>
<li>
<a href="#/testing">Testing</a>
</li>
<li>
<a href="#/metaprogramming">Metaprogramming</a>
</li>
<li>
<a href="#/concurrency">Concurrency</a>
</li>
<li>
<a href="#/resources">Resources</a>
</li>
<li>
<a href="#/upcoming-dates">Upcoming Dates</a>
</li>
</ol>
</section>
<section class="stack">
<section id="overview">
<h1>Overview</h1>
<table>
<thead>
<tr>
<th></th>
<th></th>
<th>Ruby</th>
<th>Elixir</th>
</tr>
</thead>
<tbody>
<tr>
<th rowspan="4">Paradigms</th>
<th>Imperative</th>
<td>✓</td>
<td></td>
</tr>
<tr>
<th>Concurrent</th>
<td></td>
<td>✓</td>
</tr>
<tr>
<th>Functional</th>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th>Object-Oriented</th>
<td>✓</td>
<td></td>
</tr>
<tr>
<th rowspan="3">Typing</th>
<th>Dynamic</th>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<th>Duck</th>
<td>✓</td>
<td></td>
</tr>
<tr>
<th>Strong</th>
<td></td>
<td>✓</td>
</tr>
<tr>
<th colspan="2">Mutability</th>
<td>Mutable</td>
<td>Immutable</td>
</tr>
<tr>
<th rowspan="2">Concurrency</th>
<th>CPU-bound</th>
<td>OS Processes</td>
<td>VM Processes</td>
</tr>
<tr>
<th>IO-bound</th>
<td>Threads, Fibers</td>
<td>VM Processes</td>
</tr>
<tr>
<th colspan="2">Metaprogramming</th>
<td>Runtime, Class Methods</td>
<td>Compilation, Macros</td>
</tr>
</tbody>
</table>
<aside class="notes">
<p>
Elixir is a functional language that is dynamically typed using immutable
data that is highly concurrent.
</p>
<p>
MRI Ruby's go-to concurrency approach of forking a process has too high of a overhead and is
only tolerable on system with Copy-On-Write (COW) fork, which excludes Windows. Threading
and fibers in the MRI cannot get around the GIL and so only help with IO-bound code.
</p>
<p>
On the other hand, Elixir uses the Erlang VM, which thanks to the immutable data, can run
isolated processes inside the VM so fast and so cheaply that my laptop can use as many
as I want effectively and use a separate one for each logically concurrent task.
</p>
<p>
Just as you learned imperative programming over mathematical thinking, you can retrain
to think in functional languages and even switch back and forth. I currently switch
between Java, Ruby, and Elixir. With only a few hiccups on namespace syntax and
string quoting. If you're used to using <code>map</code> or <code>select</code> from
<code>Enumerable</code> in Ruby, you are already using functional programming. If you
ever used class methods in Ruby that didn't write to class or instance variable, you're
already using functional programming.
</p>
<p>
Learning functional programming will also prepare you for the future. If you watch
conference talks in other languages, such as Javascript or C++, languages are moving to
have more and more functional features as the programming community adapts to the
many-cores future. They have figured out that locks, threads, and shared mutable
state is too error prone.
</p>
<p>
Moore's law increasing processor speed stopped 10 years ago. If you want to take
advantage of Moore's law now and in the future you need to write concurrent programs now
that can be parallelized across the additional cores of the future automatically.
</p>
<p>
Switching from imperative, mutable, object-oriented Ruby to functional, immutable,
concurrent Elixir may be intimidating, but I'll show you how easy it is to translate your
Ruby skills to Elixir to quickly get started learning Elixir on your own.
</p>
</aside>
</section>
</section>
<section class="stack">
<section id="installation">
<h1>Installation</h1>
<ul>
<li><a href="#/installation-osx">OSX</a></li>
<li><a href="#/installation-windows">Windows</a></li>
<li><a href="#/installation-linux">Linux</a></li>
</ul>
</section>
<section id="installation-osx">
<h1>OSX</h1>
<table>
<thead>
<tr>
<th></th>
<th>Ruby</th>
<th>Elixir</th>
</tr>
</thead>
<tbody>
<tr>
<td>Homebrew</td>
<td>
<code>brew install ruby</code>
</td>
<td>
<code>brew install elixir</code>
</td>
</tr>
<tr>
<td>Version Manager</td>
<td>
<code>rvm install VERSION</code>
</td>
<td>
<code>kiex install VERSION</code>
</td>
</tr>
</tbody>
</table>
<aside class="notes">
<p>
Ruby and Elixir both have homebrew packages and version managers.
</p>
<p>
If you use <code>kiex</code>, you'll need to install Erlang separately using either
<code>kerl</code>, spelled K-E-R-L, or homebrew
</p>
</aside>
</section>
<section id="installation-windows">
<h1>Windows</h1>
<table>
<thead>
<tr>
<th></th>
<th>Ruby</th>
<th>Elixir</th>
</tr>
</thead>
<tbody>
<tr>
<td>Installer</td>
<td>
<a href="http://rubyinstaller.org/">
<code>rubyinstaller.exe</code>
</a>
</td>
<td>
<a href="https://s3.amazonaws.com/s3.hex.pm/elixir-websetup.exe">
<code>elixir-websetup.exe</code>
</a>
</td>
</tr>
<tr>
<td>Chocolatey</td>
<td>
<code>cinst ruby</code>
</td>
<td>
<code>cinst elixir</code>
</td>
</tr>
</tbody>
</table>
<aside class="notes">
<p>
Both Ruby and Elixir have installers for installing the languages as a Program in Windows.
</p>
<p>
You can alternatively use the Chocolatey (or NuGET) package manager for Windows.
</p>
</aside>
</section>
<section id="installion-linux">
<h1>Linux</h1>
<p>Use your package manager</p>
</section>
</section>
<section class="stack">
<section id="interactive">
<h1>Interactive</h1>
<ul>
<li>
<a href="#/interactive-starting">Starting</a>
</li>
<li>
<a href="#/interactive-breaking">Breaking</a>
</li>
<li>
<a href="#/interactive-exiting">Exiting</a>
</li>
</ul>
</section>
<section id="interactive-starting">
<h1>
Starting Interactive
</h1>
<table>
<thead>
<tr>
<th>Ruby</th>
<th>Elixir</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>irb</code>
</td>
<td>
<code>iex</code>
</td>
</tr>
</tbody>
</table>
</section>
<section id="interactive-breaking">
<h1>Breaking the current command</h1>
<table>
<thread>
<tr>
<th>Ruby</th>
<th>Elixir</th>
</tr>
</thread>
<tbody>
<tr>
<th>CTRL+C</th>
<th><code>#iex:break</code> on line by itself</th>
</tr>
</tbody>
</table>
<aside class="notes">
If you make a typing mistake in <code>irb</code>, you're probably used to hitting CTRL+C,
but if you do that in <code>iex</code> you'll get a prompt asking whether to abort, continue,
kill, and some other options. To mimic the behavior of CTRL+C from <code>irb</code>, type
the comment <code>iex</code> colon <code>break</code> on a line by itself.
</aside>
</section>
<section id="interactive-exiting">
<table>
<thread>
<tr>
<th>Ruby</th>
<th>Elixir</th>
</tr>
</thread>
<tbody>
<tr>
<th><code>exit</code></th>
<th>CTRL+C CTRL+C</th>
</tr>
</tbody>
</table>
<aside class="notes">
A single CTRL+C in <code>iex</code> will bring up the break handler, which allows you to
inspect the running VM and kill individual processes.
</aside>
</section>
</section>
<section class="stack">
<section id="types">
<h1>Types</h1>
<ul>
<li>
<a href="#/types-numeric">Numeric</a>
</li>
<li>
<a href="#/types-constant">Constant</a>
</li>
<li>
<a href="#/types-boolean">Boolean</a>
</li>
<li>
<a href="#/types-string">String</a>
</li>
<li>
<a href="#/types-regular-expression">Regular Expression</a>
</li>
<li>
<a href="#/types-anonymous-function">Anonymous Function</a>
</li>
<li>
<a href="#/types-collection">Collection</a>
</li>
</ul>
</section>
<section id="types-numeric">
<h1>Numeric Types</h1>
<table>
<thead>
<tr>
<th colspan="2">Ruby</th>
<th colspan="2">Elixir</th>
</tr>
<tr>
<th>Name</th>
<th>Example</th>
<th>Name</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>Integer</td>
<td>
<code>9</code>, <code>0b1</code>, <code>0o7</code>, <code>0xF</code>
</td>
<td>Integer</td>
<td>
<code>9</code>, <code>0b1</code>, <code>0o7</code>, <code>0xF</code>
</td>
</tr>
<tr>
<td>Float</td>
<td>
<code>1.2</code>, <code>3e+0</code>
</td>
<td>float</td>
<td>
<code>1.2</code>, <code>3e+0</code>
</td>
</tr>
</tbody>
</table>
<aside class="notes">
<p>
Integer formats are the same for Ruby and Elixir. They both support, decimal, binary,
octal, and hexadecimal. Underscore (_) can be used to separate digit groups.
</p>
<p>
Float formats are the same for Ruby and Elixir. They both support 'e' notation.
</p>
</aside>
</section>
<section id="types-constant">
<h1>Constant Types</h1>
<table>
<thead>
<tr>
<th colspan="2">Ruby</th>
<th colspan="2">Elixir</th>
</tr>
<tr>
<th>Name</th>
<th>Example</th>
<th>Name</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>Symbol</td>
<td>
<code>:symbol</code>, <code>:"symbol"</code>, <code>:'symbol'</code>
</td>
<td>Atom</td>
<td>
<code>:atom</code>, <code>:"atom"</code>, <code>:'atom'</code>
</td>
</tr>
<tr>
<td>Class/Module name</td>
<td>
<code>MyClass</code>, <code>MyNamespace::MyModule</code>
</td>
<td>Alias</td>
<td>
<code>MyModule</code>, <code>MyNamespace.MyModule</code>, <code>:erlang_module</code>
</td>
</tr>
<tr>
<td>Constant</td>
<td>
<code>MY_CONSTANT</code>
</td>
<td>Module Attribute</td>
<td>
<code>@my_attribute</code>
</td>
</tr>
</tbody>
</table>
<aside class="notes">
<p>
Symbol in Ruby just becomes the word Atom in Elixir.
</p>
<p>
Class/Module names and Aliases both share camel-casing, but namespaces in Class/Module
names are separated with colon-colon (::), while Alias names are separated with dot (.).
Additionally, Erlang modules are just atoms. Aliases are called Aliases because they
are actually syntactic sugar with an atom starting with Elixir dot (Elixir.)
</p>
<p>
Your brain may read module attributes as being like class instance variables in Ruby
since they both start with at (@) and look like a variable, but module attributes don't
get assigned to with equals (=), instead they are referenced before the value to put into
the module attribute. This is because module attributes can be configured to either
reset their value or accumulate all values passed to them. This allows for some nice
features, which I'll get to later.
</p>
</aside>
</section>
<section id="types-boolean">
<h1>Boolean Types</h1>
<table>
<thead>
<tr>
<th>Ruby</th>
<th>Elixir</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>false</code>
</td>
<td>
<code>false</code>, <code>:false</code>
</td>
</tr>
<tr>
<td>
<code>nil</code>
</td>
<td>
<code>nil</code>, <code>:nil</code>
</td>
</tr>
<tr>
<td>
<code>true</code>
</td>
<td>
<code>true</code>, <code>:true</code>
</td>
</tr>
</tbody>
</table>
<aside class="notes">
<p>
In Elixir, false, nil, and true are all just syntactic sugar for the atoms of the same
name.
</p>
<p>
Both Ruby and Elixir has falsy logic, so both false and nil are false for boolean
operations.
</p>
</aside>
</section>
<section id="types-string">
<h1>Strings</h1>
<table>
<thead>
<tr>
<th></th>
<th colspan="2">Ruby</th>
<th colspan="2">Elixir</th>
</tr>
</thead>
<tbody>
<tr>
<th>Format</th>
<td>
<code>"string"</code>
</td>
<td></td>
<td>
<code>"string"</code>
</td>
<td></td>
</tr>
<tr>
<th>Interpolation</th>
<td>
<code>"Hello #{:world}"</code>
</td>
<td>✓</td>
<td>
<code>"Hello #{:world}"</code>
</td>
<td>✓</td>
</tr>
<tr>
<th>Encoding</th>
<td>UTF-8</td>
<td></td>
<td>UTF-8</td>
<td></td>
</tr>
<tr>
<th>Unicode Capitalization</th>
<td>
<code>"José Valim".upcase # "JOSé VALIM"</code>
</td>
<td>❌</td>
<td>
<code>String.upcase "José Valim" # "JOSÉ VALIM"</code>
</td>
<td>✓</td>
</tr>
<tr>
<th>Unicode Graphemes Rendering</th>
<td>
<code>"\u0065\u0301" # "é"</code>
</td>
<td>✓</td>
<td>
<code>"\x{0065}\x{0301}" # "é"</code>
</td>
<td>✓</td>
</tr>
<tr>
<th>Unicode Graphemes Length</th>
<td>
<code>"\u0065\u0301".length # 2</code>
</td>
<td>❌</td>
<td>
<code>String.length "\x{0065}\x{0301}" # 1</code>
</td>
<td>✓</td>
</tr>
</tbody>
</table>
<aside class="notes">
<p>
Ruby and Elixir support double quoted strings with interpolation encoded as UTF-8
</p>
<p>
Elixir excels at proper unicode handling compared to Ruby: Elixir properly capitalizes
e-acute (é) in José Valim while Ruby does not; Elixir properly handles the separate
e and acute accent being one grapheme while Ruby counts them as 2 characters for the
string length.
</p>
<p>
If you care about what the user actually sees, you want the number of graphemes in a
string, not the raw bytes, so Elixir's approach is correct.
</p>
</aside>
</section>
<section id="types-regular-expression">
<h1>Regular Expressions</h1>
<table>
<thead>
<tr>
<th></th>
<th>Ruby</th>
<th>Elixir</th>
</tr>
</thead>
<tbody>
<tr>
<th>Literals</th>
<td>
<ul>
<li>
<code>/[A-Z]+/</code>
</li>
<li>
<code>%r{[A-Z]+}</code>
</li>
</ul>
</td>
<td>
<ul>
<li>
<code>~r{[A-Z]+}</code>
</li>
<li>
<code>~r[(.*)]</code>
</li>
<li>
<code>~r<[A-Z]+></code>
</li>
<li>
<code>~r"[A-Z]+"</code>
</li>
<li>
<code>~r/[A-Z]+/</code>
</li>
<li>
<code>~r([A-Z]+)</code>
</li>
<li>
<code>~r|[A-Z]+|</code>
</li>
<li>
<code>~r'[A-Z]+'</code>
</li>
</ul>
</td>
</tr>
<tr>
<th>Compile</th>
<td>
<code>Regexp.new "string"</code>
</td>
<td>
<code>Regexp.compile! "string"</code>
</td>
</tr>
<tr>
<th>Replace</th>
<td>
<pre><code class="ruby">
'`spec` is a task for `rake`'.gsub(
/`(.*?)`/,
'<code>\1</code>'
) # "<code>test</code> is a task for <code>rake</code>"
</code></pre>
</td>
<td>
<pre><code class="elixir">
Regex.replace(
~r/`(.*?)`/,
"`test` is a task for `mix`",
"<code>\\1</code>"
) # <code>test</code> is a task for <code>mix</code>"
</code></pre>
</td>
</tr>
</tbody>
</table>
<aside class="notes">
Unlike Ruby, which only allows
</aside>
</section>
<section id="types-anonymous-function">
<h1>Anonymous Functions</h1>
<table>
<thead>
<tr>
<th></th>
<th>Ruby</th>
<th>Elixir</th>
</tr>
</thead>
<tbody>
<tr>
<td>Declaration</td>
<td>
<ul>
<li>
<code>add = ->(a,b){ a + b }</code>
</li>
<li>
<code>add = lambda { |a,b| a + b }</code>
</li>
<li>
<code>add = proc { |a,b| a + b }</code>
</li>
<li>
<code>add = Proc.new { |a, b| a + b}</code>
</li>
</ul>
</td>
<td>
<ul>
<li>
<code>add = fn a, b -> a + b end</code>
</li>
<li>
<code>add = fn (a, b) -> a + b end</code>
</li>
<li>
<code>add = &(&1 + &2)</code>
</li>
</ul>
</td>
</tr>
<tr>
<td>Calling</td>
<td>
<ul>
<li>
<code>add.call(1,2)</code>
</li>
<li>
<code>add.call 1, 2</code>
</li>
<li>
<code>add.(1,2)</code>
</li>
<li>
<code>add[1,2]</code>
</li>
</ul>
</td>
<td>
<ul>
<li>
<code>add.(1,2)</code>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</section>
<section id="types-collection">
<h1>Collections</h1>
<table>
<thead>
<tr>
<th colspan="2">Ruby</th>
<th colspan="2">Elixir</th>
</tr>
<tr>
<th>Name</th>
<th>Example</th>
<th>Name</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>Array</td>
<td>
<code>[1,2,3]</code>
</td>
<td>Tuple</td>
<td>
<code>[1,2,3]</code>
</td>
</tr>
<tr>
<td>Hash</td>
<td>
<ul>
<li>
<code>{a: 1, b: 2}</code>
</li>
<li>
<code>{:a => 1, :b => 2}</code>
</li>
</ul>
</td>
<td>Map</td>
<td>
<ul>
<li>
<code>%{a: 1, b: 2}</code>
</li>
<li>
<code>%{:a => 1, :b => 2}</code>
</li>
</ul>
</td>
</tr>
<tr>
<td>Set</td>
<td>
<code>Set.new [1,2,3]</code>
</td>
<td>HashSet</td>
<td>
<code>Enum.into [1,2,3], HashSet.new</code>
</td>
</tr>
<tr>
<td>❌</td>
<td>❌</td>
<td>Linked List</td>
<td>
<ul>
<li>
<code>[1,2,3]</code>
</li>
<li>
<code>[1 | [2 | [3 | []]]]</code>
</li>
</ul>
</td>
</tr>
<tr>
<td>❌</td>
<td>❌</td>
<td>Keyword List</td>
<td>
<ul>
<li>
<code>[a: 1, a: 2, b: 3]</code>
</li>
<li>
<code>[{:a, 1}, {:a, 2}, {:b, 3}]</code>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<aside class="notes">
<p>
Arrays and tuples are both contiguous in memory, but tuples are a fixed size while Ruby
Arrays are resizable. Both allow lookup by index.
</p>
<p>
Both Set and HashSet are built on top of Hashes and don't support a built-in syntax
for initialization, and so here are populated using an Array and Linked List,
respectively.
</p>
<p>