-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
2121 lines (1904 loc) · 90.9 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>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>The When of Python - KiwiPycon 2022</title>
<link rel="stylesheet" href="dist/reset.css">
<link rel="stylesheet" href="dist/reveal.css">
<link rel="stylesheet" href="dist/theme/night.css">
<!-- Theme used for syntax highlighted code -->
<link rel="stylesheet" href="plugin/highlight/monokai.css">
<style>
.reveal .slides section.full-height {
height: 700px;
}
.reveal .slides section.full-height > article {
position: absolute;
top: 50%; left: 50%;
transform: translate(-50%, -50%);
}
.reveal .code-list {
margin: auto;
}
.reveal .code-list ul {
width: 100%;
}
.reveal .code-list ul pre.code-wrapper {
margin-left: 0;
}
.underline {
text-decoration: underline;
}
.highlight {
color: var(--r-link-color) !important;
}
.humble {
font-weight: normal;
font-size: 0.75em;
}
.reveal .slides section .fragment.highlight {
opacity: 1;
visibility: inherit;
color: inherit !important;
}
.reveal .slides section .fragment.highlight.visible {
color: var(--r-link-color) !important;
}
.when-of-python {
width: 100%;
height: 500px;
display: flex;
flex-direction: column;
}
.when-of-python > div {
position: relative;
height: 100%;
margin: 5px;
border-radius: 10px;
background: #111111;
border: 10px solid;
}
.when-of-python .never {
border-color: #F5363F;
flex: 5;
}
.when-of-python .sometimes {
border-color: #EBC334;
flex: 4;
}
.when-of-python .always {
border-color: #37FA71;
flex: 3;
}
.when-of-python article {
position: absolute;
font-size: 0.9em;
}
.when-of-python article.faded {
opacity: 0.2;
}
.when-of-python.no-faded article.faded {
opacity: 1;
}
.when-of-python article.fragment {
opacity: 1 !important;
visibility: visible !important;
transition: all 0.2s ease, font-weight 0s !important;
}
.when-of-python article.fragment.visible.current-fragment {
text-decoration: underline;
}
.when-of-python article.fragment.visible:not(.current-fragment) {
text-decoration: none;
}
.reveal label {
display: block;
padding: 15px;
border-radius: 15px;
position: absolute;
background: #333333;
font-size: 0.7em;
z-index: 1;
line-height: 1.1;
border: 4px solid var(--r-link-color);
}
.when-of-python label {
border-color: inherit;
opacity: 0 !important;
}
.when-of-python label.current-fragment {
opacity: 1 !important;
}
.when-of-python label pre.code-wrapper {
margin-bottom: 0;
font-size: 0.8em !important;
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h2>The <span class="highlight">When</span> of Python</h2>
<p class='humble'>Grant Paton-Simpson – 2degrees<br>Benjamin Denham – AUT PhD Candidate, DataMasque</p>
<aside class="notes" data-markdown>
* [**Grant to start talking**]
* Hi everyone, my name is Grant, and this is Ben
* Thanks for coming to our talk on The When of Python
* We've been thinking a lot about the future of Python over the past few months
* ... and we're really excited to share with you some ideas we've had
</aside>
</section>
<section>
<h2 style="font-size: calc(var(--r-heading2-size) * 0.95);">The Promise of Python:</h2>
<aside class="notes" data-markdown>
* So let's start off by considering one of the main promises of Python:
* That Python is...
* [*`CLICK`*] Simple
</aside>
</section>
<section class="full-height">
<style>
.quote {
position: absolute;
text-align: left;
font-size: 0.75em;
}
.quote > .text {
display: block;
font-style: italic;
}
.quote > .source {
display: block;
font-size: 0.75em;
}
</style>
<article>
<h1>Simple<span class="fragment empty" data-fragment-index="7"><span class="highlight">?</span></span></h1>
</article>
<div class="quote fragment" data-fragment-index="1" style="left: 500px; top: 150px;">
<span class="text">Friendly & Easy to Learn</span>
<span class="source">― python.org/about</span>
</div>
<div class="quote fragment" data-fragment-index="2" style="left: 30px; top: 490px;" width="400px">
<span class="text"><code>print('Hello, world!')</code></span>
</div>
<div class="quote fragment" data-fragment-index="3" style="left: 60px; top: 175px;">
<span class="text">Python Fits Your Brain</span>
<span class="source">― Guido's theme for Pycon 2001</span>
</div>
<div class="quote fragment" data-fragment-index="3" style="left: 350px; top: 600px;">
<span class="text">Beauty, Simplicity, Flexibility</span>
<span class="source">― Kiwi PyCon</span>
</div>
<div class="quote fragment" data-fragment-index="4" style="left: 0px; top: 50px;">
<span class="text">There should be one-- and preferably only one --obvious way to do it.</span>
<span class="source">― The Zen of Python</span>
</div>
<div class="quote fragment" data-fragment-index="4" style="left: 670px; top: 480px;">
<span class="text"><span class="fragment highlight" data-fragment-index="8">Readability</span> counts.</span>
<span class="source">― The Zen of Python</span>
</div>
<aside class="notes" data-markdown>
* [*`CLICK`*] It's a major selling point of the language
* [*`CLICK`*] We talk about how Hello World is so much simpler in Python than other languages
* We emphasize simplicity...
* [*`CLICK`*] at conferences
* [*`CLICK`*] and in the Zen of Python
* [*`CLICK`*] But is Python still simple?
* [*`CLICK`*] Well, readability is a big part of simplicity,
* ... so let's focus on that for a minute
</aside>
</section>
<section>
<h3>What is <span class="highlight">Readability</span>?</h3>
<p class="fragment">Armed with basic language knowledge <br>→ <em>rapidly</em> understand what code will do</p>
<aside class="notes" data-markdown>
* So what is readability?
* [*`CLICK`*] If code is readable,
* ... I should be able to quickly understand what code will do
* ... even if I only have a basic knowledge of the language.
</aside>
</section>
<section>
<h3>However, ever-expanding language features...</h3>
<ul>
<li class="fragment">
Provide more than "one obvious way"
</li>
<li class="fragment">
Make Python too big for your brain
</li>
<li class="fragment">
<span class="highlight">Hurt readability!</span>
</li>
</ul>
<aside class="notes" data-markdown>
* However, if you think about all the new features Python's been adding over the last few years...
* [*`CLICK`*] They provide more than **one** obvious way
* [*`CLICK`*] They make Python too big for your brain
* [*`CLICK`*] And therefore, they hurt readability!
</aside>
</section>
<section>
<p><code>namedtuple()</code></p>
<p>vs</p>
<p><code>NamedTuple</code></p>
<p>vs</p>
<p><code>@dataclass</code></p>
<aside class="notes" data-markdown>
* Consider namedtuples and data classes
* Three almost identical approaches to the same task in the standard library
</aside>
</section>
<section>
<p><code>concurrent.futures</code></p>
<p>vs</p>
<p><code>asyncio</code></p>
<p>vs</p>
<p><code>threading</code> / <code>multiprocessing</code></p>
<aside class="notes" data-markdown>
* And the same can be said for the different libraries available for concurrency
</aside>
</section>
<section>
<img style="width: 100%;" src="img/Python-Concurrency-API-Decision-Tree.webp" alt="Picture of Python concurrency decision tree">
<aside class="notes" data-markdown>
* We found a flow-chart which tries to simplify the choice
* It might well be correct but oh dear! <!-- https://superfastpython.com/python-concurrency-choose-api/ -->
* [*`Switch to Ben`*]
</aside>
</section>
<section>
<h2>Does it matter?</h2>
<h3>Having choices is useful!</h3>
<aside class="notes" data-markdown>
* [*`Switch to Ben`*]
* But does any of this really matter?
* After all, having choices is useful
</aside>
</section>
<section>
<h3 style="font-size: calc(var(--r-heading3-size) * 0.85);">Storytime: X-Wing Miniatures Game</h3>
<div style="display: flex; justify-content: space-evenly;">
<img style="width: 40%;" src="img/xwing.jpg" alt="Picture of X-Wing miniatures">
<img style="width: 40%;" src="img/xwing-core.jpg" alt="Picture of small amount of original X-Wing rules">
</div>
<aside class="notes" data-markdown>
* Well, a few years ago I started playing the X-Wing miniatures game
* and the simplicity of the game was a major drawcard
* ...because it meant that I could easily teach my friends how to play!
</aside>
</section>
<section>
<h3>The game kept getting better!</h3>
<img style="height: 500px" src="img/xwing-expansion.jpg" alt="Picture of small X-Wing expansion">
<aside class="notes" data-markdown>
* and over time they kept adding new ships
* ...to keep the game fresh for veteran players
</aside>
</section>
<section>
<h3>Fast-forward a few years...</h3>
<div style="display: flex; justify-content: space-evenly; align-items: center;">
<div>
<p style="font-size: 1.1em; font-weight: bold;">35× as much<br>to learn!</p>
<img style="height: 344px" src="img/xwing-core.jpg" alt="Picture of small amount of original X-Wing rules">
</div>
<img style="height: 200px; padding-top: 50px; padding: 0 10px; position: relative; top: 65px;" src="img/arrow.svg">
<img style="height: 500px" src="img/xwing-all.png" alt="Picture of large amount of extend X-Wing rules, cards, tokens">
</div>
<aside class="notes" data-markdown>
* But fast-forward a few years of expansions
* ...the sheer volume of rules made the game unapproachable for beginners
</aside>
</section>
<section>
<blockquote style="width: 90%; margin-bottom: 0;">"...it got more <span class="highlight">complicated</span>, making it <span class="highlight">less easy</span> to jump into the proverbial cockpit."</blockquote>
<span style="font-size: 0.7em;">― starwars.com/news/x-wing-second-edition</span>
<aside class="notes" data-markdown>
* In the end, the game designers had to drastically simplify the game
* ...because it was just too complex
</aside>
</section>
<section class="full-height">
<style>
.article-quote {
position: absolute;
background: #222222;
font-size: 0.4em;
z-index: 1;
padding: 10px;
}
</style>
<article>
<h3 style="width: 900px;"><span class="highlight">Learnability</span> is a big part of Python's success</h3>
</article>
<div class="fragment" data-fragment-index="1">
<img src="img/universities-headline.png"
style="position: absolute; top: 0; left: 25px; width: 90%;"
alt="Headline: Python bumps off Java as top learning language (infoworld.com)">
<div class="article-quote"
style="top: 130px; right: 25px; width: 350px;">
Python possesses a mix of qualities that makes it a good
candidate for universities. It has a
<span class="highlight fragment" data-fragment-index="2">simpler syntax</span>
than Java or C++, allowing novices to
<span class="highlight fragment" data-fragment-index="2">start writing programs almost immediately</span>.
</div>
</div>
<div class="fragment" data-fragment-index="3">
<img src="img/tiobe-headline.png"
style="position: absolute; bottom: 35px; left: 25px; width: 80%;"
alt="Headline: Python ends C and Java's 20-year reign atop the TIOBE index (techreublic.com)">
<div class="article-quote"
style="bottom: 20px; right: 25px; width: 400px;">
“Python, which
<span class="highlight fragment" data-fragment-index="4">started as a simple scripting language</span>,
as an alternative to Perl, has become mature. Its
<span class="highlight fragment" data-fragment-index="4">ease of learning</span>,
its huge amount of libraries and its widespread
use in all kinds of domains, has made it the most popular
programming language of today,” said TIOBE CEO Paul
Jansen.
</div>
</div>
<aside class="notes" data-markdown>
* Like X-Wing, learnability has been a big part of Python's success
* [*`CLICK`*] Python recently surpassed Java as the top learning language in universities
* [*`CLICK`*] and that success has been attributed to its simplicity
* [*`CLICK`*] just last year, Python became the most popular language on the TIOBE index
* [*`CLICK`*] and again, simplicity is arguably a major factor in that success
</aside>
</section>
<section>
<h3 style="font-size: calc(var(--r-heading3-size) * 0.7);">
But how easy is it to learn modern Python?
</h3>
<ul>
<li class="fragment">
In order to start <span class="highlight">reading</span> Python, you must understand <span class="underline">all</span> commonly used features.
</li>
<li class="fragment">
After a 1-day course, how comfortable would you be reading Python from 10 years ago vs today?
<br> <span class="fragment" style="font-size: 0.9em;">Type-hinting...</span>
<br>  <span class="fragment" style="font-size: 0.85em;">F-strings...</span>
<br>   <span class="fragment" style="font-size: 0.8em;">Walrus operator (<code>:=</code>)...</span>
<br>    <span class="fragment" style="font-size: 0.75em;">Positional-only parameters...</span>
<br>     <span class="fragment" style="font-size: 0.7em;">Structural pattern matching (<code>match</code>)...</span>
<br>      <span class="fragment" style="font-size: 0.65em;">...</span>
</li>
</ul>
<aside class="notes" data-markdown>
* But how easy is it really to learn modern Python?
* [*`CLICK`*] Well, remember, in order to confidently read code,
* ...you must be familar with *all* the language features that you're likely to come across
* [*`CLICK`*] Consider how much more needs to be at least mentioned in a
Python crash-course today compared to just 10 years ago
* We have:
* ...
* And that's *just* in the last 10 years
</aside>
</section>
<section>
<h3>Not everyone has the time to learn that much Python</h3>
<ul>
<li class="fragment">
Scientists
</li>
<li class="fragment">
School Teachers
</li>
<li class="fragment">
Data Analysts
</li>
</ul>
<aside class="notes" data-markdown>
* With so much more to learn, Python risks becoming unapproachable
to beginners,
* ...especially those who aren't full-time software engineers, like:
* [*`CLICK`*] Scientists
* [*`CLICK`*] School teachers
* [*`CLICK`*] and data analysts
</aside>
</section>
<section>
<h3><span class="highlight">Language creep</span> threatens Python's popularity!</h3>
<aside class="notes" data-markdown>
* By alienating those users that have made Python
so widespread,
* ...Python's language creep could ultimately
threaten its popularity.
</aside>
</section>
<section>
<h3>So should we just stop extending Python?</h3>
<ul>
<li class="fragment">
Python must still adapt to survive and improve!
</li>
<li class="fragment">
But it's really hard to remove old features
</li>
<li class="fragment">
We need a way to shrink Python
</li>
</ul>
<aside class="notes" data-markdown>
* So should we just stop extending Python?
* [*`CLICK`*] Well, we still want Python to improve where possible
* [*`CLICK`*] But additions inevitably lead to language creep
* ...when we have to keep old features for backwards compatibility.
* [*`CLICK`*] What we really need is some way to shrink the Python language.
</aside>
</section>
<section>
<h3>Can we shrink Python?</h3>
<img src="img/js-the-good-parts.png" alt="The book on \"JavaScript: the Good Parts\" is much smaller than the book on \"JavaScript\"" style="width: 70%;">
<ul style="font-size: 0.83em;">
<li class="fragment">Languages can deprecate features and APIs
<ul>
<li>
JavaScript, Java, C++, PHP
</li>
</ul>
</li>
<li class="fragment">
Python only deprecated 4 modules since 3.0 (2008) – PEP 4
</li>
</ul>
<aside class="notes" data-markdown>
* Ok, so maybe we could copy the JS community?
* They have "JS The Good Parts",
* ...which presented a subset of JS that is more readable and reliable.
* And the JS community loved it!
* [*`CLICK`*] Some languages are even more aggressive,
* ...deprecating features and APIs entirely.
* [*`CLICK`*] Contrast that with Python,
* ...which has only deprecated 4 modules since Python 3.0 in 2008
</aside>
</section>
<section>
<h3>Python: The Good Parts?</h3>
<img src="img/python-the-good-parts.png" alt="\"Python: The Good Parts\" book cover"
style="width: 40%;">
<aside class="notes" data-markdown>
* So should we just write "Python: The Good Parts"?
* Well, Python doesn't really have the same "bad parts" problem as JS
</aside>
</section>
<section>
<h3 style="font-size: calc(var(--r-heading3-size) * 0.75);">
Not enough room for <span class="highlight">all</span> the good parts
</h3>
<img src="img/desert-island-discs.png" alt="Desert Island Discs logo">
<h3 class="fragment">What parts of Python would you take with you?</h3>
<aside class="notes" data-markdown>
* So what we're really saying is that
* ...there isn't enough room for **all* of Python's good parts
* Just like how Desert Island Discs asks
* ...which eight music albums you would take with you to a desert island...
* [*`CLICK`*] We need to ask ourselves:
* ..."What parts of Python should we take with us if we can't take it all?"
</aside>
</section>
<style>
.everyday-steps {
display: flex;
align-items: center;
}
.everyday-step.with-arrow {
padding-right: 70px;
background-image: url(img/arrow.svg);
background-size: 40px;
background-repeat: no-repeat;
background-position-x: calc(100% - 15px);
background-position-y: center;
}
.everyday-steps ul li {
margin-top: 20px;
}
.everyday-steps li.arrow::marker {
content: '→';
font-weight: bold;
}
.everyday-steps li.arrow {
padding-left: 15px;
}
</style>
<section class="everyday-steps">
<h2><span class="highlight">Everyday</span> Python</h2>
<ul style="font-size: 0.93em; list-style: none;">
<li class="fragment">
The community defines a <span class="highlight">limited subset</span> of Python for
<span class="highlight">everyday</span> use
<ul>
<li class="fragment arrow">
The community <span class="highlight">agrees to favour</span>
Everyday Python in their code as much as possible
<ul>
<li class="fragment arrow">
Beginners have <span class="highlight">confidence</span>
in what they need to learn in order to
<span class="highlight">read most</span> Python code
</li>
<li class="fragment arrow">
A smaller Python is more <span class="highlight">readable</span>,
is <span class="highlight">easier</span>
to master, and <span class="highlight">speeds up</span>
development time.
</li>
</ul>
</li>
</ul>
</li>
</ul>
<aside class="notes" data-markdown>
* Practically, we're proposing the Python community defines an Everyday Python
* [*`CLICK`*] That is, a limited subset of Python for everyday use
* [*`CLICK`*] And if we can agree to use Everyday Python as much as possible...
* [*`CLICK`*] then beginners will be able to read most Python code
* [*`CLICK`*] and all developers will benefit
* ...from having an agreed Everyday Python that is easier to **master**.
</aside>
</section>
<section>
<h2>Everyday Python is a...</h2>
<aside class="notes" data-markdown>
* So, what we're saying is that Everyday Python is a...
</aside>
</section>
<section>
<img src="img/bad-pun-ahead.svg" width="33%" alt="Road sign warning of a bad pun ahead">
<aside class="notes" data-markdown>
</aside>
</section>
<section>
<h2>Python <span class="highlight">Constrictor</span>!</h2>
<aside class="notes" data-markdown>
* Python constrictor!
</aside>
</section>
<section>
<h3>
So let's <span class="highlight">constrict</span> Python!
</h3>
<img src="img/the-when-of-python.png" alt="\"The When of Python\" book cover"
style="width: 40%;">
<aside class="notes" data-markdown>
* So instead of writing "Python: The Good Parts",
* ...we propose establishing "The When of Python"
* ...a guide that answers the question of "When" you
should reach for the various features of Python.
* [*`Switch to Grant`*]
</aside>
</script>
</section>
<style>
.when-of-python.overview article {
display: none;
}
.when-of-python .description {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.when-of-python .description > div.title {
font-weight: bold;
opacity: 1 !important;
visibility: visible !important;
}
.when-of-python .description > div.title.visible {
transform: translate(-50%, 0);
}
.when-of-python .description > div.criteria {
position: absolute;
top: 50%;
transform: translate(0, -50%);
left: 550px;
}
</style>
<section>
<h2>The <span class="highlight">When</span> of Python</h2>
<div class="when-of-python fragment overview" data-fragment-index="1">
<div class="always">
<div class="description">
<div class="title fragment" data-fragment-index="2">
Almost always use
</div>
<div class="criteria fragment" data-fragment-index="2">
<ul>
<li>Everyday Python</li>
<li>Teach first</li>
</ul>
</div>
</div>
</div>
<div class="sometimes">
<div class="description">
<div class="title fragment" data-fragment-index="3">
Sometimes use
</div>
<div class="criteria fragment" data-fragment-index="3">
<ul>
<li>Situational</li>
<li>Advanced users</li>
</ul>
</div>
</div>
</div>
<div class="never">
<div class="description">
<div class="title fragment" data-fragment-index="4">
Almost never use
</div>
<div class="criteria fragment" data-fragment-index="4">
<ul>
<li>Niche uses</li>
<li>Deprecated</li>
<li>Not taught</li>
</ul>
</div>
</div>
</div>
</div>
<aside class="notes" data-markdown>
* [*`Switch to Grant`*]
* Specifically, we propose organising Python's features
into three tiers:
* [*`CLICK`*]
* Those that you should almost always use,
* ... the first tools you reach for
* Those that you should use less often,
* ... but that are still the best approach for certain use-cases
* And finally those that the community has decided
* ... should rarely if ever be used
* [*`CLICK`*] The first tier is what we'd consider "Everyday Python",
* ... and is what you'd teach first in an introductory Python course
* [*`CLICK`*] The second tier contains features that are mostly situational
* [*`CLICK`*] Finally, features in the third tier
* ... are reserved for very specific niche uses,
* ... or are considered obsolete.
</aside>
</section>
<section>
<img src="img/opinions-ahead.svg" width="33%" alt="Road sign urging caution because of opinions ahead">
<aside class="notes" data-markdown>
* Now we're going to look at how some of Python's features
* ... could be organised using the "When of Python"
* Obviously these are just our opinions,
* ... and we welcome a healthy debate on these
</aside>
</section>
<section>
<h3>The <span class="highlight">When</span> of Python</h3>
<div class="when-of-python no-faded">
<div class="always">
</div>
<div class="sometimes">
</div>
<div class="never">
</div>
</div>
<p style="font-size: 0.9em; margin-top: 0.2em;">(This is how we think Python <span class="highlight"><em>should</em> be used</span>,<br>not how it is currently used)</p>
<aside class="notes" data-markdown>
* So, here's our When of Python
* We're going to work through each feature to explain our choices
* There are some general principles behind our decisions,
* ... but we'll elaborate at the end
</aside>
</section>
<section>
<h3>String Formatting</h3>
<p style="font-size: 0.7em;">(See: <a href="https://realpython.com/python-string-formatting/">realpython.com/python-string-formatting</a>)</p>
<div class="code-list" style="width: 95%;">
<ul>
<li class="fragment">
<code>%</code>-formatting – Original string formatting
<pre><code class="python hljs" data-trim>
'Hello %s' % name
</code></pre>
</li>
<li class="fragment">
<code>.format()</code> – Safer support for more types
<pre><code class="python hljs" data-trim>
'Hello {name}'.format(name=name)
</code></pre>
</li>
<li class="fragment">
f-strings – Provided a more concise syntax
<pre><code class="python hljs" data-trim>
f'Hello {name}!'
</code></pre>
</li>
<li class="fragment">
Template – Safest for user-provided templates
<pre><code class="python hljs" data-trim>
string.Template('Hello $name!').substitute(name=name)
</code></pre>
</li>
</ul>
</div>
<aside class="notes" data-markdown>
* Let's start with string formatting
* [*`CLICK`*] First we had old style string formatting
* [*`CLICK`*] Then dot-format was added
* ... to address some issues with how some data types were handled
* [*`CLICK`*] And most recently, we've had f-strings,
* ... which have taken the benefits of dot-format
* ... and combined them with a nicer syntax
* [*`CLICK`*] Template Strings also exist,
* ... which are safest for the niche case of user-provided templates
</aside>
</section>
<section>
<h3>String Formatting</h3>
<div class="when-of-python">
<div class="always">
<article class="fragment" style="top: 5px; left: 20px;">f-strings</article>
<label data-below data-right style="top: 25px; left: 165px;">
<span class="highlight">Concise</span>, <span class="highlight">readable</span>, covers most cases
</label>
</div>
<div class="sometimes">
<article class="fragment" style="top: 25px; left: 20px;"><code>.format()</code></article>
<label data-below data-right style="top: 50px; left: 225px;">
Useful in <span class="highlight">certain situations</span>: <pre class="code-wrapper"><code class="python hljs">'...'.format(**kwargs)</code></pre>
</label>
</div>
<div class="never">
<article class="fragment" style="top: 5px; left: 20px;"><code>Template()</code></article>
<label data-below data-right style="width: 410px; top: 40px; left: 255px;">
The safe tool for the <span class="highlight">niche</span> of user-provided template strings
</label>
<article class="fragment" style="bottom: 5px; left: 20px;"><code>%</code>-formatting</article>
<label data-above data-right style="bottom: 40px; left: 240px;">
<span class="highlight">Redundant</span> now that we have f-strings
</label>
</div>
</div>
<aside class="notes" data-markdown>
* So, we place these features onto the When of Python as follows:
* [*`CLICK`*] You should almost always use f-strings:
* ... they are concise, readable, and cover most cases
* [*`CLICK`*] Dot-format should be used less often now,
* ... but it's still useful for some cases, like unpacking arguments.
* [*`CLICK`*] Template strings are useful but only for user-provided templates.
* ... They're a good example of a feature that is a good part of the language
* ... but still belongs in the third tier
* [*`CLICK`*] And old-style string formatting
* ... should be considered redundant and obsolete
</aside>
</section>
<section>
<h3>Data-Storage Objects</h3>
<div class="code-list" style="width: 90%;">
<ul>
<li class="fragment">
Original: <code>collections.namedtuple</code>
<pre><code class="python hljs" data-trim>
Rectangle = namedtuple('Rectangle', ['width', 'height'])
my_square = Rectangle(width=42, height=42)
</code></pre>
</li>
<li class="fragment">
Simpler, typed: <code>typing.NamedTuple</code>
<pre><code class="python hljs" data-trim>
class Rectangle(NamedTuple):
width: float
height: float
</code></pre>
</li>
<li class="fragment">
More versatile Data Classes:
<pre><code class="python hljs" data-trim>
@dataclass(frozen=True, order=True)
class Rectangle:
width: float
height: float
</code></pre>
</li>
</ul>
</div>
<aside class="notes" data-markdown>
* Now let's move on to data-storage objects
* [*`CLICK`*] Originally, named tuples were the standard way
* ... to quickly define a Class for immutable objects
* ... that store a bunch of attributes
* [*`CLICK`*] When typing was introduced, we got a cleaner syntax for defining namedtuples
* [*`CLICK`*] And finally,
* ... the more recently introduced Data Classes fulfill essentially the same role as namedtuples,
* ... but can be used for both mutable and immutable objects
* ... depending on the `frozen` argument.
</aside>
</section>
<section>
<h3>Data-Storage Objects</h3>
<div class="when-of-python">
<div class="always">
<article class="fragment" style="bottom: 15px; right: 5px;"><code>@dataclass</code></article>
<label data-left data-below style="width: 410px; top: 85px; right: 230px;">
<span class="highlight">Simple</span> syntax for
<span class="highlight">both</span> mutable and immutable objects
</label>
</div>
<div class="sometimes">
</div>
<div class="never">
<article class="fragment" style="bottom: 0px; right: 5px;"><code>NamedTuple/namedtuple()</code></article>
<label data-above data-left style="bottom: 25px; left: 60px;">
<span class="highlight">Only immutable</span> objects.
</label>
</div>
</div>
<aside class="notes" data-markdown>
* So, in The When of Python,
* [*`CLICK`*] we think Data Classes should be the
everyday, go-to tool for data-storage objects,
* [*`CLICK`*] while namedtuples should only be rarely used.
<!-- If someone raises performance, two points:
1) memory usage for data classes is lower, and runtime appears to be comparable, and
2) if you really need some performance difference, you have a niche use case, so go ahead and use it -->
<!-- Source: Re-ran github gists from https://medium.com/@jacktator/dataclass-vs-namedtuple-vs-object-for-performance-optimization-in-python-691e234253b9 on Python 3.8.5 -->
</aside>
</section>
<section>
<h3>Structural Pattern Matching: The Promise</h3>
<pre><code class="python hljs" data-trim>
match json_shape:
case {'type': 'circle', 'radius': radius}:
return Circle(radius)
case {'type': 'rectangle', 'dimensions': [width, height]}:
return Rectangle(width, height)
case _:
raise ValueError('Not a shape')
</code></pre>
<ul style="font-size: 0.85em;">
<li class="fragment">Python finally gets a <span class="highlight">concise <code>switch</code> statement</span>!</li>
<li class="fragment"><span class="highlight">Elegantly unpack</span> nested data structures</li>
<li class="fragment">Stealing another <span class="highlight">handy feature</span> from functional languages</li>
</ul>
<aside class="notes" data-markdown>
* Now, let's look at one of Python's most recent features:
* ... structural pattern matching
* Here we have an example of using a `match` statement
* ... to check the structure of a dictionary
* ... and then unpack values from it.
* There's some real benefits structural pattern matching gives us:
* [*`CLICK`*] For one, with literal values in cases,
* ... we have a concise switch statement
* [*`CLICK`*] We can also really elegantly unpack
* ... complex and deeply nested data structures
* [*`CLICK`*] It's another case of stealing another handy feature from functional languages
* ... - just like list and dictionary comprehensions etc
</aside>
</section>
<section>
<h3>Structural Pattern Matching: The Reality</h3>
<ul>
<li class="fragment">A new <span class="highlight">mini-language</span> within Python</li>
<li class="fragment">More <span class="highlight">subtleties</span> than constructs like <code>if-else</code>:
<pre style="width: 100%;"><code class="python hljs" data-trim>
match value:
case str():
print(f'{value} is a string!')
# Without parens after str...
match value:
case str:
print('Oops, this case always matches and redefines str!')
</code></pre>
</li>
<li class="fragment"><span class="highlight">Bugs are hard to see</span> if you're not confident in reading its syntax</li>
</ul>
<aside class="notes" data-markdown>
* But all these benefits come at a cost
* [*`CLICK`*] Match introduces another mini-language within Python
* [*`CLICK`*] And that mini-language has some really subtle gotchas:
* For example, if you forget the parentheses after a type name,
* ... you'll end up redefining that type name for all following code!
* [*`CLICK`*] Because this looks really similar to normal Python code,
* ... bugs like that will be really hard to see
* ... unless you're really confident in the match mini-language
</aside>