forked from mikeckennedy/talk-python-transcripts
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path024_fluent_python.vtt
2810 lines (1873 loc) · 86.2 KB
/
024_fluent_python.vtt
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
WEBVTT
00:00:00.001 --> 00:00:03.120
Are you fluent in Python, or do you speak the language with an accent?
00:00:03.120 --> 00:00:08.620
Python's ease of learning can also lead to non-Pythonic patterns for even experienced developers.
00:00:08.620 --> 00:00:12.960
Luciano Romalo is here to give us a deeper understanding of this language we love.
00:00:12.960 --> 00:00:17.580
It's episode number 24, recorded Thursday, August 6, 2015.
00:00:17.580 --> 00:00:28.800
I'm a developer in many senses of the word, because I make these applications, but I also use these verbs to make this music.
00:00:28.800 --> 00:00:33.340
I construct it line by line, just like when I'm coding another software design.
00:00:33.340 --> 00:00:39.560
In both cases, it's about design patterns. Anyone can get the job done, it's the execution that matters.
00:00:39.560 --> 00:00:42.180
I have many interests, sometimes conflict.
00:00:42.500 --> 00:00:46.320
Welcome to Talk Python to Me, a weekly podcast on Python.
00:00:46.320 --> 00:00:49.380
The language, the libraries, the ecosystem, and the personalities.
00:00:49.380 --> 00:00:53.260
This is your host, Michael Kennedy. Follow me on Twitter where I'm @mkennedy.
00:00:53.260 --> 00:00:57.260
Keep up with the show and listen to past episodes at talkpython.fm.
00:00:57.260 --> 00:01:00.120
And follow the show on Twitter via at Talk Python.
00:01:00.120 --> 00:01:03.120
This episode is brought to you by Hired and CodeChip.
00:01:03.120 --> 00:01:08.660
Thank them for supporting the show on Twitter via at Hired underscore HQ and at CodeChip.
00:01:09.380 --> 00:01:15.100
Before we get to the conversation with Luciano, he generously agreed to give away an electronic copy of his book, Fluent Python.
00:01:15.100 --> 00:01:19.200
All you have to do to be eligible to win is to be a friend of the show.
00:01:19.200 --> 00:01:24.000
Visit talkpython.fm, choose friend of the show in the nav bar, and sign up.
00:01:24.000 --> 00:01:25.980
Now, let me introduce Luciano.
00:01:25.980 --> 00:01:28.480
Luciano Romalo is the author of Fluent Python.
00:01:28.480 --> 00:01:36.220
Romalo was a web developer before the Netscape IPO in 1995 and switched from Perl to Java and finally to Python in 1998.
00:01:36.920 --> 00:01:40.300
Since then, he's worked on some of the largest news portals in Brazil using Python.
00:01:40.300 --> 00:01:45.300
He's taught Python web development in the Brazilian media, banking, and government sectors.
00:01:45.300 --> 00:01:50.680
He's spoken multiple times at OSCON, PyCon, Python Brazil, FISL, and Rupy.
00:01:50.680 --> 00:01:58.000
Romalo is a fellow at the Python Software Foundation and a co-founder at the Garoa Hacker Club, the first hackerspace in Brazil.
00:01:58.000 --> 00:02:03.720
Finally, he's the managing partner at python.pro.br at Python Training Company.
00:02:03.720 --> 00:02:06.120
Luciano, welcome to the show.
00:02:06.420 --> 00:02:06.980
Thanks, Mike.
00:02:06.980 --> 00:02:07.920
Thanks for having me.
00:02:07.920 --> 00:02:11.220
Yeah, I'm really excited to talk to you about your new book, Fluent Python.
00:02:11.220 --> 00:02:13.920
Yeah, I'm excited about it too.
00:02:13.920 --> 00:02:14.720
I bet.
00:02:14.720 --> 00:02:16.220
You've been working on it for a while.
00:02:16.220 --> 00:02:21.880
Before we get into talking about your book, which is really an amazing book, I'll have more to say on that in a minute.
00:02:21.880 --> 00:02:22.360
Thanks.
00:02:22.360 --> 00:02:23.060
You're welcome.
00:02:23.560 --> 00:02:27.800
Let's talk about how you got started in the programming and Python at all.
00:02:27.800 --> 00:02:29.360
You know so much.
00:02:29.360 --> 00:02:30.660
I can tell from your book.
00:02:30.660 --> 00:02:34.040
But at some point, you had to start at the beginning, like we all do, right?
00:02:34.040 --> 00:02:35.340
Where did you get started?
00:02:36.340 --> 00:02:36.840
Okay.
00:02:36.840 --> 00:02:39.480
Now, I'm 51 years old.
00:02:39.480 --> 00:02:44.660
So when I was a teenager in Brazil, there were no microcomputers.
00:02:44.660 --> 00:02:50.500
But I got a hand on a programmable calculator, a TA-58.
00:02:51.500 --> 00:02:54.340
And I learned to program by programming it.
00:02:54.340 --> 00:03:02.900
And actually, my first interesting program was a port of a game from the HP-25 calculator to the TI-59.
00:03:02.900 --> 00:03:06.220
It was the lunar landing game that was famous.
00:03:06.220 --> 00:03:07.420
Oh, that was a great game.
00:03:07.420 --> 00:03:08.120
Yeah.
00:03:08.120 --> 00:03:12.420
So that was my first significant program.
00:03:12.420 --> 00:03:16.900
And then I was an exchange student in 81 in the US.
00:03:16.900 --> 00:03:21.400
I lived in Little Harrisburg, Illinois, population 10,000.
00:03:21.400 --> 00:03:31.440
And there I got – there were – in the library, in the school, there were a few Apple II computers that had just arrived when I arrived.
00:03:31.440 --> 00:03:33.440
And nobody knew how to use them.
00:03:33.440 --> 00:03:40.220
The teachers who were supposed to teach about them hadn't yet taken the course to do it.
00:03:40.220 --> 00:03:43.920
So they were basically free for anyone to do whatever they wanted.
00:03:43.920 --> 00:03:47.300
And I learned – I taught myself basic programming in them.
00:03:48.440 --> 00:03:50.580
Anyway, so that's a long time.
00:03:50.580 --> 00:03:54.540
And then I went through lots of languages after basic, Pascal.
00:03:54.540 --> 00:03:58.980
And Pascal was one of the most important ones for me.
00:03:58.980 --> 00:04:00.520
And then Delphi.
00:04:00.520 --> 00:04:02.280
And then Visual Basic.
00:04:02.280 --> 00:04:06.500
And I studied a little bit of small talk.
00:04:07.160 --> 00:04:19.640
And then when the web started here in Brazil, again, we had a kind of a different situation because there was – all telecom companies in Brazil were state-owned at that time.
00:04:19.640 --> 00:04:22.980
Later they were privatized, but they were state-owned in 94.
00:04:24.080 --> 00:04:30.140
And so I was hired by a large publishing company here to start developing their strategy for online.
00:04:30.140 --> 00:04:37.960
And I learned – I taught myself pro programming because everybody did everything on the web that was automated using Perl at the time.
00:04:37.960 --> 00:04:38.300
Right?
00:04:38.300 --> 00:04:38.820
Right.
00:04:39.360 --> 00:04:41.060
And I loved Perl.
00:04:41.060 --> 00:04:42.040
I thought it was awesome.
00:04:42.040 --> 00:04:48.120
But I also found it – well, I'm saying I just said I love it.
00:04:48.120 --> 00:04:53.840
But I loved it, but I also hated it at the same time because it was very powerful and quick.
00:04:53.840 --> 00:04:56.860
But it was also full of traps.
00:04:56.860 --> 00:05:00.420
And it was difficult to read afterwards and so on.
00:05:01.140 --> 00:05:18.000
Then I tried Java and I probably was one of the first people in Brazil to do server-side Java because when Java was first released, Sun was trying to market it as a tool for client-side programming, right, with the applets and so on.
00:05:18.000 --> 00:05:24.480
It took a while for them to realize that server-side was where Java was going to thrive.
00:05:24.480 --> 00:05:27.700
But I didn't enjoy the verbosity of Java.
00:05:27.700 --> 00:05:32.280
I liked the fact that it was really object-oriented, which Perl was not at the time.
00:05:32.280 --> 00:05:34.240
But it was too verbose.
00:05:34.240 --> 00:05:37.180
And then after a while, I went back to Perl again.
00:05:37.180 --> 00:05:43.600
And Perl had acquired object-oriented features in around Perl 5.
00:05:43.600 --> 00:05:45.980
And then something happened.
00:05:45.980 --> 00:05:54.500
As the Perl community was discussing how to do things in a dynamic language, but also in an object-oriented way,
00:05:54.500 --> 00:05:58.700
they kept repeating the sentence.
00:05:58.700 --> 00:06:00.860
Here's how they do it in Python.
00:06:00.860 --> 00:06:03.480
In Python, this is like that.
00:06:03.480 --> 00:06:05.620
And that's how I first heard of Python.
00:06:05.620 --> 00:06:13.760
It was discussions on the Perl mailing list about how to do things in an object-oriented way,
00:06:13.760 --> 00:06:16.540
but in a language that was a scripting language, in a dynamic language.
00:06:16.540 --> 00:06:20.800
So after reading mentions of Python a few times, I decided to go study it.
00:06:20.800 --> 00:06:25.780
And then I read the tutorial, which was shorter at the time than it is now.
00:06:25.780 --> 00:06:35.040
And I just fell in love immediately because for me, it had the best features of Python, of Java and Perl.
00:06:35.120 --> 00:06:47.960
It was really object-oriented with an object-oriented standard library like Java and had exceptions and other things that I liked about Java,
00:06:47.960 --> 00:06:49.580
but was not verbose.
00:06:49.580 --> 00:06:56.720
So it was, you know, very concise and to the point and agile like Perl.
00:06:57.420 --> 00:07:02.400
And so it was for me the combination of the best features of both languages.
00:07:02.400 --> 00:07:04.660
And then I basically never looked back.
00:07:04.660 --> 00:07:06.800
That's a great story.
00:07:06.800 --> 00:07:12.060
I think we've all had those sorts of feelings about some of our first programming languages.
00:07:12.060 --> 00:07:17.220
We love them because we really got into programming, but, you know, they're not necessarily the best.
00:07:17.220 --> 00:07:19.060
So you have those words as well, right?
00:07:19.060 --> 00:07:20.120
Exactly.
00:07:20.520 --> 00:07:24.300
But Python's where you've sort of settled into.
00:07:24.300 --> 00:07:26.860
I can tell you've been doing it for a long time from your book.
00:07:26.860 --> 00:07:28.040
Yeah.
00:07:28.040 --> 00:07:30.780
So I started doing it in 98.
00:07:30.780 --> 00:07:33.800
That was when I found the tutorial that I mentioned.
00:07:33.800 --> 00:07:42.720
And then I immediately pitched a Python solution to a client at the time for an online news site.
00:07:43.920 --> 00:07:51.680
And then I discovered Zope, which was just then released as open source.
00:07:51.680 --> 00:07:58.040
And I started using it like a couple weeks after it was released as open source.
00:07:58.040 --> 00:08:05.920
And then a couple months later, we actually launched in Brazil a new site that was based on Zope.
00:08:05.920 --> 00:08:09.580
And it was one of the first big Zope cases around the world.
00:08:09.580 --> 00:08:10.460
Oh, that's excellent.
00:08:11.080 --> 00:08:11.320
Yeah.
00:08:11.320 --> 00:08:13.720
And so I owe a lot to Zope.
00:08:13.720 --> 00:08:29.400
I don't use Zope anymore these days, but I owe a lot to it because it was because of Zope that I was able to deliver the kinds of products that the clients were looking for me to deliver, like content management systems.
00:08:29.400 --> 00:08:39.200
And so I was able to get paid for writing Python pretty early, at least in the context of Brazil, since 98.
00:08:39.200 --> 00:08:40.540
That's a great feeling, right?
00:08:40.540 --> 00:08:41.120
Yeah.
00:08:41.120 --> 00:08:43.600
You find this thing you love and, wow, people pay me to do it.
00:08:43.600 --> 00:08:44.280
Exactly.
00:08:44.280 --> 00:08:45.420
Exactly.
00:08:45.420 --> 00:08:47.300
It's a good time to be a programmer indeed.
00:08:47.300 --> 00:08:49.740
So let's talk a little bit about your book.
00:08:49.740 --> 00:08:51.300
The title is Fluent Python.
00:08:51.300 --> 00:08:54.500
And it's coming out under, being published by O'Reilly.
00:08:54.500 --> 00:08:58.700
And it's coming out, I think, September 4th is what Amazon.com tells me anyway.
00:08:58.700 --> 00:08:59.140
Is that right?
00:09:00.140 --> 00:09:00.420
Yeah.
00:09:00.420 --> 00:09:06.680
To be honest, I don't know exactly when the print book is going to come out because different pages that I look at give different dates.
00:09:06.680 --> 00:09:07.640
I've seen August.
00:09:07.640 --> 00:09:08.600
I've seen September.
00:09:08.600 --> 00:09:11.580
And I've seen October all in the last two weeks.
00:09:11.580 --> 00:09:13.640
So, yeah.
00:09:14.480 --> 00:09:15.460
But soon, right?
00:09:15.460 --> 00:09:16.040
Pretty soon.
00:09:16.040 --> 00:09:20.660
Just about the same time that this podcast comes out, I think, should be the time that the book is released.
00:09:20.660 --> 00:09:21.680
Wow.
00:09:21.680 --> 00:09:22.320
That's excellent.
00:09:22.320 --> 00:09:28.960
But let me say, the e-book is now complete in the final form.
00:09:29.160 --> 00:09:40.400
So people who buy the e-book or who have bought it previously can now download the final version of, you know, first edition, first revision.
00:09:40.400 --> 00:09:47.400
And it's also available from Amazon.com for the Kindle in the final form.
00:09:47.400 --> 00:09:50.740
So we are only waiting for the print book at this time.
00:09:50.740 --> 00:09:51.320
Right.
00:09:51.320 --> 00:09:51.620
Okay.
00:09:51.620 --> 00:09:52.080
Excellent.
00:09:52.080 --> 00:09:52.820
Yeah.
00:09:52.820 --> 00:09:55.140
I think having the electronic book works really well.
00:09:55.140 --> 00:09:59.180
I was reading it on my Kindle and it, on my Kindle, paper white, and it was really nice.
00:09:59.180 --> 00:10:02.120
You know, the code samples came through really well.
00:10:02.120 --> 00:10:04.020
Like sometimes that doesn't work so well.
00:10:04.020 --> 00:10:04.740
Wow.
00:10:04.740 --> 00:10:05.240
That's cool.
00:10:05.240 --> 00:10:05.960
Nice to know.
00:10:05.960 --> 00:10:06.320
Yeah.
00:10:06.320 --> 00:10:06.540
Yeah.
00:10:06.540 --> 00:10:07.600
It came out really, really well.
00:10:07.600 --> 00:10:11.560
And, you know, so I've only had the book for a few days.
00:10:11.560 --> 00:10:14.200
So I've only been able to read maybe the first five chapters.
00:10:14.200 --> 00:10:22.260
But my impression of the first five chapters, if it keeps going like this, I'm sure it does, is this book is a masterpiece.
00:10:22.260 --> 00:10:24.360
It is really, really good.
00:10:25.020 --> 00:10:26.060
Well, thank you very much.
00:10:26.060 --> 00:10:29.520
I think it's going to go down as a classic book in the Python community.
00:10:29.520 --> 00:10:30.300
Really.
00:10:30.300 --> 00:10:31.340
Thank you very much.
00:10:31.340 --> 00:10:31.560
Yeah.
00:10:31.560 --> 00:10:33.060
I'm not just saying that because you're on the show.
00:10:33.060 --> 00:10:41.400
But I was reading it and it's a little hard for me to put in words, I think, for people to really understand.
00:10:41.540 --> 00:10:46.000
But it seemed like everything that you covered, and we'll talk a bit more about that.
00:10:46.000 --> 00:10:49.800
But it seemed like everything you covered, I'm kind of like, I mostly know this.
00:10:49.800 --> 00:10:50.720
Oh, wait.
00:10:50.780 --> 00:10:56.840
There's this really cool piece of information or motivation that I was never really aware of.
00:10:57.340 --> 00:11:02.040
And just underneath the surface of the knowledge that I do have.
00:11:02.040 --> 00:11:02.260
Right.
00:11:02.260 --> 00:11:06.360
And that was like all the time happening to me while I was reading your book.
00:11:06.360 --> 00:11:08.220
And so I think it's a great contribution.
00:11:08.220 --> 00:11:09.440
Thank you.
00:11:09.440 --> 00:11:09.820
Yeah.
00:11:10.020 --> 00:11:17.100
So let me read a quick quote right from the beginning to give people a sense of, I think, what you're going for with this book.
00:11:17.100 --> 00:11:24.100
So in the introduction or one of the first chapters, you say, Python is an easy-to-learn, powerful programming language.
00:11:24.100 --> 00:11:26.840
Those are the first words of the official Python tutorial.
00:11:26.840 --> 00:11:28.700
That's true, but there's a catch.
00:11:28.800 --> 00:11:35.820
Because the language is so easy to learn and put to use, many practicing Python programmers leverage only a fraction of its powerful features.
00:11:35.820 --> 00:11:40.200
Does that kind of sum up the problem you're trying to solve with this book?
00:11:40.200 --> 00:11:41.040
Exactly.
00:11:41.040 --> 00:11:42.900
And that's why I called it Fluent Python.
00:11:42.900 --> 00:11:52.440
You know, as somebody who is fluent in two languages, in Portuguese and English, and that knows how difficult it is to become fluent in a language,
00:11:52.440 --> 00:11:56.240
because it's easy to become fluent in the language in your native language, right?
00:11:56.300 --> 00:12:01.540
You grow with it, and that's basically people don't even notice.
00:12:01.540 --> 00:12:05.520
But getting fluent in another language is hard.
00:12:05.520 --> 00:12:11.100
And so I've been teaching Python to lots of people.
00:12:11.100 --> 00:12:18.380
When I had a company, whenever we hired people, we never could hire people that knew Python because nobody knew Python at the time.
00:12:18.380 --> 00:12:22.360
So we hired people who knew Java and then taught them Python.
00:12:22.360 --> 00:12:28.820
But I also worked as a Python instructor, and that's what I do now these days.
00:12:28.980 --> 00:12:36.600
So I realized that this thing that I say over there, that the language is easy to use, it's practical.
00:12:36.600 --> 00:12:40.000
So people start solving real problems real fast.
00:12:40.000 --> 00:12:47.320
But that means that sometimes they are already using it for several years and don't know why some things are the way they are.
00:12:47.860 --> 00:12:57.440
And another thing that I say right after that in the second paragraph is that when you're learning a new language,
00:12:57.440 --> 00:13:01.580
you look for things that are familiar to you.
00:13:01.580 --> 00:13:08.340
Like, for instance, maybe this language, probably this language has a way to use a regular expression.
00:13:08.460 --> 00:13:09.920
Let's see how that works.
00:13:09.920 --> 00:13:17.380
But if there is something in the language that is not matched by something that you know from another language,
00:13:17.380 --> 00:13:22.040
like, for instance, the concept of generators that many languages don't have,
00:13:22.040 --> 00:13:25.260
then you're unlikely to go look for it, right?
00:13:25.260 --> 00:13:27.460
Because you don't even know the thing exists.
00:13:27.460 --> 00:13:32.120
Another simpler example than generators is like tuple unpacking.
00:13:32.540 --> 00:13:35.120
It's just a nice synthetic sugar.
00:13:35.120 --> 00:13:39.160
But if you've never seen that in a language, you won't look for it.
00:13:39.160 --> 00:13:43.460
And maybe you're going to spend years working with Python without ever using it.
00:13:43.460 --> 00:13:49.200
But it's a really nice thing to use because it makes code more readable, even safer in some ways.
00:13:49.200 --> 00:13:59.600
Python tuple unpacking has this characteristic because it actually forces the interpreter to count the number of items.
00:13:59.800 --> 00:14:03.260
So if there's one more or one less, an error will be raised.
00:14:03.260 --> 00:14:10.340
So it's a very nice feature, but it's something that people who come from other languages may never use because they won't think about it.
00:14:10.340 --> 00:14:10.940
Right.
00:14:10.940 --> 00:14:15.820
If you came from something like C#, for example, that doesn't have this concept of tuple unpacking,
00:14:15.820 --> 00:14:19.700
and so you just wouldn't even, you might not ever find it.
00:14:19.700 --> 00:14:29.080
And that kind of gets at the broader issue or concept of Pythonic versus non-Pythonic code, right?
00:14:29.080 --> 00:14:29.260
Yes.
00:14:29.260 --> 00:14:30.220
Yes.
00:14:30.220 --> 00:14:37.020
It's pretty easy to come over to Python and learn it really quickly so that you can do the same thing that you do.
00:14:37.020 --> 00:14:39.280
But it's not always the best, is it?
00:14:39.280 --> 00:14:42.280
Some of your mental models don't really carry over so well.
00:14:42.280 --> 00:14:43.320
Exactly.
00:14:43.320 --> 00:14:43.880
Yeah.
00:14:43.880 --> 00:14:44.900
Yeah.
00:14:44.900 --> 00:14:51.280
It's very, it's, of course, it's a very elusive thing to define what is Pythonic.
00:14:51.280 --> 00:14:58.620
I actually mentioned it several times in the book and tried to address it afterwards.
00:14:58.620 --> 00:15:11.100
But basically, I just send people links to other people that I respect a lot in the Python community who have attempted to define it directly.
00:15:11.460 --> 00:15:11.760
Right.
00:15:11.760 --> 00:15:20.720
But it's like, it's about a good definition which doesn't really explain what is Pythonic is to say it's idiomatic Python, right?
00:15:20.720 --> 00:15:21.120
Right.
00:15:21.220 --> 00:15:23.060
But okay, so what is idiomatic Python?
00:15:23.060 --> 00:15:24.800
Right?
00:15:24.800 --> 00:15:26.940
It's hard to define.
00:15:27.980 --> 00:15:28.560
Yeah.
00:15:28.560 --> 00:15:34.940
I think your best bet is to show a bunch of people a bunch of examples, say, all of these things are Pythonic.
00:15:34.940 --> 00:15:44.420
All of these things are not Pythonic because they carry over concepts that work well in other languages but are not the proper way to do them here.
00:15:44.420 --> 00:15:54.380
And once you get enough experience of going, bad example, good example, then you kind of get this sense, like almost a smell for like, yeah, it seems like this is right.
00:15:54.380 --> 00:15:55.400
It seems like that's not right.
00:15:55.400 --> 00:15:57.560
But it's very hard to be very concrete.
00:15:57.560 --> 00:15:58.540
Exactly.
00:15:58.540 --> 00:15:59.320
Yeah.
00:15:59.320 --> 00:15:59.800
Yeah.
00:15:59.800 --> 00:16:01.620
I tried to do that in the book.
00:16:01.620 --> 00:16:20.160
And actually, a decision that I made early on was to be as Pythonic as I could in the program examples, even when being Pythonic might not have provided the clearest source code from something that's not familiar with the language.
00:16:20.160 --> 00:16:21.120
You know?
00:16:21.120 --> 00:16:29.460
Like, for instance, right in the first example in the book, I use named tuple, right?
00:16:29.460 --> 00:16:29.920
Yep.
00:16:29.920 --> 00:16:34.460
And then I give it just a couple sentences to explain.
00:16:34.460 --> 00:16:41.700
It's probably not enough if the person has never seen it, but it's actually something useful that I start using all over the book.
00:16:41.700 --> 00:16:48.380
And if that picks up the person's curiosity, then the person can go and look for it.
00:16:48.380 --> 00:16:50.480
So this is what I decided.
00:16:50.480 --> 00:16:59.900
Like, for instance, before I actually have a chapter that formally discusses generated expressions, I use them in the book whenever it was natural to do so.
00:16:59.900 --> 00:17:02.220
Even before I actually cover it.
00:17:02.220 --> 00:17:03.740
Because of what I just said.
00:17:03.740 --> 00:17:09.440
You know, I wanted to write idiomatic Python whenever I could, even if that made the...
00:17:09.440 --> 00:17:21.420
Because the thing is, when you're speaking to a native speaker of English, for example, the person won't dumb down his or her speech for you, right?
00:17:21.420 --> 00:17:22.020
That's right.
00:17:22.260 --> 00:17:23.520
And that's cool.
00:17:23.520 --> 00:17:33.460
Sometimes maybe you don't understand everything, but you're catching, you know, there's something new about the way this person is expressing herself.
00:17:33.460 --> 00:17:37.060
And then you're going to try and find out what that means.
00:17:37.720 --> 00:17:49.240
That's, you know, if you always talk to people that spoke English, easy English, you would only learn easy English and not real English, fluent English.
00:17:49.240 --> 00:17:52.420
You wouldn't get that chance to grow into a fluent speaker, kind of like you said.
00:17:53.080 --> 00:17:58.560
So your example with the name tuple kind of hits on the point that I was talking about.
00:17:58.560 --> 00:18:00.640
Like, I've used name tuples.
00:18:00.640 --> 00:18:01.660
I'm familiar with them.
00:18:01.660 --> 00:18:02.440
I think they're great.
00:18:02.440 --> 00:18:15.340
But, you know, you go a little bit deeper and you're like, hey, it's really cool to use a name tuple because the actual dictionary that stores the attributes is stored in the class object, which is a singleton in the runtime.
00:18:16.300 --> 00:18:17.860
Not in the individual instances.
00:18:17.860 --> 00:18:21.320
So storage is actually cheaper than regular custom classes.
00:18:21.320 --> 00:18:21.900
Yes.
00:18:21.900 --> 00:18:31.160
So if all you want to have is just a bunch of pieces of data that have names in an object, but not functionality, maybe you should use these name tuples.
00:18:31.160 --> 00:18:43.760
This episode is brought to you by Hired.
00:18:44.080 --> 00:18:50.300
Hired is a two-sided, curated marketplace that connects the world's knowledge workers to the best opportunities.
00:18:50.300 --> 00:18:59.400
Each offer you receive has salary and equity presented right up front, and you can view the offers to accept or reject them before you even talk to the company.
00:18:59.400 --> 00:19:05.020
Typically, candidates receive five or more offers in just the first week, and there are no obligations.
00:19:05.020 --> 00:19:05.740
Ever.
00:19:05.740 --> 00:19:07.840
Sounds pretty awesome, doesn't it?
00:19:07.840 --> 00:19:09.900
Well, did I mention there's a signing bonus?
00:19:10.220 --> 00:19:18.340
Everyone who accepts a job from Hired gets a $2,000 signing bonus, and as Talk Python listeners, it gets way sweeter.
00:19:18.340 --> 00:19:25.900
Use the link Hired.com slash Talk Python To Me, and Hired will double the signing bonus to $4,000.
00:19:25.900 --> 00:19:27.620
Opportunities knocking.
00:19:27.620 --> 00:19:31.240
Visit Hired.com slash Talk Python To Me and answer the call.
00:19:31.960 --> 00:19:41.920
Exactly.
00:19:41.920 --> 00:19:42.780
Yeah.
00:19:42.780 --> 00:19:43.880
And another thing.
00:19:43.880 --> 00:19:47.240
They are, because they are inexpensive, you can use it.
00:19:47.240 --> 00:19:52.700
And they are inexpensive and they are completely compatible with tuples, right?
00:19:52.800 --> 00:19:55.980
You can unpack them, you can iterate over the items and so on.
00:19:55.980 --> 00:20:03.580
So, for instance, whenever you need to return more than one value from a function, I recommend you return a name tuple.
00:20:03.580 --> 00:20:11.300
Because it will make, for instance, understanding what the function does easier, because there's going to be the definition of this name tuple.
00:20:11.480 --> 00:20:23.520
If the person is looking at the result of the function in the console or in the debugger, the person is going to actually see the names of the parts of the tuple that the function is returning.
00:20:24.400 --> 00:20:26.120
So, this is a recommendation.
00:20:26.120 --> 00:20:34.080
Like, for instance, if you're going to return more than one value from a function, usually people do it with a tuple, and that's fine.
00:20:34.080 --> 00:20:36.680
But with the name tuple is even better.
00:20:36.680 --> 00:20:40.560
And it's cheap, like you said, because of the way it's implemented.
00:20:40.560 --> 00:20:44.760
It doesn't require more memory.
00:20:44.760 --> 00:20:45.000
Yeah.
00:20:45.000 --> 00:20:49.060
You don't have to store all the keys, copies of the keys for every instance, right?
00:20:49.060 --> 00:20:52.380
Like you would with regular classes or objects.
00:20:52.380 --> 00:20:52.920
Yeah.
00:20:53.180 --> 00:21:02.820
And, of course, when those come back, if you're unsure what's coming back from that method, you could print it out and you get a nice listing of actually not just what's in there, but the meaning of them by the name.
00:21:02.820 --> 00:21:03.280
Exactly.
00:21:03.280 --> 00:21:03.900
Exactly.
00:21:03.900 --> 00:21:10.200
Or if you're in a debugger like PyCharm, you could probably hover over it and actually see it pop up in the watch window.
00:21:10.200 --> 00:21:11.060
Yeah, it's excellent.
00:21:11.060 --> 00:21:11.320
Yeah.
00:21:11.320 --> 00:21:12.000
Yeah.
00:21:12.000 --> 00:21:18.820
So, one thing that you said you used in your book is something called Doctest to check the code in the console listings.
00:21:18.820 --> 00:21:20.360
Can you talk about that a little bit?
00:21:20.360 --> 00:21:20.920
Yeah.
00:21:20.920 --> 00:21:28.620
So, that's something that I think was created by the people in the ZOOP community.
00:21:28.620 --> 00:21:32.340
And it's not...
00:21:32.340 --> 00:21:35.100
So, in the ZOOP community, this was always very big.
00:21:35.220 --> 00:21:56.100
So, the main idea of Doctest is to make sure that whatever code snippets appear in documentation, particularly listings of console sessions demonstrating stuff, that those actually match the behavior of the program at that time.
00:21:56.100 --> 00:22:00.840
So, this was the starting point for Doctest.
00:22:01.360 --> 00:22:07.800
In the ZOOP community, which is still active, there's a lot of development going on still in ZOOP.
00:22:07.800 --> 00:22:17.500
There's a lot of also files that are testing files that are not strictly documentation that are written in the Doctest format.
00:22:18.180 --> 00:22:19.440
Because it's really easy to...
00:22:19.440 --> 00:22:20.440
Because it's really easy to...
00:22:20.440 --> 00:22:22.220
I find it excellent to...
00:22:22.220 --> 00:22:24.800
When I have to design a new API.
00:22:24.800 --> 00:22:27.440
Because I...
00:22:27.440 --> 00:22:30.460
It's sort of a BDD thing, you know?
00:22:30.800 --> 00:22:41.100
You start typing those fake console sessions where you're thinking how it would feel to interact with this API.
00:22:41.100 --> 00:22:44.900
And then the result would look like that and so on.
00:22:44.900 --> 00:22:46.360
And then you...
00:22:46.360 --> 00:22:48.520
It's really good to do TDD.
00:22:49.960 --> 00:22:59.640
Because you write a couple of stanzas of Doctest and then you implement the code that makes it pass and so on and on and on.
00:22:59.640 --> 00:23:10.400
You know, the whole idea of trying to envision what your API looks like from the outside and then implement it generates much cleaner APIs in the end.
00:23:10.400 --> 00:23:12.280
And this is, you know, one flavor of that, right?