1
00:00:01,120 --> 00:00:03,520
Welcome. 
To Happy Path Programming. 

2
00:00:03,760 --> 00:00:09,080
I'm Bruce Eckel. 
And I'm James Ward, Welcome to 

3
00:00:09,080 --> 00:00:13,560
Happy Path Programming. 
Today we have some friends who 

4
00:00:13,560 --> 00:00:17,160
have been up in Crestview this 
week for the Rust Developer 

5
00:00:17,160 --> 00:00:20,480
Retreat. 
And so we've been exploring some

6
00:00:20,480 --> 00:00:24,800
Rust stuff with some folks up 
here this week and been fun. 

7
00:00:25,320 --> 00:00:26,680
So. 
Yeah, yeah. 

8
00:00:26,680 --> 00:00:31,480
This is the last day of the 
retreat and we've been diving in

9
00:00:31,480 --> 00:00:36,760
and out of rust and it's it's 
been kind of a new experiment 

10
00:00:36,760 --> 00:00:40,120
because we've been let's see 
we've had camping on the porch 

11
00:00:40,120 --> 00:00:45,480
and on the floor and you know 
just just it's it's been sort of

12
00:00:45,480 --> 00:00:49,120
like glamping I think because 
we've had all the everybody 

13
00:00:49,120 --> 00:00:52,960
brought food and then we've been
you know making meals and things

14
00:00:52,960 --> 00:00:55,410
like that it's been. 
It's been pretty fun and we've 

15
00:00:55,410 --> 00:01:03,650
been diving into Rust a lot and 
using a I to to write Rust 

16
00:01:03,650 --> 00:01:07,250
examples, which is actually been
really helpful, yeah. 

17
00:01:07,810 --> 00:01:12,970
And Bruce is Bruce would 
continually say when we ran into

18
00:01:12,970 --> 00:01:14,850
a problem or didn't or send 
something, just feed it in a 

19
00:01:14,850 --> 00:01:18,690
ChatGPT and see what it says. 
And we'd feed it code and say 

20
00:01:18,730 --> 00:01:21,420
fix this code and then it would.
Help us. 

21
00:01:21,500 --> 00:01:22,660
It would help us. 
Wouldn't always. 

22
00:01:22,660 --> 00:01:25,900
Yeah, wouldn't always fix it 
completely, but it would move us

23
00:01:25,900 --> 00:01:28,140
forward, You know, Sometimes it 
would get you unstuck. 

24
00:01:28,420 --> 00:01:32,180
And also, when I've been 
interested in a topic, I would 

25
00:01:32,180 --> 00:01:36,060
just say, give me an example 
that demonstrates this. 

26
00:01:37,100 --> 00:01:38,580
Yeah. 
Again, didn't always get it 

27
00:01:38,580 --> 00:01:41,140
right the first time, but it 
would certainly move you forward

28
00:01:41,140 --> 00:01:43,820
a lot. 
So it's very helpful to do that,

29
00:01:44,940 --> 00:01:46,940
Yeah. 
And our the, the project that I 

30
00:01:46,940 --> 00:01:50,140
worked on mostly with 
participation from everyone here

31
00:01:50,140 --> 00:01:55,540
was around the easy racer thing,
which is comparing different 

32
00:01:55,540 --> 00:01:58,340
frameworks and languages for 
structure, concurrency and 

33
00:01:58,340 --> 00:02:00,820
different approaches there. 
So we'll get into that at the 

34
00:02:01,660 --> 00:02:03,820
after we talk about just general
stuff. 

35
00:02:03,820 --> 00:02:08,860
So before we go there, does 
Zenbe have anything they worked 

36
00:02:08,860 --> 00:02:11,500
on, things they learned about 
rest, things that were 

37
00:02:11,660 --> 00:02:16,960
interesting, surprising, any 
highlights or we're sharing or 

38
00:02:18,280 --> 00:02:20,040
just what you worked on, what 
you learned? 

39
00:02:22,160 --> 00:02:23,040
Yeah. 
What? 

40
00:02:23,040 --> 00:02:25,240
What's your experience? 
What was your experience at the 

41
00:02:25,240 --> 00:02:27,080
retreat? 
Just general stuff. 

42
00:02:27,800 --> 00:02:29,400
Yeah, well, this is this is 
going. 

43
00:02:29,400 --> 00:02:32,960
We claim I was the one camping 
in the porch, or yeah, I 

44
00:02:32,960 --> 00:02:34,840
wouldn't exactly call that 
camping. 

45
00:02:34,840 --> 00:02:40,200
I'm sleeping in a tent. 
None of the other usual things 

46
00:02:40,200 --> 00:02:43,830
with camping, but. 
Yeah, I I came in, I had the 

47
00:02:43,830 --> 00:02:47,710
skeleton of a a little project 
that something I wanted to do 

48
00:02:47,710 --> 00:02:51,910
for a while just tell the story.
I have a TB drive at home that 

49
00:02:51,910 --> 00:02:54,710
has all these pictures of my 
kids back from the early 2000s 

50
00:02:55,350 --> 00:02:58,190
when we had a series of 
different digital cameras and 

51
00:02:58,550 --> 00:03:00,830
you know, they were downloaded 
by whatever weird software they 

52
00:03:00,830 --> 00:03:05,070
had onto a hard drive on, you 
know, the desktop computer we 

53
00:03:05,070 --> 00:03:06,870
had. 
And eventually all that got 

54
00:03:06,870 --> 00:03:08,980
shoved off on this. 
TB Drive. 

55
00:03:08,980 --> 00:03:10,340
And you know, this thing's a 
real mess. 

56
00:03:10,340 --> 00:03:12,540
There's multiple copies of 
photos there. 

57
00:03:13,380 --> 00:03:14,980
You know, photos that have been 
resized. 

58
00:03:14,980 --> 00:03:16,940
There are just multiple copies 
in different directories. 

59
00:03:16,940 --> 00:03:20,460
There are photos that are have 
been resized or rotated or 

60
00:03:21,180 --> 00:03:23,380
whatever. 
And so I had this idea of like, 

61
00:03:23,380 --> 00:03:26,660
Gee, it would be, well, it would
be nice to have these photos 

62
00:03:26,660 --> 00:03:28,620
organized. 
And the first thing is to get 

63
00:03:28,620 --> 00:03:31,860
rid of all this duplication. 
So I have this basic idea for a 

64
00:03:31,860 --> 00:03:34,460
thing that would just walk 
across the file tree and try to 

65
00:03:34,460 --> 00:03:37,540
identify what files it thought 
might be duplicated. 

66
00:03:38,090 --> 00:03:40,690
You know sort of starting off 
like looking at file names and 

67
00:03:40,690 --> 00:03:45,730
then doing like a a 
cryptographic hash of it. 

68
00:03:46,330 --> 00:03:48,650
And so anyway I I just had the 
scale and I had a little bit of 

69
00:03:48,650 --> 00:03:57,250
code and coming in, you know, I 
mean there's a bunch of stuff. 

70
00:03:57,250 --> 00:04:00,290
I mean I guess the the the main 
thing is like like how super 

71
00:04:00,290 --> 00:04:04,050
effective ChatGPT is giving you 
help and specifically Rust. 

72
00:04:04,050 --> 00:04:06,010
I've used it for other 
languages, but man, it's super 

73
00:04:06,010 --> 00:04:11,370
effective and Rust. 
And yeah, that was that was 

74
00:04:11,370 --> 00:04:13,890
really surprising. 
Bruce is now on a first name 

75
00:04:13,890 --> 00:04:16,730
basis with ChatGPT, he just 
refers to his chat. 

76
00:04:16,730 --> 00:04:23,810
So the but yeah, I mean, I 
finished up basically yesterday,

77
00:04:24,650 --> 00:04:27,890
you know, finished up what I 
intended to do, which was doing 

78
00:04:27,890 --> 00:04:31,250
searches across the tree, 
indexing things by their 

79
00:04:31,330 --> 00:04:34,930
cryptographic hash, and to get 
indexing things by sort of 

80
00:04:34,930 --> 00:04:39,670
partial matches on file names. 
And even started adding some 

81
00:04:39,670 --> 00:04:42,150
tests because that partial match
logic started getting 

82
00:04:42,150 --> 00:04:45,870
complicated. 
And so got into a little bit of 

83
00:04:45,870 --> 00:04:49,430
the testing trying to figure 
out, you know, we we actually 

84
00:04:49,430 --> 00:04:52,590
had this philosophical debate 
yesterday on on mocking because 

85
00:04:52,590 --> 00:04:58,030
I was trying to mock out pieces 
of the the file system stuff and

86
00:04:58,230 --> 00:04:59,870
you know we got into a big 
debate. 

87
00:04:59,870 --> 00:05:02,310
I actually then eventually ended
up abandoning mocking for that 

88
00:05:02,310 --> 00:05:04,310
case basically because of that 
discussion. 

89
00:05:04,310 --> 00:05:06,250
But. 
In any case, yeah, I mean that 

90
00:05:06,250 --> 00:05:10,730
that was. 
I guess my impression is not 

91
00:05:10,730 --> 00:05:14,530
really having done much you 
know, before this week is like 

92
00:05:17,410 --> 00:05:22,050
if you get code to run, it's 
going to, you know, it's very 

93
00:05:22,050 --> 00:05:25,010
likely to work. 
Unless the one actual bug I had 

94
00:05:25,010 --> 00:05:27,810
was forgetting a negation 
operator, a logical negation 

95
00:05:27,810 --> 00:05:30,090
operator, and you know 
everything else. 

96
00:05:30,090 --> 00:05:32,310
There was no. 
There's none of this fooling 

97
00:05:32,310 --> 00:05:33,350
around. 
There's none of this. 

98
00:05:33,350 --> 00:05:35,710
You know, I've got this 
Dictionary of values. 

99
00:05:35,710 --> 00:05:37,230
What do they name that key 
again? 

100
00:05:37,230 --> 00:05:39,270
What are the types of the? 
You know, whatever. 

101
00:05:39,550 --> 00:05:43,950
It's like the compiler forces 
you to deal with all of that and

102
00:05:44,950 --> 00:05:48,510
you know, and the only runtime 
errors I ever encountered were 

103
00:05:49,590 --> 00:05:52,230
files that didn't exist. 
I had forgotten to create my 

104
00:05:52,230 --> 00:05:55,550
file system and stuff like that.
But you know, for the most part 

105
00:05:55,550 --> 00:05:57,500
it's like. 
You know, yeah, if you can get 

106
00:05:57,500 --> 00:05:59,180
the code to compile, it's going 
to run. 

107
00:05:59,180 --> 00:06:00,460
That's going to do what you 
meant it to. 

108
00:06:00,700 --> 00:06:05,180
And you know, the the process is
frustrating because you you have

109
00:06:05,180 --> 00:06:06,740
to make a lot of decisions up 
front. 

110
00:06:06,780 --> 00:06:11,100
But you know, you pay that pain 
up front and then getting your 

111
00:06:11,100 --> 00:06:14,620
code to run is like 
anticlimactic because it's just 

112
00:06:14,620 --> 00:06:16,660
like you've done all the hard 
work already. 

113
00:06:16,660 --> 00:06:21,980
So I mean, that's my overall 
impression and you were able to 

114
00:06:21,980 --> 00:06:25,120
get something working and tested
and yeah. 

115
00:06:25,640 --> 00:06:28,400
Some good progress still still 
working through my tests again I

116
00:06:28,400 --> 00:06:32,240
I started you know making that 
the file match file name 

117
00:06:32,240 --> 00:06:35,120
matching logic more complicated 
and so you know that's just 

118
00:06:35,160 --> 00:06:39,000
honestly it's right now my my 
logic is messed up but I got to 

119
00:06:39,040 --> 00:06:42,960
go back and look at it. 
But the, you know, yeah, I've, 

120
00:06:43,440 --> 00:06:46,800
you know, got got a test suite 
and I've got this thing running 

121
00:06:46,800 --> 00:06:51,190
and it's, you know. 
At least what I had as of 

122
00:06:51,310 --> 00:06:54,750
yesterday afternoon was, you 
know, essentially what I set out

123
00:06:54,870 --> 00:06:57,190
to accomplish. 
So you know, that's that. 

124
00:06:57,190 --> 00:07:00,030
That was pretty nice. 
And now it's sort of onto, you 

125
00:07:00,030 --> 00:07:04,750
know, adding features and gold 
playing gold, playing the crap 

126
00:07:04,750 --> 00:07:07,350
out of this week. 
The great thing about these 

127
00:07:07,350 --> 00:07:13,110
things is lots of people had 
different ideas about doing 

128
00:07:13,110 --> 00:07:15,150
image matching, like you know, 
approaches to figuring out 

129
00:07:15,150 --> 00:07:16,630
whether the image has been 
rotated. 

130
00:07:19,670 --> 00:07:22,830
Or, you know, rotated or resized
or something like that. 

131
00:07:22,870 --> 00:07:28,670
And, you know, really got a 
bunch of good research done on 

132
00:07:28,750 --> 00:07:31,790
like, yeah, how I can approach 
that problem when I get to the 

133
00:07:31,790 --> 00:07:35,230
point I want to tackle it. 
So you know, it's it's great 

134
00:07:35,230 --> 00:07:37,910
having a lot of people around 
and I can just ask stupid 

135
00:07:37,910 --> 00:07:39,430
questions like explain this to 
me. 

136
00:07:39,430 --> 00:07:43,110
And you know people are 
generally happy to explain it to

137
00:07:43,110 --> 00:07:46,740
you. 
That's cool. 

138
00:07:47,140 --> 00:07:48,900
Nice to. 
Was there anything that stuck 

139
00:07:48,900 --> 00:07:54,260
out in the Rust language that 
was new or interesting as you're

140
00:07:54,620 --> 00:07:57,540
in the language and? 
You know, I I I think the whole,

141
00:07:58,180 --> 00:08:00,460
you know, it's it's the same 
thing everybody runs into. 

142
00:08:00,500 --> 00:08:03,100
It's the, you know, it's this 
this whole concept of borrowing 

143
00:08:03,100 --> 00:08:06,340
and understanding that Rust is 
really, really specific about 

144
00:08:06,340 --> 00:08:10,180
ownership and you know, and 
that's one of the things you 

145
00:08:10,180 --> 00:08:12,500
have to think about. 
There was one point where I was 

146
00:08:12,500 --> 00:08:15,140
wrestling with some problem and 
it was wanting me to, you know? 

147
00:08:15,690 --> 00:08:18,210
Wanted me to change well I mean 
it was an error I had to change 

148
00:08:18,210 --> 00:08:23,170
something and the the you know 
after thinking through it's like

149
00:08:23,170 --> 00:08:25,410
well I guess the quick way to 
fix this is just to clone the 

150
00:08:25,410 --> 00:08:33,570
subject and and you know which 
kind of hurt to do but then I 

151
00:08:33,570 --> 00:08:36,210
realized I have to think about 
it for a minute it's like well 

152
00:08:36,210 --> 00:08:38,770
you know this is this is the 
design choice I made and I have 

153
00:08:38,770 --> 00:08:40,370
to stare every time I look at 
this code I. 

154
00:08:40,799 --> 00:08:43,000
Have to stare at that clone 
thing and it has to hurt me. 

155
00:08:43,480 --> 00:08:46,000
And so eventually it's it's 
either like I'm going to, you 

156
00:08:46,000 --> 00:08:49,600
know, freak out over wasting the
memory and go deal with that or 

157
00:08:49,600 --> 00:08:52,560
I just deal with the fact that 
it's like, well, you know I have

158
00:08:52,560 --> 00:08:55,680
to make a lot of copies of 
memory to make this thing 

159
00:08:55,680 --> 00:08:58,120
correct. 
Yeah, yeah. 

160
00:08:58,120 --> 00:09:01,800
I experienced the the borrow 
checker kind of the power of 

161
00:09:02,000 --> 00:09:06,880
ownership in. 
I was playing with in Tokyo. 

162
00:09:06,880 --> 00:09:11,070
There's a one shot channel with 
a transmission channel side and 

163
00:09:11,070 --> 00:09:14,110
a receive channel side, and in 
the one shot channel you can 

164
00:09:14,110 --> 00:09:18,230
only have one receiver and one 
transmitter. 

165
00:09:18,630 --> 00:09:22,230
And it's kind of cool that the 
borrow checker actually enforces

166
00:09:22,230 --> 00:09:24,110
that. 
It's like, no, you can't share 

167
00:09:24,790 --> 00:09:28,750
either of those in multiple 
places because that's not 

168
00:09:28,750 --> 00:09:30,550
allowed. 
But the compiler can actually 

169
00:09:30,550 --> 00:09:34,590
verify that, oh, you you 
actually, it won't compile if 

170
00:09:34,590 --> 00:09:38,190
you try to to share those 
references in multiple places. 

171
00:09:38,190 --> 00:09:39,350
And that was. 
Pretty. 

172
00:09:39,630 --> 00:09:41,550
Brilliant. 
Yeah. 

173
00:09:41,950 --> 00:09:47,830
And I think a lot of people, you
know, look, come in and see the,

174
00:09:48,430 --> 00:09:53,870
the lifetime system as, oh, it's
so that we don't have to have a 

175
00:09:53,870 --> 00:09:57,150
garbage collector. 
And what I've learned is that's 

176
00:09:57,150 --> 00:10:00,750
only part of what it does. 
That's the one that you run into

177
00:10:00,750 --> 00:10:06,150
initially. 
But it also means that with 

178
00:10:06,190 --> 00:10:10,870
Rust's generics. 
You don't have to have any 

179
00:10:11,150 --> 00:10:15,550
annotations for covariance or 
contravariance like you do with 

180
00:10:15,550 --> 00:10:20,070
JVM languages. 
And that is so nice. 

181
00:10:20,070 --> 00:10:24,870
That is such a wonderful thing 
not to have to think about. 

182
00:10:26,150 --> 00:10:27,550
So. 
And then there's some other 

183
00:10:27,550 --> 00:10:32,270
things, well, like concurrency 
the the lifetime system. 

184
00:10:32,690 --> 00:10:36,210
Make sure or. 
It helps ensure that concurrency

185
00:10:36,210 --> 00:10:39,930
is correct as well. 
Like the example that you gave 

186
00:10:39,930 --> 00:10:43,370
there. 
Yeah, yeah, the one. 

187
00:10:43,410 --> 00:10:46,090
The one. 
I think my biggest pain point 

188
00:10:46,490 --> 00:10:50,210
with Rust this week was 
mutability. 

189
00:10:50,210 --> 00:10:55,380
Because there's places where I, 
you know, I spent so much time 

190
00:10:55,380 --> 00:11:00,780
just in the world of immutable 
that having to to do some things

191
00:11:00,820 --> 00:11:05,260
with mutability and then fight 
through some of the challenges 

192
00:11:05,260 --> 00:11:06,820
with that. 
I think there was one compiler 

193
00:11:06,820 --> 00:11:10,060
we were struggling with where 
it's like, oh, you can't do this

194
00:11:10,060 --> 00:11:13,900
because it needs a mutable 
version of this and you have an 

195
00:11:13,900 --> 00:11:18,470
immutable version of this and 
like if everything was just 

196
00:11:18,550 --> 00:11:21,190
immutable that would certainly 
simplify things. 

197
00:11:21,190 --> 00:11:24,470
And I get for like you know, 
performance, memory reasons why 

198
00:11:24,470 --> 00:11:29,550
they use mutability in places, 
but definitely like like felt 

199
00:11:29,550 --> 00:11:32,830
the pain of that mixed world 
and. 

200
00:11:33,870 --> 00:11:38,510
But we've learned that even in 
pure functional languages you 

201
00:11:38,990 --> 00:11:42,670
sometimes have mutability. 
I mean it's it's usually behind 

202
00:11:42,670 --> 00:11:47,270
a wall, so. 
I I think having done like, you 

203
00:11:47,310 --> 00:11:51,430
know most recently a lot of 
Kotlin, Scala, the it's, you 

204
00:11:51,470 --> 00:11:54,470
know, kind of intellectually 
painful to have to make things 

205
00:11:54,470 --> 00:11:59,030
meatable. 
And you know, I my first impulse

206
00:11:59,150 --> 00:12:02,150
after like the last year or so 
has been training myself to try 

207
00:12:02,150 --> 00:12:06,310
to try to do things immediately.
But, you know, it's like you 

208
00:12:06,310 --> 00:12:08,190
kind of have to suppress that 
and be like, yeah, this is a 

209
00:12:08,190 --> 00:12:11,740
different language. 
And you know, see I I had the 

210
00:12:11,740 --> 00:12:13,300
exact opposite problem. 
OK. 

211
00:12:13,380 --> 00:12:16,860
So I I come from a almost 
strictly Python background and I

212
00:12:16,860 --> 00:12:18,860
I am not big into functional 
language. 

213
00:12:18,860 --> 00:12:20,500
I did not, not that I don't like
it. 

214
00:12:20,500 --> 00:12:22,060
I just have not had a lot of 
exposure to it. 

215
00:12:23,100 --> 00:12:27,340
And so I was exploring creating 
a game using Rust this week. 

216
00:12:27,940 --> 00:12:33,620
I I'm kind of an amateur game 
dev and that's an area where I I

217
00:12:33,620 --> 00:12:34,820
was really struggling 
everything. 

218
00:12:34,820 --> 00:12:36,860
I was like, OK, everything's 
mutable right now we're just 

219
00:12:36,860 --> 00:12:38,300
going to, you know, run pass 
these things around. 

220
00:12:38,300 --> 00:12:41,270
Everything needs to mutate, etc 
etc. 

221
00:12:41,270 --> 00:12:44,910
And I was like no, I feel like. 
I feel like I want this to be 

222
00:12:44,910 --> 00:12:46,950
immutable, but I'm not quite. 
Sure. 

223
00:12:47,390 --> 00:12:48,790
Like what the right way to do 
that is. 

224
00:12:48,790 --> 00:12:51,390
So I had the the opposite 
problem that you had where you 

225
00:12:51,390 --> 00:12:52,750
wanted every, you know 
everything wanted to be 

226
00:12:52,750 --> 00:12:54,670
immutable and I was like no, 
everything feels like it needs 

227
00:12:54,670 --> 00:12:58,470
to be immutable and I I'm 
struggling to find out where I 

228
00:12:58,470 --> 00:13:00,550
can make things immutable. 
So that was that's been a 

229
00:13:00,550 --> 00:13:04,470
struggle for me, but. 
It's a yeah, it's a it's an 

230
00:13:04,470 --> 00:13:07,270
evolution. 
But the interesting thing is, is

231
00:13:07,430 --> 00:13:09,490
that. 
You know what I was running into

232
00:13:10,290 --> 00:13:13,730
is I had a. 
You know, I had a function that 

233
00:13:13,730 --> 00:13:15,770
was called from. 
It was actually an argument to 

234
00:13:15,770 --> 00:13:19,650
another function, and then that 
function was working off of a 

235
00:13:19,650 --> 00:13:21,330
data structure. 
That. 

236
00:13:21,810 --> 00:13:27,010
You know, itself at the very key
core had a member field that had

237
00:13:27,010 --> 00:13:28,930
to be mutable because that was 
the purpose of this function was

238
00:13:28,930 --> 00:13:32,650
to go through and populate this 
this data structure and. 

239
00:13:33,850 --> 00:13:36,090
I spent some time wrestling 
around with that because it was 

240
00:13:36,090 --> 00:13:38,650
saying, you know this little 
function right in here, which is

241
00:13:38,690 --> 00:13:42,330
like, you know, pretty deep into
the call chain is trying to 

242
00:13:42,330 --> 00:13:44,650
modify this thing which was 
declared way out here. 

243
00:13:44,650 --> 00:13:47,650
And the compiler traces all the 
way through and said Nope, you 

244
00:13:47,650 --> 00:13:50,490
have to flag this as mutable 
function because you're mutating

245
00:13:50,530 --> 00:13:53,090
something. 
And that's it's really, really, 

246
00:13:53,090 --> 00:13:58,410
really, I I think you would 
really have to work hard to to 

247
00:13:58,490 --> 00:14:01,570
try to subvert that because it's
just deep into the compiler that

248
00:14:01,570 --> 00:14:03,580
it's going to. 
Yeah, check all that for you. 

249
00:14:03,860 --> 00:14:05,980
Yeah. 
Yeah, it's very meticulous. 

250
00:14:06,980 --> 00:14:08,500
So what were you working on, 
Duncan? 

251
00:14:09,620 --> 00:14:14,300
OK, so let's see. 
I came to Rust writing Python 

252
00:14:14,300 --> 00:14:21,740
extension modules. 
So numpy and scipy give real 

253
00:14:21,740 --> 00:14:26,340
performance boost to Python, but
some algorithms can't be cleanly

254
00:14:26,340 --> 00:14:29,260
expressed in using that 
approach. 

255
00:14:30,990 --> 00:14:35,350
And we had some success porting 
just the performance critical 

256
00:14:35,350 --> 00:14:40,230
parts of some applications, some
signal processing algorithms. 

257
00:14:40,710 --> 00:14:46,390
So this week I've been thinking 
about using Rust for higher 

258
00:14:46,390 --> 00:14:51,750
level problems like scientific 
programming in general and web 

259
00:14:51,750 --> 00:14:56,590
applications. 
So I I was looking at Axum which

260
00:14:56,590 --> 00:15:01,720
is a web framework. 
And I've been trying to think 

261
00:15:01,720 --> 00:15:09,520
about error propagation. 
Basically there's there's a 

262
00:15:09,520 --> 00:15:15,600
question mark operator which I 
feel it should have a name, but 

263
00:15:15,600 --> 00:15:18,120
the question. 
That's what I was thinking. 

264
00:15:18,120 --> 00:15:20,760
It's effectively like a flat 
map, yeah. 

265
00:15:21,680 --> 00:15:26,280
But that that really helps you 
to write code that's that's 

266
00:15:26,280 --> 00:15:29,920
really clean. 
Deal with the get the domain 

267
00:15:29,920 --> 00:15:33,320
logic. 
There's a single level of 

268
00:15:33,320 --> 00:15:37,120
abstraction principle where 
you're trying to have everything

269
00:15:37,120 --> 00:15:40,720
at the same level of abstraction
and just with question marks. 

270
00:15:40,720 --> 00:15:43,960
And then deal deal with all the 
errors at a higher level. 

271
00:15:46,080 --> 00:15:53,280
And I was serving up as Felt UI 
from Axon. 

272
00:15:54,760 --> 00:15:56,840
I work along with Single Page 
Applications. 

273
00:15:58,020 --> 00:16:03,980
And so rust and accidents felt 
seems like an interesting 

274
00:16:03,980 --> 00:16:04,980
direction. 
Yeah. 

275
00:16:06,900 --> 00:16:12,900
On the question mark operator, I
it is nice that it's it, it's 

276
00:16:12,900 --> 00:16:15,300
more general than than like in 
cotton. 

277
00:16:15,300 --> 00:16:17,540
The question mark is only on a 
knowable type. 

278
00:16:18,540 --> 00:16:21,780
The fact that you, I think can 
put a question mark on not just 

279
00:16:21,780 --> 00:16:26,990
result but on option and other 
things, it can kind of chain 

280
00:16:26,990 --> 00:16:29,590
onto multiple types. 
I don't know if it does that 

281
00:16:29,590 --> 00:16:36,670
through a type class or. 
Yeah, I just I went and asked 

282
00:16:36,670 --> 00:16:42,430
chat about I go what are the 
different ways to handle errors 

283
00:16:42,430 --> 00:16:45,950
with result and it listed a 
bunch of things then it missed 

284
00:16:46,070 --> 00:16:49,790
at least one thing which I said 
well what about is error? 

285
00:16:49,790 --> 00:16:53,220
Oh yeah, I forgot about that. 
You know, but, so and there's a 

286
00:16:53,220 --> 00:16:55,820
bunch of different ways that you
can handle the result. 

287
00:16:55,820 --> 00:16:59,180
But one of them, I mean the 
cleanest way is the question 

288
00:16:59,180 --> 00:17:06,700
mark, which extracts the success
value, and then if there's a 

289
00:17:06,700 --> 00:17:12,180
failure, it basically throws it 
out to what doesn't throw it. 

290
00:17:12,180 --> 00:17:15,980
That's the one word. 
It passes it out into the result

291
00:17:16,099 --> 00:17:20,020
of the the function that you're 
inside of, and it just. 

292
00:17:20,560 --> 00:17:24,160
It makes it really clean. 
It's really, it's really nice. 

293
00:17:24,160 --> 00:17:27,680
And I guess if you were in 
Scholar it would be the for 

294
00:17:27,680 --> 00:17:32,440
comprehension and then Haskell, 
I think it's the do yeah do 

295
00:17:32,440 --> 00:17:36,000
notation, right? 
So it's picked up from that, but

296
00:17:36,040 --> 00:17:40,800
it's nice that they don't use 
any, you know, functional. 

297
00:17:41,550 --> 00:17:44,950
They don't mention anything 
about monads and all that kind 

298
00:17:44,950 --> 00:17:47,830
of stuff because they they don't
want to go down that path. 

299
00:17:47,950 --> 00:17:51,030
But but when you look at it, you
realize, oh, that's what it is. 

300
00:17:51,030 --> 00:17:54,590
The result is a monad and the 
question mark is basically a 

301
00:17:54,590 --> 00:18:00,550
flat map I think. 
Yeah, the I think I ran into 

302
00:18:00,550 --> 00:18:05,670
some challenges with this where 
in the world of monads you get 

303
00:18:05,670 --> 00:18:09,430
into the whole thing of monad 
Transformers where let's say 

304
00:18:09,430 --> 00:18:13,470
you've got an option and a 
result and you need to kind of 

305
00:18:13,470 --> 00:18:17,670
munch those two things together.
That's where in the world of 

306
00:18:17,670 --> 00:18:20,550
monads you then get into monad 
Transformers and it gets all 

307
00:18:20,790 --> 00:18:24,790
tricky. 
And I don't think that Rust had 

308
00:18:24,790 --> 00:18:28,950
a direct way to do something 
like monad Transformers and so 

309
00:18:28,950 --> 00:18:32,310
then you have to do some kind of
manual unpacking and and pattern

310
00:18:32,310 --> 00:18:38,110
matching which which gets a a 
little bit nastier than I'm used

311
00:18:38,590 --> 00:18:41,350
to. 
But it wasn't it wasn't too bad.

312
00:18:42,910 --> 00:18:48,870
The one really nice thing in 
Rust is not having exceptions 

313
00:18:49,190 --> 00:18:52,990
and just and. 
This is very similar to what the

314
00:18:52,990 --> 00:18:57,390
way that I write code and Colin 
and Scala is putting the the 

315
00:18:58,150 --> 00:19:03,950
exception or the error into a 
data type like result in in in 

316
00:19:03,950 --> 00:19:06,190
REST. 
And that was that. 

317
00:19:06,190 --> 00:19:09,310
Felt so much nicer than than the
world of exceptions. 

318
00:19:09,590 --> 00:19:11,870
Yeah. 
I mean, basically exceptions or 

319
00:19:11,990 --> 00:19:14,470
side effects, right? 
Yeah. 

320
00:19:14,470 --> 00:19:17,310
Yeah. 
So yeah, they're just like, 

321
00:19:19,030 --> 00:19:20,630
yeah, yeah. 
So not not dealing with 

322
00:19:20,630 --> 00:19:26,630
exceptions was certainly nice. 
Yeah, I was looking at or my 

323
00:19:26,910 --> 00:19:34,060
because I've been looking at. 
Structured concurrency in Python

324
00:19:34,620 --> 00:19:39,820
And so I was in particular was 
looking at cancellation and 

325
00:19:40,380 --> 00:19:47,980
seeing how Python when you 
cancel something it it actually 

326
00:19:47,980 --> 00:19:52,020
monitors it, puts the code in 
for you to monitor for 

327
00:19:52,020 --> 00:19:54,860
cancellation and do all the 
necessary cleanup. 

328
00:19:54,860 --> 00:19:58,060
So I was curious about, you 
know, how does Russ do that? 

329
00:19:58,060 --> 00:20:04,510
How does it contrast it? 
And its cancellation system is 

330
00:20:05,790 --> 00:20:08,590
they call it cooperative 
cancellation. 

331
00:20:09,110 --> 00:20:13,150
And it means that you actually 
have to look for. 

332
00:20:13,390 --> 00:20:19,110
You have to put in one of those 
one shot channels, and then you 

333
00:20:19,110 --> 00:20:23,390
have to look for. 
Somewhere in your task. 

334
00:20:23,390 --> 00:20:27,710
You have to be looking for a 
cancellation signal and then. 

335
00:20:28,250 --> 00:20:32,490
When that happens, you can 
return from it, or you know 

336
00:20:32,970 --> 00:20:35,490
whatever it is that you want to 
do, so it's explicit. 

337
00:20:36,050 --> 00:20:39,850
So Rust tends to be a lot more 
explicit in things, but it does.

338
00:20:40,850 --> 00:20:45,330
We did figure out that in the 
Tokyo library when we were using

339
00:20:45,330 --> 00:20:52,090
the select, it does. 
So what select does is it runs a

340
00:20:52,090 --> 00:20:55,170
number of tasks against each 
other and the first one that 

341
00:20:55,170 --> 00:21:00,210
succeeds it returns as its 
result and then the rest it 

342
00:21:00,210 --> 00:21:04,530
cancels. 
And it does do clean up when it 

343
00:21:04,530 --> 00:21:05,530
does that. 
So. 

344
00:21:05,770 --> 00:21:09,810
So there is some, there is some 
automation, but also you have to

345
00:21:09,810 --> 00:21:16,930
be ready to do it yourself. 
You'll monitor for cancellation 

346
00:21:16,930 --> 00:21:20,770
yourself in in normal code. 
Yeah. 

347
00:21:20,770 --> 00:21:24,290
So anybody have any other 
thoughts or things they learn 

348
00:21:24,290 --> 00:21:26,010
before we go on the structure 
concurrency? 

349
00:21:27,700 --> 00:21:30,580
I guess one point in the 
question mark operator, what 

350
00:21:30,580 --> 00:21:35,180
came out of that was like there 
is an error message around using

351
00:21:35,180 --> 00:21:39,460
that. 
That is actually one of the rare

352
00:21:39,460 --> 00:21:40,940
times. 
But one of the nice things is 

353
00:21:40,940 --> 00:21:42,820
being somebody learning the 
language is the compiler gives 

354
00:21:42,820 --> 00:21:46,300
you a lot of help. 
About 80% of the time it's going

355
00:21:46,300 --> 00:21:49,460
to give you a hint as to what 
you probably need to do. 

356
00:21:51,310 --> 00:21:53,430
And this one particular case, 
you use the question mark 

357
00:21:53,430 --> 00:21:56,230
operator in a function that 
doesn't return an option or 

358
00:21:56,230 --> 00:21:58,950
result. 
The the error message is a 

359
00:21:58,950 --> 00:22:01,750
little confusing and but 
effectively that's what it's 

360
00:22:01,750 --> 00:22:04,550
saying is you know you can't do 
this because you can only use 

361
00:22:04,550 --> 00:22:07,950
the question mark operator in a 
function that returns optional 

362
00:22:07,950 --> 00:22:13,030
result. 
And it kind of made me think of 

363
00:22:13,270 --> 00:22:15,910
with respect to concurrency if 
you work in these languages that

364
00:22:15,910 --> 00:22:19,570
have. 
Async operators, you have the 

365
00:22:19,570 --> 00:22:22,890
whole idea of what color is your
function and it's kind of the 

366
00:22:22,890 --> 00:22:25,690
same thing that you've got to 
decide. 

367
00:22:26,290 --> 00:22:29,530
Am I going to follow this normal
error protocol? 

368
00:22:29,850 --> 00:22:32,570
And if I do then I can use you 
know, things like shortcuts like

369
00:22:32,570 --> 00:22:35,450
question mark operator. 
If I don't then you know you're 

370
00:22:35,490 --> 00:22:38,970
stuck with some more manual way 
of handling stuff because you 

371
00:22:38,970 --> 00:22:41,370
don't have a way to to really 
propagate out those errors. 

372
00:22:41,370 --> 00:22:44,580
So it kind of. 
It's kind of the same situation 

373
00:22:44,580 --> 00:22:47,580
that governs how you design your
functions, because you know, you

374
00:22:47,580 --> 00:22:49,980
have to think about, you know 
how am I going to return 

375
00:22:49,980 --> 00:22:51,140
another. 
So what am I going to do if I 

376
00:22:51,140 --> 00:22:55,660
did an error right, And if the 
question mark produces an error 

377
00:22:55,940 --> 00:22:58,660
that isn't part? 
Basically, the general idea is 

378
00:22:58,660 --> 00:23:01,300
if it produces an error that 
isn't part of the signature of 

379
00:23:01,300 --> 00:23:06,500
your return type, the compiler 
will say, oh, that won't work, 

380
00:23:06,500 --> 00:23:11,260
because you've told me that this
thing returns, you know, this 

381
00:23:11,260 --> 00:23:13,900
particular kind of error, and 
that question mark produces a 

382
00:23:13,900 --> 00:23:16,540
different kind of error. 
So you have to go up and and 

383
00:23:16,540 --> 00:23:19,060
specify it. 
Yeah, yeah, so. 

384
00:23:19,260 --> 00:23:22,740
The one tricky piece that we ran
into and did figure out around 

385
00:23:22,740 --> 00:23:26,420
this was if you've got a 
function that can fail in 

386
00:23:26,420 --> 00:23:30,500
multiple different ways, how do 
you then put that into the air? 

387
00:23:30,980 --> 00:23:37,390
Air channel, the air type and. 
The the way that I would do that

388
00:23:37,390 --> 00:23:45,030
in Scala is with a sum type, 
that is a fails. 

389
00:23:45,030 --> 00:23:48,470
Well in our case it was either a
request error, so the request 

390
00:23:48,470 --> 00:23:51,630
failed in some way or a timeout 
error. 

391
00:23:52,110 --> 00:23:57,350
And through an anonymous sum 
type you can just say request 

392
00:23:57,350 --> 00:24:02,630
error or timeout error and. 
Though it seems like there's an 

393
00:24:02,630 --> 00:24:05,910
open proposal in Rust to add 
anonymous some types to the 

394
00:24:05,910 --> 00:24:09,270
language, but I don't think it's
available yet. 

395
00:24:09,710 --> 00:24:13,310
And So what we ended up doing 
was creating an enum to 

396
00:24:13,310 --> 00:24:17,710
represent that some type. 
But then we had to transform our

397
00:24:17,710 --> 00:24:23,580
AIR into that enum. 
To to represent that. 

398
00:24:23,580 --> 00:24:27,700
So it it was fine. 
But yeah, if if there were 

399
00:24:27,740 --> 00:24:30,780
anonymous subtypes, it would 
have cleaned that up a bit. 

400
00:24:31,220 --> 00:24:32,860
Yeah, it's a pretty sweet 
feature. 

401
00:24:32,860 --> 00:24:35,380
Python has it as well. 
And what about? 

402
00:24:35,620 --> 00:24:37,660
Does does Cotman have something 
like that? 

403
00:24:39,500 --> 00:24:41,940
You would do it the same way 
that we ended up doing it, 

404
00:24:41,940 --> 00:24:43,260
thrust within the camera or 
something. 

405
00:24:43,580 --> 00:24:47,180
So. 
So I guess you call it an enum 

406
00:24:47,180 --> 00:24:49,900
and explicit subtype. 
Yeah, right. 

407
00:24:50,980 --> 00:24:54,830
Yeah. 
Yeah, so that that part wasn't 

408
00:24:54,870 --> 00:24:57,430
wasn't too bad. 
I mean we were able to model our

409
00:24:57,430 --> 00:25:00,350
data structure fairly easily in 
the way that we wanted to. 

410
00:25:00,350 --> 00:25:07,750
But yeah the the async support 
out-of-the-box is is definitely 

411
00:25:07,750 --> 00:25:12,390
nice. 
And yeah, I don't know, I felt 

412
00:25:12,390 --> 00:25:16,990
like yeah, the async async stuff
felt felt like a good approach 

413
00:25:17,030 --> 00:25:19,230
and but pretty typical I think 
these days of. 

414
00:25:19,710 --> 00:25:23,510
Colored function approach of and
you need to indicate that this 

415
00:25:23,510 --> 00:25:29,430
is async and we were able to get
through all of the Easy Racer 

416
00:25:29,510 --> 00:25:32,630
exercises. 
Yeah, at least with Tokyo. 

417
00:25:32,630 --> 00:25:35,910
Yeah yeah. 
Which is seems like the most 

418
00:25:36,270 --> 00:25:40,630
like the first library you you 
should reach for if cuz it's 

419
00:25:40,910 --> 00:25:47,430
there isn't a Rust's philosophy 
is providing just enough in the 

420
00:25:47,430 --> 00:25:51,030
core language, but not assuming 
that there's an operating 

421
00:25:51,030 --> 00:25:54,270
system, which is really nice if 
you're working on hardware, like

422
00:25:54,270 --> 00:25:56,310
the interview that we did on our
year or so. 

423
00:25:56,710 --> 00:26:00,110
Yeah, they were able to put 
something on hardware that was 

424
00:26:00,110 --> 00:26:05,430
using async and thus have 
shorter wake up times and then 

425
00:26:05,430 --> 00:26:08,830
longer battery life. 
Yeah, well Okay, that's pretty 

426
00:26:08,830 --> 00:26:12,510
neat. 
But their architecture has to be

427
00:26:12,510 --> 00:26:15,230
a little different to do that 
and so you always have to go 

428
00:26:15,590 --> 00:26:18,750
find a library and there's 
there's nothing you know like 

429
00:26:18,790 --> 00:26:22,830
Python has the built in async 
I/O library, whereas rest you 

430
00:26:22,830 --> 00:26:27,630
have to choose a library but the
most common one is Tokyo and 

431
00:26:27,630 --> 00:26:31,910
that but that assumes you have 
an operating system, so building

432
00:26:31,910 --> 00:26:34,670
everything with that. 
Yeah. 

433
00:26:35,550 --> 00:26:38,510
Oh, I wanted to point out one of
the other challenges that I had 

434
00:26:38,510 --> 00:26:40,700
was. 
The air messages are often 

435
00:26:40,700 --> 00:26:44,300
really helpful, but as soon as 
we dove into the world of using 

436
00:26:44,300 --> 00:26:51,900
macros in more more complex ways
then some of the the nice things

437
00:26:51,900 --> 00:26:55,780
that you usually get with the 
helpful air messages did fall 

438
00:26:55,780 --> 00:26:59,100
apart a bit as we went into 
macro land and that was 

439
00:26:59,100 --> 00:27:03,780
specifically on the the Tokyo 
Select macro and I remember 

440
00:27:03,860 --> 00:27:07,380
struggling through. 
That a bit because the error 

441
00:27:07,380 --> 00:27:09,820
messages all of a sudden weren't
as helpful as they were when 

442
00:27:09,820 --> 00:27:15,260
you're in non macro land. 
I think it depends on the macro 

443
00:27:15,300 --> 00:27:17,260
writer. 
That was my impression, in other

444
00:27:17,260 --> 00:27:17,940
words. 
Could. 

445
00:27:18,420 --> 00:27:24,100
You try again. 
It could be, it could be on the 

446
00:27:24,860 --> 00:27:30,340
web, It could be well done, but 
it requires the macro writer to,

447
00:27:30,700 --> 00:27:33,260
you know, know enough about it 
to. 

448
00:27:34,390 --> 00:27:36,430
But I could be wrong about that.
Maybe it's just in? 

449
00:27:36,430 --> 00:27:39,470
Your maybe the macro could do a 
better job. 

450
00:27:39,470 --> 00:27:42,470
Yeah, helpful error messages or 
something, right? 

451
00:27:44,270 --> 00:27:48,790
Yeah, And it was interesting to 
see in Tokyo Select's case that 

452
00:27:49,030 --> 00:27:53,510
they almost created like a DSL 
and it was the first time I'd 

453
00:27:53,510 --> 00:27:59,790
seen in Rust using a macro to 
create a DSL looking thing. 

454
00:28:01,230 --> 00:28:03,640
But then. 
The challenge with that is that 

455
00:28:04,400 --> 00:28:08,120
whenever you're in kind of a DSL
land, you're no longer in in the

456
00:28:08,120 --> 00:28:11,000
normal land. 
And then I need more 

457
00:28:11,160 --> 00:28:15,280
documentation, more examples, 
more assistance, because I'm in 

458
00:28:15,280 --> 00:28:17,720
kind of a different, a little 
bit different of a world. 

459
00:28:17,960 --> 00:28:20,400
And so I remember with Tokyo 
Select kind of struggling with 

460
00:28:20,760 --> 00:28:26,000
what is this thing doing. 
It's not normal Rust code, so So

461
00:28:26,000 --> 00:28:29,240
what? 
What do I do in in this in in 

462
00:28:29,240 --> 00:28:33,610
this macro DSL land? 
And most macros that we use, 

463
00:28:33,610 --> 00:28:36,650
whether you know, Printland, 
whatever, don't have, yeah, 

464
00:28:36,650 --> 00:28:38,610
straightforward. 
They don't have kind of a DSL to

465
00:28:38,610 --> 00:28:40,730
it. 
But Tokyo Select had had a bit 

466
00:28:40,730 --> 00:28:44,730
of a, yeah, that was kind of an 
eye opener because you realize, 

467
00:28:44,810 --> 00:28:48,930
oh, it's possible to create a 
kind of a DSL inside of a macro.

468
00:28:48,930 --> 00:28:50,330
Yeah, you know that. 
Yeah. 

469
00:28:50,970 --> 00:28:52,210
So. 
Yeah, and I don't know how 

470
00:28:52,210 --> 00:28:55,450
common that is in rest beyond 
Tokyo Select. 

471
00:28:55,770 --> 00:28:59,530
Like if that's the first time 
I've cyclical, you know, I don't

472
00:28:59,530 --> 00:29:04,200
have vast experience, so it 
could be a common thing that we 

473
00:29:04,200 --> 00:29:09,560
just haven't seen much of. 
Yeah, and then the other thing 

474
00:29:09,560 --> 00:29:13,760
we realized there was that as we
were working through Easy Racer.

475
00:29:13,760 --> 00:29:19,200
So Easy Racer is a bunch of 
scenarios to test approaches to 

476
00:29:19,200 --> 00:29:24,040
structure concurrency. 
And the basic ones say okay race

477
00:29:24,040 --> 00:29:26,720
these two things against each 
other and Tokyo Select is a 

478
00:29:26,720 --> 00:29:32,180
really easy way to do that race.
But we discovered when we got to

479
00:29:32,180 --> 00:29:35,700
the scenario three, an easy 
racer where you have to race 

480
00:29:35,700 --> 00:29:40,540
10,000 concurrent things, the 
macro doesn't work because it's 

481
00:29:40,580 --> 00:29:44,180
it's a runtime sized thing and 
the macro works. 

482
00:29:44,940 --> 00:29:48,760
Yeah. 
Well, the 10,000 is well, your. 

483
00:29:48,800 --> 00:29:52,280
Yeah, your problem required 
runtime, so yeah, but yeah, the 

484
00:29:52,280 --> 00:29:54,560
macro says you have to 
explicitly say. 

485
00:29:54,560 --> 00:29:56,520
Here are all. 
My tasks here are all my tasks. 

486
00:29:56,640 --> 00:30:00,200
Yeah, it was not made for. 
The dynamic made, yeah, exactly 

487
00:30:00,200 --> 00:30:02,400
thing that you wanted. 
So we had to find a different 

488
00:30:02,400 --> 00:30:04,000
approach for that particular 
one. 

489
00:30:05,120 --> 00:30:08,320
But it was interesting like, oh,
the macro is super helpful when 

490
00:30:08,320 --> 00:30:11,680
you're in the constraints of 
what they've designed it for. 

491
00:30:13,070 --> 00:30:17,030
And I don't think that a macro 
could do what we're trying to do

492
00:30:17,630 --> 00:30:20,230
because it has to be run at 
compile time. 

493
00:30:20,310 --> 00:30:24,790
Yeah, it's, it's. 
I mean, like when you look at 

494
00:30:26,950 --> 00:30:31,470
the sort of the initial use case
for the macro is, oh, I have a 

495
00:30:31,590 --> 00:30:34,590
variable argument list where 
Russ goes, well, we don't do 

496
00:30:34,590 --> 00:30:36,230
that. 
You have to have everything at 

497
00:30:36,230 --> 00:30:40,870
compile time, but the macro can 
actually handle that. 

498
00:30:41,510 --> 00:30:45,270
But then it's. 
So the idea is it's like, OK, it

499
00:30:45,270 --> 00:30:48,150
writes the code for your 
multiple different arguments, 

500
00:30:48,550 --> 00:30:51,870
but then the compiler goes 
through and it says, all right, 

501
00:30:51,870 --> 00:30:53,350
I know everything at compile 
time. 

502
00:30:53,350 --> 00:30:57,030
So yeah, that's the kind of Rust
philosophy is we got to know 

503
00:30:57,030 --> 00:30:58,270
everything at compile time, 
yeah. 

504
00:31:01,350 --> 00:31:05,950
So yeah, any other thoughts or 
learnings before we go on the 

505
00:31:05,950 --> 00:31:10,270
structure concurrency? 
I don't know. 

506
00:31:10,390 --> 00:31:13,930
This was a this is a very good 
week for me. 

507
00:31:14,450 --> 00:31:19,250
I just, yeah, I felt like I 
moved forward significantly 

508
00:31:20,010 --> 00:31:21,610
nice. 
It was really nice to have 

509
00:31:21,610 --> 00:31:24,130
everybody around kind of working
on the same thing. 

510
00:31:25,010 --> 00:31:27,610
So yeah, it's a good, it's a 
good experience. 

511
00:31:27,610 --> 00:31:31,410
It's fun. 
So. 

512
00:31:33,140 --> 00:31:37,300
Bruce and I were Bruce has been 
exploring Structure Concurrency 

513
00:31:37,420 --> 00:31:41,460
and I was trying to get the easy
race or REST stuff working this 

514
00:31:41,460 --> 00:31:46,620
week, which is structure 
concurrency oriented and maybe 

515
00:31:46,620 --> 00:31:49,220
we should start with what is 
Structure concurrency? 

516
00:31:49,220 --> 00:31:51,340
You want to take a stab at it? 
Sure, yeah. 

517
00:31:51,340 --> 00:31:54,020
It comes from. 
Well, the reason for the 

518
00:31:54,060 --> 00:32:02,000
structure term is because way 
back, like in the 60s, some of 

519
00:32:02,000 --> 00:32:05,840
the computer scientists started 
noticing that all the Go Tos 

520
00:32:06,160 --> 00:32:12,040
produced crazy unmaintainable 
code you didn't know where you 

521
00:32:12,040 --> 00:32:13,920
were going to end up with. 
The spaghetti? 

522
00:32:14,000 --> 00:32:17,280
Yes, the spaghetti. 
And so the idea was okay. 

523
00:32:18,320 --> 00:32:21,520
What we should do is move to 
putting everything in functions.

524
00:32:21,520 --> 00:32:24,600
Of course the functional 
programmers knew that already, 

525
00:32:25,610 --> 00:32:28,810
but that way you have a single 
entry point and a single exit 

526
00:32:28,810 --> 00:32:30,650
point. 
Even if you do early returns, 

527
00:32:30,850 --> 00:32:34,090
you're still exiting at this 
single point. 

528
00:32:34,490 --> 00:32:39,530
And that way you have a scope, 
and the scope allows you to say,

529
00:32:39,530 --> 00:32:42,170
all right, you build things, we 
can make sure that they get all 

530
00:32:42,170 --> 00:32:45,690
cleaned up. 
Everything you know, drop the 

531
00:32:45,690 --> 00:32:48,290
stack pointer for all the stuff 
that you need. 

532
00:32:48,770 --> 00:32:52,250
Everything that you do gets 
cleaned up as you exit the 

533
00:32:52,250 --> 00:32:56,360
function. 
So we have small scopes all over

534
00:32:56,360 --> 00:32:59,120
the place instead of 1 giant 
scope where we're jumping all 

535
00:32:59,120 --> 00:33:01,200
over the place. 
So that's where the go to 

536
00:33:01,200 --> 00:33:07,600
considered harmful. 
And then Nathaniel Smith wrote, 

537
00:33:08,200 --> 00:33:11,360
you know, a number of years ago 
wrote this blog post called go 

538
00:33:11,600 --> 00:33:14,640
statement considered harmful. 
And I think he was specifically 

539
00:33:14,640 --> 00:33:18,440
talking about the go statement 
in the Go language, because you 

540
00:33:18,440 --> 00:33:22,120
just say go fire up a function 
and then the functions off there

541
00:33:22,120 --> 00:33:25,600
running. 
When does it ever get collected?

542
00:33:26,400 --> 00:33:28,840
How do you get the result? 
How do you cancel it? 

543
00:33:30,040 --> 00:33:32,680
You kind of lost the linear. 
You basically lost you. 

544
00:33:32,720 --> 00:33:35,280
You're just firing it off. 
Very back into Go. 

545
00:33:35,560 --> 00:33:38,360
Go to. 
Yeah, very similar to to the 

546
00:33:39,040 --> 00:33:44,080
jumps, the, the, and the reason 
that they had to fight their way

547
00:33:44,080 --> 00:33:46,920
out of it is because so many 
people were coming from assembly

548
00:33:46,920 --> 00:33:49,800
language programming, and that 
was just how you did it. 

549
00:33:49,800 --> 00:33:52,200
You didn't, you didn't write all
these nice little neat 

550
00:33:52,200 --> 00:33:55,800
functions, you just jumped. 
And so they had to be pushed 

551
00:33:55,800 --> 00:33:58,720
into using functions. 
And now that's kind of the 

552
00:33:59,160 --> 00:34:00,840
standard way of thinking of 
things. 

553
00:34:00,840 --> 00:34:06,280
We write functions everywhere. 
So what this blog post 

554
00:34:06,280 --> 00:34:08,840
suggested, and I don't think he 
was the first one to come up 

555
00:34:08,840 --> 00:34:13,040
with it, but he made it as clear
as possible, is that, well, we 

556
00:34:13,040 --> 00:34:15,120
need a kind of a different kind 
of a scope. 

557
00:34:15,639 --> 00:34:20,340
And so we create a scope, we 
create tasks within that scope, 

558
00:34:20,780 --> 00:34:26,300
and then the scope guarantees 
that those tasks are finished 

559
00:34:26,540 --> 00:34:33,100
before we exit the scope. 
And so that that's kind of the 

560
00:34:33,100 --> 00:34:36,340
foundation of structured 
concurrency. 

561
00:34:36,340 --> 00:34:42,219
But there's some other things 
which are not completely clear 

562
00:34:42,219 --> 00:34:44,940
to me. 
It seems like you also need a 

563
00:34:44,940 --> 00:34:49,110
reliable cancellation mechanism 
in a reliable error handling 

564
00:34:49,110 --> 00:34:54,949
mechanism. 
And Python has well, I mentioned

565
00:34:54,949 --> 00:34:59,270
the cancellation stuff, but it 
also in the most recent version 

566
00:34:59,270 --> 00:35:03,110
has added called something 
called exception groups. 

567
00:35:03,470 --> 00:35:06,950
So it's something that is 
treated like a normal exception,

568
00:35:07,270 --> 00:35:09,990
but it can actually hold 
multiple exceptions within it. 

569
00:35:10,430 --> 00:35:15,110
Because if you fire off a bunch 
of tasks, they could all fail, 

570
00:35:15,550 --> 00:35:17,950
or you know, multiple ones that 
fail. 

571
00:35:18,350 --> 00:35:22,430
And if there's only if if the 
first exception is the only one 

572
00:35:22,670 --> 00:35:25,550
you hear, then the rest of them 
get lost. 

573
00:35:25,590 --> 00:35:30,230
And so that was why it was 
necessary to add this feature in

574
00:35:30,230 --> 00:35:36,190
Python, but so the. 
Task or the error group? 

575
00:35:36,190 --> 00:35:38,390
What is it called? 
Exception. 

576
00:35:38,390 --> 00:35:41,950
Group exception group allows you
to have these different. 

577
00:35:42,410 --> 00:35:47,770
Things concurrently and then 
aggregate the errors across the.

578
00:35:48,050 --> 00:35:51,330
All of the things that fail can 
come back into a exception 

579
00:35:51,330 --> 00:35:56,130
group, and it seems like that 
that has to be inherently 

580
00:35:56,130 --> 00:35:59,370
connected to structured 
exceptions because the exception

581
00:35:59,370 --> 00:36:03,850
group is what comes back from 
the scope that is managing the 

582
00:36:03,850 --> 00:36:06,010
exceptions. 
Yeah, I just realized that this 

583
00:36:06,010 --> 00:36:10,630
moment, it's like, OK, that's 
got to be tied to that exception

584
00:36:10,630 --> 00:36:15,710
scope that is creating those 
tasks because who else are they 

585
00:36:15,710 --> 00:36:19,190
going to report to? 
And it and it has to be to that 

586
00:36:19,190 --> 00:36:22,230
scope. 
So yeah, I would say that both 

587
00:36:24,070 --> 00:36:29,710
both cancellation and error 
handling almost have to be an 

588
00:36:29,710 --> 00:36:34,470
essential part of structured 
exception of structured 

589
00:36:34,470 --> 00:36:38,880
concurrency, yeah. 
Yeah, and I think the what 

590
00:36:38,880 --> 00:36:44,280
structure concurrency tries to 
do is say, all right, a 

591
00:36:44,280 --> 00:36:48,600
function, a given function is 
not enough to model the things 

592
00:36:49,560 --> 00:36:53,440
that you need when you're in a 
concurrent world, but how do we 

593
00:36:53,440 --> 00:36:58,200
avoid the the go to 
spaghettiness And we have to be 

594
00:36:58,200 --> 00:37:03,160
able to have a bunch of things. 
Running concurrently and get 

595
00:37:03,160 --> 00:37:06,680
back the results from those 
things and the errors from those

596
00:37:06,680 --> 00:37:11,200
things and cancel cancel things 
when when needed. 

597
00:37:12,440 --> 00:37:15,120
And so yeah, it seems like like 
it was like, OK, a function 

598
00:37:15,120 --> 00:37:19,760
doesn't give you the 
cancellation, the the error 

599
00:37:19,760 --> 00:37:24,280
aggregation, all that stuff, and
so we need another concept there

600
00:37:24,280 --> 00:37:26,400
and structure concurrency gives 
us that concept. 

601
00:37:26,680 --> 00:37:29,320
One of the things I've wondered 
about with structure concurrency

602
00:37:29,320 --> 00:37:31,290
is. 
We call it structure 

603
00:37:31,290 --> 00:37:36,010
concurrency, but what is the 
structure of it and the only the

604
00:37:36,010 --> 00:37:40,410
only thing that I've seen is a 
hierarchical structure where you

605
00:37:40,410 --> 00:37:43,440
have. 
You have a something that owns 

606
00:37:43,440 --> 00:37:47,200
children essentially, but then 
those children can have other 

607
00:37:47,200 --> 00:37:49,640
children and so on. 
So you can create a hierarchy if

608
00:37:49,640 --> 00:37:53,760
you want to, or you can keep it 
a single depth tree. 

609
00:37:54,320 --> 00:37:58,960
But but the hierarchy with 
having a parent and children is 

610
00:37:59,120 --> 00:38:01,280
is the only structure that I've 
seen for. 

611
00:38:01,520 --> 00:38:06,040
I would argue that the what's in
common between a function and 

612
00:38:06,040 --> 00:38:10,110
structure concurrency is scope. 
So it's like I'm creating a 

613
00:38:10,110 --> 00:38:14,950
scope in both cases and the the 
structure concurrency thing is 

614
00:38:14,950 --> 00:38:18,350
like it's a different kind of a 
scope but and then when you 

615
00:38:18,350 --> 00:38:21,470
start looking at these things 
you, well, you look at Rust and 

616
00:38:21,470 --> 00:38:25,270
you look at its lifetime and you
go, oh the lifetime seems like 

617
00:38:25,270 --> 00:38:28,110
it's maybe a different kind of 
scope as well. 

618
00:38:28,550 --> 00:38:30,510
And that's I think that's what 
it comes down to. 

619
00:38:30,510 --> 00:38:35,150
It's like we humans, yes, we 
humans can only handle a little 

620
00:38:35,750 --> 00:38:39,710
bit of stuff at once. 
And so we have to make sure that

621
00:38:39,710 --> 00:38:43,110
that's, you know, clean and 
independent so that we can 

622
00:38:43,470 --> 00:38:45,550
reason about it. 
And then. 

623
00:38:45,710 --> 00:38:48,710
So by creating these scopes we 
achieve that. 

624
00:38:49,150 --> 00:38:53,150
Yeah, yeah. 
So must all be about scope, 

625
00:38:53,150 --> 00:38:56,190
whether it's it's function. 
The way that we avoid the 

626
00:38:56,190 --> 00:38:59,630
spaghettiness is by scoping 
things and. 

627
00:39:00,030 --> 00:39:02,990
In the case of structured 
concurrency is scoping with 

628
00:39:02,990 --> 00:39:06,190
cancellation, concurrency and 
air handling. 

629
00:39:06,190 --> 00:39:10,830
And when you look at I mean you 
know way back when you were I 

630
00:39:10,830 --> 00:39:13,550
don't know if you remember 
Modula, the language Modula. 

631
00:39:13,550 --> 00:39:16,750
Modula 2. 
Well that that the whole 

632
00:39:17,630 --> 00:39:21,150
evolution there was the idea of 
modules which is another kind of

633
00:39:21,150 --> 00:39:24,590
scope and rest has those. 
You know, we saw that with, you 

634
00:39:24,590 --> 00:39:27,510
know, you can have your library 
code and in the same file you 

635
00:39:27,510 --> 00:39:33,330
can create a module which is 
just for tests, for example and 

636
00:39:33,450 --> 00:39:36,570
and yeah, it's a different form 
of scoping. 

637
00:39:36,770 --> 00:39:41,330
Yeah, I guess it's what the 
compiler sees. 

638
00:39:41,370 --> 00:39:42,970
Something to something to do 
with that? 

639
00:39:42,970 --> 00:39:46,690
So in the The Ghost and 
Concerned Harmful article he 

640
00:39:46,690 --> 00:39:49,610
introduces his own framework 
which was for Python I think 

641
00:39:49,610 --> 00:39:53,770
right Treo right. 
And their obstruction was the 

642
00:39:53,770 --> 00:39:56,850
nursery. 
So that's their that's the 

643
00:39:56,890 --> 00:39:58,410
scope. 
The nursery is the scope, yeah 

644
00:39:58,610 --> 00:39:59,810
yeah. 
And then every. 

645
00:40:00,010 --> 00:40:05,610
So you create a nursery and then
each time you create a task you 

646
00:40:06,650 --> 00:40:12,170
create it from that nursery 
object and then Python itself 

647
00:40:12,690 --> 00:40:16,930
changed so its async IO library 
has a task group. 

648
00:40:17,720 --> 00:40:20,920
And that which is basically the 
same thing, but. 

649
00:40:20,960 --> 00:40:24,560
Ultimately just a scope and but 
the thing about the task group 

650
00:40:24,600 --> 00:40:27,880
is that it also manages the 
exception groups. 

651
00:40:28,360 --> 00:40:33,560
So which and I wrote a blog 
post, I think the last one I 

652
00:40:33,560 --> 00:40:38,240
wrote where I looked at that and
I said oh so async I/O. 

653
00:40:38,360 --> 00:40:42,360
The standard Python library has 
this structured exception 

654
00:40:42,360 --> 00:40:46,350
handling that it works with its 
task group, but trio doesn't. 

655
00:40:46,550 --> 00:40:49,270
I mean because it it almost has 
to be part of the language. 

656
00:40:49,270 --> 00:41:00,150
So it seems like the async I/O 
library is more useful than trio

657
00:41:00,150 --> 00:41:03,790
can be, and so I'm not sure that
was the question I left to the. 

658
00:41:04,030 --> 00:41:06,750
Language support? 
Yeah, for the exception group, 

659
00:41:07,150 --> 00:41:11,070
right? 
So I'm not sure if I mean my in,

660
00:41:12,340 --> 00:41:16,740
you know, my result was oh, I 
think I want to use the task 

661
00:41:16,740 --> 00:41:21,060
groups because it has this 
better support and I'm not even 

662
00:41:21,060 --> 00:41:23,940
sure if if trio or any of the 
other third party libraries. 

663
00:41:25,180 --> 00:41:27,540
I suppose they could probably 
catch up with it, but I'm not 

664
00:41:27,540 --> 00:41:29,340
sure. 
Anyway, it's there now, so. 

665
00:41:30,340 --> 00:41:33,220
And we was a week or two ago did
get the. 

666
00:41:34,910 --> 00:41:42,110
The Python, easy racer, async IO
stuff all working so that was 

667
00:41:42,110 --> 00:41:47,110
nice to see. 
So I think for structure 

668
00:41:47,110 --> 00:41:50,870
concurrency, the kind of 
primitive that I've seen across 

669
00:41:50,870 --> 00:41:54,790
now many different languages is 
the idea of a nursery or scope, 

670
00:41:55,110 --> 00:41:58,110
and the way that it gets used is
you create your scope. 

671
00:41:58,540 --> 00:42:02,940
And then you add tasks into that
scope and then you determine 

672
00:42:03,740 --> 00:42:07,660
what you want to do with those 
tasks that are that are now in 

673
00:42:07,660 --> 00:42:11,260
the scope. 
And so the the two typical ones 

674
00:42:11,260 --> 00:42:17,500
are a race which is often called
a select, and the select says as

675
00:42:17,500 --> 00:42:22,060
soon as one task in the scope 
completes, either with an error 

676
00:42:22,060 --> 00:42:25,330
or with a value. 
Then cancel all the other things

677
00:42:25,330 --> 00:42:31,370
in that scope and pass that one 
thing out to to to your 

678
00:42:31,690 --> 00:42:35,850
consumer. 
And so that select is what we 

679
00:42:35,850 --> 00:42:38,370
used in many of the easy racer 
ones because a lot of them are 

680
00:42:38,370 --> 00:42:44,490
race based structure concurrency
challenges and so select seems 

681
00:42:44,490 --> 00:42:48,530
to be pretty universal for 
structured concurrency. 

682
00:42:48,530 --> 00:42:50,970
The idea of the scope and then 
and then being able to do a 

683
00:42:50,970 --> 00:42:54,480
select. 
The other approach, once you 

684
00:42:54,480 --> 00:42:56,720
have your things in your scope, 
is a join. 

685
00:42:56,760 --> 00:43:01,560
Is what it's called in Rust, and
trying to think of other 

686
00:43:01,640 --> 00:43:03,240
languages, have a joint. 
Yeah. 

687
00:43:03,560 --> 00:43:07,040
And so the joint says run all 
these things and just give me 

688
00:43:07,040 --> 00:43:10,160
back all of the results and 
exceptions from all of those 

689
00:43:10,160 --> 00:43:14,320
things And so. 
So those are kind of the two I 

690
00:43:14,320 --> 00:43:19,130
think, kind of primitive. 
Things that you can do once you 

691
00:43:19,130 --> 00:43:20,930
have a structured concurrency 
scope. 

692
00:43:20,930 --> 00:43:25,210
But what structured concurrency?
I mean, normally you would like 

693
00:43:25,210 --> 00:43:27,250
without structured concurrency. 
You would create a bunch of 

694
00:43:27,250 --> 00:43:30,330
tasks and then you would put a 
join to to. 

695
00:43:30,570 --> 00:43:33,610
At some point you would 
basically artificially create 

696
00:43:33,610 --> 00:43:36,370
your own scope that way. 
So what structured concurrency 

697
00:43:36,370 --> 00:43:40,690
does effectively is it puts. 
It quietly puts its own join in 

698
00:43:40,770 --> 00:43:42,170
at the end of the scope. 
Yeah. 

699
00:43:44,120 --> 00:43:47,840
And in the case of the Python 
one, we did have to and I think 

700
00:43:47,840 --> 00:43:53,000
some of the scenarios do the 
join but then manually manage 

701
00:43:53,000 --> 00:43:58,480
cancellation of the tasks. 
So we were we were doing a race 

702
00:43:58,480 --> 00:44:04,400
on top of a join and I don't 
remember why, but but what we 

703
00:44:04,400 --> 00:44:08,040
would do is do our join and then
as soon as we got one of the the

704
00:44:08,640 --> 00:44:12,560
things in the scope to complete 
then we would cancel all the 

705
00:44:12,560 --> 00:44:13,960
others and so we were kind of 
doing. 

706
00:44:14,040 --> 00:44:16,920
Manual a manual select and 
something like that because was 

707
00:44:16,920 --> 00:44:20,120
there not a select and they 
think. 

708
00:44:20,560 --> 00:44:24,640
There, there was. 
So there was. 

709
00:44:24,640 --> 00:44:27,960
But there was some of the 
scenarios where it didn't work 

710
00:44:27,960 --> 00:44:30,240
for us, and I can't remember the
details on why it didn't work. 

711
00:44:30,440 --> 00:44:36,120
So then we had to kind of do our
own, our own select, Yeah, we 

712
00:44:36,120 --> 00:44:38,760
had to essentially create our 
own select implementation that 

713
00:44:38,760 --> 00:44:40,320
worked the way that we needed it
to. 

714
00:44:40,920 --> 00:44:44,800
So in Cotland, I mean because 
this is the first place that I 

715
00:44:44,800 --> 00:44:47,200
came across the idea of 
structured currency was in 

716
00:44:47,240 --> 00:44:49,520
Cotland. 
When we do structured currency, 

717
00:44:50,200 --> 00:44:51,680
you of course know what that 
means. 

718
00:44:52,040 --> 00:44:55,440
That was the the implication. 
And so which I didn't. 

719
00:44:55,480 --> 00:45:00,280
And so now I'm wondering, I mean
now if I went back and looked at

720
00:45:00,280 --> 00:45:02,840
it, I'd probably have much 
better idea of what was going 

721
00:45:02,840 --> 00:45:06,680
on. 
But did they also handle 

722
00:45:07,140 --> 00:45:11,740
cancellation and errors? 
Yep, yeah so Co routines in 

723
00:45:11,740 --> 00:45:15,020
Kotlin do handle both 
cancellation and error 

724
00:45:15,340 --> 00:45:18,260
management. 
So if you call a Co routine and 

725
00:45:18,260 --> 00:45:20,500
it throws an exception, it is an
exception based. 

726
00:45:20,500 --> 00:45:24,660
But if you throw an exception, 
then that will cancel your other

727
00:45:24,780 --> 00:45:27,220
children that are in that same 
scope. 

728
00:45:27,260 --> 00:45:30,260
And So what if you get multiple 
exceptions? 

729
00:45:33,640 --> 00:45:37,040
I think it depends on the 
implementation of selector join 

730
00:45:37,040 --> 00:45:39,160
that you're using and what 
happens there. 

731
00:45:39,800 --> 00:45:43,320
I'd have to go look at it, but 
yeah, I didn't have those 

732
00:45:43,320 --> 00:45:46,400
questions in mind when I was 
initially looking at it. 

733
00:45:46,400 --> 00:45:50,880
And now I go, oh, here are the 
things that you need to have for

734
00:45:51,360 --> 00:45:55,920
to to have a, you know, a task 
system that actually works 

735
00:45:55,920 --> 00:45:58,200
effectively and doesn't drop 
things on the floor. 

736
00:45:58,880 --> 00:46:01,920
But I have cancellation and 
reliable, you know. 

737
00:46:02,350 --> 00:46:06,350
You don't lose either 
cancellation messages or any of 

738
00:46:06,350 --> 00:46:09,870
the exceptions. 
Yeah, yeah. 

739
00:46:09,870 --> 00:46:14,080
And so with the the rust. 
Structure, concurrency. 

740
00:46:14,080 --> 00:46:17,480
One, as we mentioned, we were 
using select for most of the 

741
00:46:17,480 --> 00:46:21,120
scenarios are a basic race and 
so it was pretty 

742
00:46:21,120 --> 00:46:22,760
straightforward. 
We make our request to the 

743
00:46:22,760 --> 00:46:26,960
server, we do two of those 
concurrently and then we do a 

744
00:46:26,960 --> 00:46:30,040
select and the first one that 
comes back is the winner and we 

745
00:46:30,040 --> 00:46:32,080
return it. 
And that was all pretty 

746
00:46:32,080 --> 00:46:35,680
straightforward with the Tokyo 
Select macro. 

747
00:46:37,490 --> 00:46:40,570
But then we there's one 
scenario, I think it's scenario 

748
00:46:40,570 --> 00:46:43,210
9 where we have to do a bunch of
concurrent requests and 

749
00:46:43,210 --> 00:46:47,530
aggregate the results, and we 
use the Tokyo join for that one.

750
00:46:48,170 --> 00:46:53,530
And then the 10,000 concurrent 
request race where you're 

751
00:46:53,530 --> 00:46:55,490
raising 10,000 concurrent 
requests. 

752
00:46:56,030 --> 00:46:58,670
We weren't able to use the 
select macros we talked about 

753
00:46:58,950 --> 00:47:02,550
and what we ended up doing was 
we had to have some way to kind 

754
00:47:02,550 --> 00:47:06,790
of track the the the progress of
these 10,000 requests and then 

755
00:47:06,950 --> 00:47:09,710
and then be able to get the 
result out. 

756
00:47:10,230 --> 00:47:15,590
And so we found in Tokyo there's
the multi producer single 

757
00:47:15,590 --> 00:47:19,070
consumer channel I think is what
we use M MPSC. 

758
00:47:19,850 --> 00:47:24,610
And that allowed us to to make 
our 10,000 concurrent requests 

759
00:47:24,810 --> 00:47:28,090
when one comes back, we put that
in the channel. 

760
00:47:28,850 --> 00:47:33,050
So we we push to the transit 
side, the result to the transmit

761
00:47:33,050 --> 00:47:36,730
side. 
And then we outside of all that 

762
00:47:36,730 --> 00:47:39,970
our 10,000 concurrent requests, 
we can just wait for something 

763
00:47:39,970 --> 00:47:43,050
to come into the channel and 
when something comes into the 

764
00:47:43,050 --> 00:47:48,450
channel then then we return it. 
And I think managed through the 

765
00:47:48,450 --> 00:47:53,010
life cycle stuff. 
In in Rust, it automatically 

766
00:47:53,010 --> 00:47:57,890
then cancels the other 9999. 
Who were the the losers, 

767
00:47:57,890 --> 00:48:00,250
essentially in that case? 
And so we didn't have to 

768
00:48:00,250 --> 00:48:02,690
manually do any cancellation or 
anything, it was just all 

769
00:48:03,410 --> 00:48:07,610
automatic. 
Yeah, the contrast between 

770
00:48:08,050 --> 00:48:13,210
cooperative multitasking and 
preemptive multitasking is that 

771
00:48:13,490 --> 00:48:18,530
when you have threads or 
processes that are preemptive, 

772
00:48:19,390 --> 00:48:23,270
that means that they can be 
interrupted at any time, which 

773
00:48:23,270 --> 00:48:29,390
means that trying to do correct 
cancellation or error handling 

774
00:48:29,390 --> 00:48:35,870
or anything becomes either 
really difficult or impossible. 

775
00:48:35,870 --> 00:48:40,190
I definitely came across things 
that said, oh, just don't write 

776
00:48:40,190 --> 00:48:44,030
any code that can't be cancelled
at any time, can't be 

777
00:48:44,070 --> 00:48:45,910
terminated. 
In fact, they use the term 

778
00:48:45,910 --> 00:48:48,640
terminated because it's very 
heavy-handed. 

779
00:48:48,920 --> 00:48:53,680
And so it seems like only with 
cooperative multitasking do you 

780
00:48:53,680 --> 00:48:58,040
have the ability to, you know, 
easily correctly cancel and 

781
00:48:58,040 --> 00:49:00,200
correctly handle errors. 
Yeah. 

782
00:49:00,560 --> 00:49:04,480
So that's a that's a different 
benefit than I was thinking of 

783
00:49:04,720 --> 00:49:08,400
when you go back and and look at
these other things it's it's 

784
00:49:08,400 --> 00:49:13,200
much I I think it's why we've 
had some libraries that don't do

785
00:49:13,200 --> 00:49:16,800
that correctly is because 
traditionally and you've got 

786
00:49:17,000 --> 00:49:20,240
threads or processes you just 
kind of have to go well. 

787
00:49:20,240 --> 00:49:23,760
Either you have to be a very 
clever careful programmer and 

788
00:49:23,800 --> 00:49:30,160
probably you still won't get it 
right or or just write your code

789
00:49:30,160 --> 00:49:33,880
so carefully that it can be 
stopped at any point. 

790
00:49:34,240 --> 00:49:40,240
You you can never like take a. 
You can never have a hold a lock

791
00:49:40,780 --> 00:49:43,620
because you could be holding a 
lock and then your task is 

792
00:49:43,620 --> 00:49:46,700
dropped and then everything is 
any anybody else who's using 

793
00:49:46,700 --> 00:49:49,940
that lock is is screwed. 
So it's very. 

794
00:49:50,660 --> 00:49:54,220
Yeah, I think the the resource 
safety piece is is really 

795
00:49:54,260 --> 00:49:56,460
crucial in the world of 
structure concurrencies. 

796
00:49:56,460 --> 00:50:00,500
You have to wait, have to have a
way to safely cancel things that

797
00:50:00,500 --> 00:50:04,700
can clean up any resources that 
that that thing is holding on to

798
00:50:05,100 --> 00:50:09,460
and in I think in all the 
structure concurrency stuff 

799
00:50:09,460 --> 00:50:12,550
we've used. 
There there definitely is that 

800
00:50:12,550 --> 00:50:18,150
like cancellation, resource 
safety handling happening a lot 

801
00:50:18,150 --> 00:50:21,670
of times in our cases underneath
the covers cuz what we're what 

802
00:50:21,670 --> 00:50:24,230
we have is a connection to the 
server which needs to be cleaned

803
00:50:24,230 --> 00:50:28,670
up and so the the actual HTTP 
client library is the one that 

804
00:50:28,670 --> 00:50:32,550
is seeing that The thing is 
cancelled and then doing the 

805
00:50:32,550 --> 00:50:34,430
cleanup of closing the 
connection. 

806
00:50:35,160 --> 00:50:39,480
For us, so we didn't have to, in
the case of Easy Racer, do much 

807
00:50:39,480 --> 00:50:43,680
of that on our own. 
It was handled handled correctly

808
00:50:43,920 --> 00:50:48,720
by the HTTP client library, but 
we we validated that yeah, sure 

809
00:50:48,720 --> 00:50:51,760
enough it is doing the right 
thing on cancellation. 

810
00:50:51,760 --> 00:50:54,320
It's closing the connection. 
And I mean, the nice thing about

811
00:50:54,320 --> 00:51:00,560
cooperative concurrency is that 
you have these known suspension 

812
00:51:00,560 --> 00:51:05,500
points and so the compiler can 
look at those and go, all right,

813
00:51:05,500 --> 00:51:09,860
I know this is where I need to 
store the necessary things so 

814
00:51:09,860 --> 00:51:15,140
that the task can be suspended 
and then and and that's also why

815
00:51:15,580 --> 00:51:19,060
it can be such a small thing. 
Why you can have, you know, 

816
00:51:19,620 --> 00:51:22,380
hundreds of thousands or 
millions of tasks because each 

817
00:51:22,380 --> 00:51:27,300
of them doesn't have to store 
the entire stack frame because 

818
00:51:27,660 --> 00:51:29,580
it knows where you're 
suspending. 

819
00:51:30,030 --> 00:51:35,350
And that's true with also with 
cancellation that happens at 

820
00:51:35,350 --> 00:51:38,390
those suspension points if it's 
automated like it is in Python, 

821
00:51:38,390 --> 00:51:39,670
of course, if you do it 
yourself. 

822
00:51:39,990 --> 00:51:45,670
But in both cases, the scope of 
everything means that, like in 

823
00:51:45,670 --> 00:51:49,070
in Rust, things get dropped. 
And that's where that cleanup 

824
00:51:49,070 --> 00:51:51,510
happens for for your server 
connection. 

825
00:51:52,030 --> 00:51:55,590
Everything that's in scope gets 
dropped when you return from. 

826
00:51:56,030 --> 00:51:58,840
It. 
Yeah, so the scenario for this 

827
00:51:58,840 --> 00:52:02,280
one that we did, an Easy Eraser 
where Easy Eraser tries to 

828
00:52:02,280 --> 00:52:06,080
validate that you're doing this 
correctly, is you race 2 

829
00:52:06,080 --> 00:52:09,480
connections, but one of them 
needs to have a one second 

830
00:52:09,480 --> 00:52:12,680
timeout. 
So you open the connection, you 

831
00:52:12,680 --> 00:52:16,880
wait a second, and then it needs
to close before the other one 

832
00:52:16,880 --> 00:52:20,520
wins the race. 
The Easy Racer server won't let 

833
00:52:20,520 --> 00:52:22,720
you win the race until you've 
correctly done that. 

834
00:52:22,960 --> 00:52:26,320
That timeout, that's the rules. 
Yeah, yeah, that you set up. 

835
00:52:26,980 --> 00:52:32,380
And and so in the Rust version 
we just wrapped our request with

836
00:52:32,380 --> 00:52:36,620
a timeout which is part of Tokyo
and the timeout did the correct 

837
00:52:36,620 --> 00:52:39,580
thing It you know it knew that 
there was a task that it needed 

838
00:52:39,580 --> 00:52:44,140
to run and start and then then 
timeout cancels that task and 

839
00:52:44,140 --> 00:52:46,380
then that closed the connection 
which allowed the other 

840
00:52:46,380 --> 00:52:51,140
connection to to win the race. 
So that was all verified to work

841
00:52:51,140 --> 00:52:55,420
and pretty straightforward in in
Tokyo and the rest of that was. 

842
00:52:56,120 --> 00:52:59,680
It was nice. 
So Russ does do threading, so 

843
00:52:59,840 --> 00:53:05,480
that makes me wonder what's the 
cleanup story in that case. 

844
00:53:06,480 --> 00:53:09,880
Yeah, we didn't play with the 
the thread stuff and and Russ we

845
00:53:09,880 --> 00:53:13,200
were on Tokyo which is all green
threads fiber based. 

846
00:53:13,200 --> 00:53:16,400
And so it's all it's doing, all 
the management of actually 

847
00:53:16,400 --> 00:53:18,440
executing stuff on threads for 
you. 

848
00:53:19,070 --> 00:53:22,510
And we didn't dive into how that
works, but I do remember there 

849
00:53:22,510 --> 00:53:27,070
was a great blog post about 
Tokyo's scheduler which has some

850
00:53:27,070 --> 00:53:30,910
pretty at the time had some 
pretty significant advancements 

851
00:53:30,910 --> 00:53:35,750
for doing fiber based scheduling
onto threads and all that. 

852
00:53:36,570 --> 00:53:40,370
And doing it efficiently and 
doing alleviating things like 

853
00:53:40,370 --> 00:53:43,250
headline blocking and a lot of 
the problems that you often run 

854
00:53:43,250 --> 00:53:47,810
into with a naive simple 
scheduler that did some 

855
00:53:48,130 --> 00:53:52,970
impressive optimizations and 
automatic management around. 

856
00:53:53,460 --> 00:53:57,100
Which then inspired Zeo's in Zo 
2. 

857
00:53:57,100 --> 00:54:02,020
The Zo 2 scheduler was was I 
think pretty inspired by Tokyo's

858
00:54:02,020 --> 00:54:05,460
scheduler for how the how the 
actual scheduling of tasks work.

859
00:54:05,460 --> 00:54:07,500
So interesting. 
Yeah, I didn't know that. 

860
00:54:08,660 --> 00:54:11,660
Yeah, there was a talk I think 
it was by Adam and the Zo team 

861
00:54:11,660 --> 00:54:16,860
about the inspiration for ZO 2 
scheduler and how they learned a

862
00:54:16,860 --> 00:54:21,810
lot from the Tokyo scheduler. 
Yeah, I have written something 

863
00:54:21,810 --> 00:54:27,890
using threads but they that was 
embarrassingly parallel and it 

864
00:54:28,090 --> 00:54:33,210
just ran to completion and I I 
had no worries about cleanup or 

865
00:54:33,250 --> 00:54:35,810
errors or anything. 
So so I haven't really 

866
00:54:35,810 --> 00:54:38,450
experimented with that at this 
point, but now I'm curious it. 

867
00:54:39,330 --> 00:54:43,650
Seemed like a lot of the Tokyo 
API's mirrored the thread based 

868
00:54:43,650 --> 00:54:48,570
API's and so maybe it wouldn't 
be too hard to to. 

869
00:54:49,010 --> 00:54:51,770
Take what we did and do it on 
top of threads and see if 

870
00:54:52,130 --> 00:54:54,210
there's any difference or 
anything. 

871
00:54:54,210 --> 00:54:59,530
But yeah. 
Yeah, so we continue to learn 

872
00:54:59,530 --> 00:55:02,170
about structure, concurrency and
different approaches. 

873
00:55:02,610 --> 00:55:07,090
Definitely seems like the the 
commonality is the structure, 

874
00:55:07,090 --> 00:55:11,970
having a scope that you put 
things in, the cancellation, the

875
00:55:11,970 --> 00:55:15,370
air handling, the resource 
management, all that stuff seems

876
00:55:15,370 --> 00:55:17,770
to be pretty common. 
There are. 

877
00:55:20,350 --> 00:55:25,070
One thing that is that I do like
in the world of scholar around 

878
00:55:25,070 --> 00:55:28,590
this is that there are some 
higher level APIs for structure 

879
00:55:28,590 --> 00:55:33,230
concurrency that I haven't seen 
built in some of the other 

880
00:55:33,230 --> 00:55:35,230
languages and frameworks that 
we've worked with. 

881
00:55:35,710 --> 00:55:44,310
So for instance, if you want to 
do a join essentially but but 

882
00:55:44,310 --> 00:55:49,710
take only all the successes. 
In scalazio there's a collect 

883
00:55:49,710 --> 00:55:53,630
all successes par or something 
like that and that will just, 

884
00:55:53,630 --> 00:55:58,070
you know, you give it your list 
of essentially tasks and it will

885
00:55:58,070 --> 00:56:01,110
just give you back the list of 
all the things that successfully

886
00:56:01,110 --> 00:56:04,110
completed. 
And you can certainly do that 

887
00:56:04,110 --> 00:56:09,950
with it a join, but you have to 
do some manual stuff after the 

888
00:56:09,950 --> 00:56:12,510
fact because the join is just 
going to give you back the 

889
00:56:12,510 --> 00:56:14,990
errors and values and so then 
you have to filter out the 

890
00:56:14,990 --> 00:56:16,470
errors, and we did this one in 
the Rust. 

891
00:56:16,810 --> 00:56:20,570
One where we had to manually 
filter out the errors and it's 

892
00:56:20,610 --> 00:56:23,330
you know, it's not. 
It wasn't too hard to do, but 

893
00:56:23,610 --> 00:56:26,690
it's certainly nice to have some
of the higher level APIs on top 

894
00:56:26,690 --> 00:56:29,250
of this stuff. 
To be fair, we didn't go looking

895
00:56:29,250 --> 00:56:32,410
for crates that might do that 
and. 

896
00:56:32,570 --> 00:56:35,650
That's very possible. 
Could be a crate that would do a

897
00:56:35,690 --> 00:56:40,610
collect all successes par on top
of the Tokyo join. 

898
00:56:41,170 --> 00:56:42,770
So yeah, it definitely could 
exist. 

899
00:56:43,930 --> 00:56:45,450
But we didn't. 
We didn't. 

900
00:56:45,450 --> 00:56:47,690
We were just trying to solve 
this problem, which was fine. 

901
00:56:47,690 --> 00:56:51,930
But now I'm curious because a 
lot of times when you go, Gee, I

902
00:56:51,930 --> 00:56:55,090
wonder if this exists in Rust, 
it typically does. 

903
00:56:55,090 --> 00:56:59,410
Like there's a whole lot of 
Python libraries that if, you 

904
00:56:59,410 --> 00:57:02,090
know, if there's a library you 
like and you go, huh, wonder if 

905
00:57:02,090 --> 00:57:04,570
it exists in Rust? 
Very often it does. 

906
00:57:04,570 --> 00:57:08,450
There seems to be a lot of back 
and forth between the two 

907
00:57:08,450 --> 00:57:12,350
communities. 
Somebody, somebody even called 

908
00:57:12,350 --> 00:57:14,230
it. 
They said I know Python And Rust

909
00:57:14,230 --> 00:57:20,150
are best friends now. 
Nice, yeah. 

910
00:57:20,150 --> 00:57:22,110
Any other thoughts on structure 
concurrency? 

911
00:57:22,950 --> 00:57:24,950
There will be, but not right 
now. 

912
00:57:26,590 --> 00:57:27,910
Yeah, still. 
Figuring it out. 

913
00:57:27,910 --> 00:57:33,010
Continue exploring that and. 
The Easy Racer repo is up on my 

914
00:57:33,010 --> 00:57:36,530
GitHub toward Easy Racer, and 
with all the implementations 

915
00:57:36,530 --> 00:57:40,290
there's now different. 
Languages Colin, Scala, Rust, 

916
00:57:40,450 --> 00:57:48,090
Python, Go, Swift, and Elm. 
So yeah, that's been a fun place

917
00:57:48,090 --> 00:57:51,370
to explore this stuff. 
Yeah, that's been a good 

918
00:57:51,370 --> 00:57:54,810
learning experience. 
Cool. 

919
00:57:54,850 --> 00:57:58,370
Any last thoughts? 
No, it was a good week. 

920
00:57:58,650 --> 00:57:59,650
Yeah, good week. 
Kind of fun. 

921
00:58:00,150 --> 00:58:01,590
REST Developer Retreat. 
Yeah, it was. 

922
00:58:01,590 --> 00:58:04,070
That's great. 
All right. 

923
00:58:04,230 --> 00:58:07,230
Well, thanks for being here and 
look forward to more.

