WEBVTT

1
00:00:00.080 --> 00:00:03.600
<v Speaker 1>I want you to I want you to picture a garage,

2
00:00:04.000 --> 00:00:06.320
<v Speaker 1>like a really high end modern.

3
00:00:05.960 --> 00:00:07.799
<v Speaker 2>Garage, Okay, I'm picturing it.

4
00:00:07.719 --> 00:00:11.000
<v Speaker 1>And on the left side, you've got the absolute cutting

5
00:00:11.119 --> 00:00:16.079
<v Speaker 1>edge of automotive engineering. Let's say a brand new, gleaming

6
00:00:16.120 --> 00:00:17.920
<v Speaker 1>Tesla or maybe Elucid Air.

7
00:00:17.960 --> 00:00:19.679
<v Speaker 2>Right, something really sleek, exactly.

8
00:00:19.679 --> 00:00:22.559
<v Speaker 1>It's got the self driving AI, the massive touch screens,

9
00:00:22.600 --> 00:00:25.359
<v Speaker 1>the over the air updates. It is the future.

10
00:00:25.519 --> 00:00:28.559
<v Speaker 2>It's sexy. It's what everyone wants to drive right now, right, and.

11
00:00:28.480 --> 00:00:31.879
<v Speaker 1>That represents modern coding languages, your Python, your rust go

12
00:00:32.159 --> 00:00:34.640
<v Speaker 1>things like that. Yeah, But then I want you to

13
00:00:34.640 --> 00:00:36.320
<v Speaker 1>look over to the right side of this garage. O.

14
00:00:37.600 --> 00:00:41.240
<v Speaker 1>Sitting on cinder blocks covered in maybe forty years of dust,

15
00:00:41.840 --> 00:00:44.640
<v Speaker 1>is a rusted out Model T Ford. It looks like

16
00:00:44.640 --> 00:00:47.159
<v Speaker 1>it belongs in a museum, sounds out a place. It does.

17
00:00:47.600 --> 00:00:50.039
<v Speaker 1>But here's the twist. You pop the hood of that

18
00:00:50.079 --> 00:00:53.280
<v Speaker 1>shiny k need Tesla and the engine inside it. It's

19
00:00:53.320 --> 00:00:54.359
<v Speaker 1>the Model T engine.

20
00:00:54.399 --> 00:00:57.679
<v Speaker 2>That is a terrifying image, honestly, but it's painfully accurate.

21
00:00:57.920 --> 00:01:00.359
<v Speaker 1>It really is. Yeah, Because we're ta talking go to

22
00:01:00.439 --> 00:01:06.400
<v Speaker 1>technology that feels ancient, almost prehistoric in computer years, yet

23
00:01:07.439 --> 00:01:09.799
<v Speaker 1>it is currently running the back end of your bank.

24
00:01:10.159 --> 00:01:12.480
<v Speaker 1>It's the logistics system delivering your packages.

25
00:01:12.640 --> 00:01:16.439
<v Speaker 2>And crucially, it is installed on every single Windows computer in.

26
00:01:16.400 --> 00:01:18.640
<v Speaker 1>Existence right now, Yes, every single one.

27
00:01:18.719 --> 00:01:21.439
<v Speaker 2>We are talking about batch scripting. I've heard it called

28
00:01:21.480 --> 00:01:23.120
<v Speaker 2>the cockroach of the IT world.

29
00:01:23.280 --> 00:01:26.840
<v Speaker 1>Cockroach feels a little harsh, but I kind of get it.

30
00:01:26.840 --> 00:01:27.840
<v Speaker 1>It just won't die.

31
00:01:28.000 --> 00:01:30.959
<v Speaker 2>It won't, and honestly it shouldn't. It's way too integrated

32
00:01:31.000 --> 00:01:33.599
<v Speaker 2>into the bedrock of our digital infrastructure.

33
00:01:34.200 --> 00:01:36.959
<v Speaker 1>So today we're doing a deep dive into a really

34
00:01:37.000 --> 00:01:40.319
<v Speaker 1>fascinating source. It's called the Book of Batch Scripting From

35
00:01:40.359 --> 00:01:44.239
<v Speaker 1>Fundamentals to Advance Automation by Jack McLarney. It's great read,

36
00:01:44.400 --> 00:01:46.239
<v Speaker 1>it is, and the mission for this deep dive is

37
00:01:46.239 --> 00:01:48.760
<v Speaker 1>pretty clear. We want to figure out why this nineteen

38
00:01:48.760 --> 00:01:52.159
<v Speaker 1>eighties technology, which is rooted in MS doos, is still

39
00:01:52.159 --> 00:01:52.719
<v Speaker 1>so vital.

40
00:01:52.879 --> 00:01:54.879
<v Speaker 2>But we also need to warn you. McLarney makes it

41
00:01:54.959 --> 00:01:57.159
<v Speaker 2>very clear in the book that batch is a minefield.

42
00:01:57.319 --> 00:02:01.280
<v Speaker 2>Oh absolutely, it's powerful, but it is just full of traps.

43
00:02:01.640 --> 00:02:04.040
<v Speaker 2>He actually coins a term for this, which I absolutely love.

44
00:02:04.079 --> 00:02:07.120
<v Speaker 2>He calls them bat beats. Bat beats, yeah, like caveats,

45
00:02:07.120 --> 00:02:10.599
<v Speaker 2>but specific to batch. A bat beat is basically a

46
00:02:10.719 --> 00:02:13.240
<v Speaker 2>quirk or a trap in the language that just doesn't

47
00:02:13.280 --> 00:02:14.879
<v Speaker 2>exist in modern coding.

48
00:02:14.719 --> 00:02:17.520
<v Speaker 1>Right because modern languages have safety rails exactly.

49
00:02:17.879 --> 00:02:22.120
<v Speaker 2>But in Batch, the interpreter is incredibly literal or sometimes

50
00:02:22.159 --> 00:02:25.360
<v Speaker 2>just plain weird in a way that can completely destroy

51
00:02:25.439 --> 00:02:27.879
<v Speaker 2>your entire workflow if you aren't careful.

52
00:02:28.159 --> 00:02:30.479
<v Speaker 1>And we have a list of the nastiest ones to

53
00:02:30.520 --> 00:02:32.960
<v Speaker 1>get through today, we're going to look at the space trap,

54
00:02:33.360 --> 00:02:36.080
<v Speaker 1>the Octal Horror Story, which is my absolute.

55
00:02:35.719 --> 00:02:37.719
<v Speaker 2>Favorite, by the way, oh it's a classic.

56
00:02:37.400 --> 00:02:40.759
<v Speaker 1>And the inception logic of nested variables. But let's start

57
00:02:40.759 --> 00:02:43.759
<v Speaker 1>with the basics what the book calls the wild West

58
00:02:43.759 --> 00:02:44.560
<v Speaker 1>of variables.

59
00:02:44.759 --> 00:02:46.800
<v Speaker 2>The wild West is definitely the right way to put it.

60
00:02:46.840 --> 00:02:48.680
<v Speaker 2>There is no sheriff in this town at all.

61
00:02:48.879 --> 00:02:51.159
<v Speaker 1>So in most languages, if I want to write code,

62
00:02:51.639 --> 00:02:54.319
<v Speaker 1>I have to be specific. I tell the computer, Hey,

63
00:02:54.439 --> 00:02:57.120
<v Speaker 1>this variable is a number, or this variable is a

64
00:02:57.120 --> 00:02:58.800
<v Speaker 1>string of text. There were rules.

65
00:02:59.000 --> 00:03:01.159
<v Speaker 2>Batch doesn't care about any of that, not at all.

66
00:03:01.240 --> 00:03:06.960
<v Speaker 2>In Batch, everything is created x nihilo out of nothing. Intrinsically,

67
00:03:07.000 --> 00:03:09.639
<v Speaker 2>to the Batch interpreter, everything is just a string of bytes.

68
00:03:10.000 --> 00:03:12.000
<v Speaker 2>It doesn't know the difference between the number five and

69
00:03:12.039 --> 00:03:12.639
<v Speaker 2>the word five.

70
00:03:12.719 --> 00:03:14.919
<v Speaker 1>Until you force it to do math, which leads to

71
00:03:14.919 --> 00:03:17.319
<v Speaker 1>what I think is the most infuriating yet kind of

72
00:03:17.400 --> 00:03:20.960
<v Speaker 1>hilarious rookie mistake in the book The Space Trap.

73
00:03:21.039 --> 00:03:26.080
<v Speaker 2>Oh Man, the Space Trap. This is a classic batv.

74
00:03:26.400 --> 00:03:31.759
<v Speaker 2>I have seen grown engineers, people with master's degrees, completely

75
00:03:31.759 --> 00:03:32.919
<v Speaker 2>pull their hair out over this.

76
00:03:33.280 --> 00:03:35.000
<v Speaker 1>So walk us through this. Let's say I want to

77
00:03:35.039 --> 00:03:38.360
<v Speaker 1>set a variable named x to the value hello.

78
00:03:38.560 --> 00:03:38.919
<v Speaker 2>Okay.

79
00:03:39.159 --> 00:03:41.360
<v Speaker 1>In a normal language, being a tidy person who likes

80
00:03:41.360 --> 00:03:44.479
<v Speaker 1>readable code, I might type set x, then a space,

81
00:03:44.560 --> 00:03:47.719
<v Speaker 1>an equal sign, another space, and then hello. I put

82
00:03:47.719 --> 00:03:49.719
<v Speaker 1>spaces around the equal sign because it looks nice.

83
00:03:49.719 --> 00:03:52.479
<v Speaker 2>It's clean, right, And in Python our JavaScript, that's fine.

84
00:03:52.520 --> 00:03:54.639
<v Speaker 2>The computer ignores the white space. That knows what you mean.

85
00:03:54.719 --> 00:03:58.400
<v Speaker 2>But the batch interpreter it is aggressively literal.

86
00:03:58.599 --> 00:03:59.520
<v Speaker 1>Aggressively literal.

87
00:03:59.639 --> 00:04:02.599
<v Speaker 2>Yes, if you type set x space equal space hello,

88
00:04:02.639 --> 00:04:05.240
<v Speaker 2>the interpreter doesn't say, oh they want x to equal hello,

89
00:04:05.520 --> 00:04:08.120
<v Speaker 2>does it do? It reads exactly what you typed. It

90
00:04:08.199 --> 00:04:11.000
<v Speaker 2>sees the space before the equal sign and includes it

91
00:04:11.039 --> 00:04:13.680
<v Speaker 2>in the name. So now you have a variable named

92
00:04:13.919 --> 00:04:14.680
<v Speaker 2>x space.

93
00:04:14.479 --> 00:04:16.839
<v Speaker 1>Wait xspace literally.

94
00:04:16.680 --> 00:04:19.680
<v Speaker 2>Literally, and then it sees the space after the equal

95
00:04:19.759 --> 00:04:21.920
<v Speaker 2>sign and includes that in the value. So the value

96
00:04:21.959 --> 00:04:23.639
<v Speaker 2>isn't Hello, it's space Hello.

97
00:04:23.839 --> 00:04:25.600
<v Speaker 1>So I haven't said X to hello at all. I've

98
00:04:25.639 --> 00:04:27.839
<v Speaker 1>set x space to space hello exactly.

99
00:04:27.879 --> 00:04:30.560
<v Speaker 2>And here is the kicker. If you try to use

100
00:04:30.600 --> 00:04:33.560
<v Speaker 2>that variable later by calling just x, which is what

101
00:04:33.639 --> 00:04:36.439
<v Speaker 2>you think you named it, it won't work because X

102
00:04:36.480 --> 00:04:38.480
<v Speaker 2>doesn't exist, only X space exists.

103
00:04:38.680 --> 00:04:41.360
<v Speaker 1>That is maddening. And since you can't see a space

104
00:04:41.439 --> 00:04:43.680
<v Speaker 1>character with the naked eye, you'd be steering at your

105
00:04:43.680 --> 00:04:45.439
<v Speaker 1>code for hours wondering why it's broken.

106
00:04:45.519 --> 00:04:48.759
<v Speaker 2>Precisely, you're looking at the screen shouting, I defined X.

107
00:04:48.800 --> 00:04:52.040
<v Speaker 2>It's right there. But you didn't define X. You defined

108
00:04:52.199 --> 00:04:52.639
<v Speaker 2>x space.

109
00:04:53.199 --> 00:04:53.519
<v Speaker 1>Wow.

110
00:04:53.560 --> 00:04:56.759
<v Speaker 2>That's why their author mcclerney practically begs you to stop

111
00:04:56.879 --> 00:05:00.000
<v Speaker 2>using basic notepad. You need an editor like Notepad plas

112
00:05:00.160 --> 00:05:02.040
<v Speaker 2>plus where you can turn on show space and tab.

113
00:05:02.360 --> 00:05:04.879
<v Speaker 2>You have to see the invisible characters or badge will

114
00:05:04.879 --> 00:05:05.399
<v Speaker 2>destroy you.

115
00:05:05.600 --> 00:05:08.879
<v Speaker 1>Okay, So once we've successfully set a variable, you know,

116
00:05:08.920 --> 00:05:12.120
<v Speaker 1>without the space as, we run into another issue, usefulness.

117
00:05:12.639 --> 00:05:15.279
<v Speaker 1>Usually when I set a variable and a command prompt,

118
00:05:15.399 --> 00:05:17.319
<v Speaker 1>it vanishes the second I close the window.

119
00:05:17.439 --> 00:05:20.079
<v Speaker 2>That's the ephemeral nature of the standard set command. It's

120
00:05:20.079 --> 00:05:22.240
<v Speaker 2>only a live for that specific session. It's like short

121
00:05:22.319 --> 00:05:25.680
<v Speaker 2>term memory. Yeah, but mcclarney highlights a tool that I

122
00:05:25.720 --> 00:05:30.600
<v Speaker 2>think is vastly underused, sex the extreme set Essentially, yes,

123
00:05:30.839 --> 00:05:33.759
<v Speaker 2>SETX allows you to save a variable into the system

124
00:05:33.839 --> 00:05:36.480
<v Speaker 2>environment permanently. It actually survives a reboot.

125
00:05:36.600 --> 00:05:39.000
<v Speaker 1>So why does that matter? Give me a real world

126
00:05:39.040 --> 00:05:40.480
<v Speaker 1>scenario where i'd use that.

127
00:05:40.800 --> 00:05:43.439
<v Speaker 2>Imagine you're a developer. You're building an app that needs

128
00:05:43.480 --> 00:05:45.920
<v Speaker 2>to know where a database is located. You don't want

129
00:05:45.959 --> 00:05:48.879
<v Speaker 2>to type that really long filepath every single time you

130
00:05:48.920 --> 00:05:50.319
<v Speaker 2>open a terminal to test your.

131
00:05:50.199 --> 00:05:52.079
<v Speaker 1>Code, right, That would be pedious.

132
00:05:52.160 --> 00:05:54.800
<v Speaker 2>So you can use set x to burn that location

133
00:05:54.879 --> 00:05:56.800
<v Speaker 2>into your machine's environment.

134
00:05:56.360 --> 00:05:58.639
<v Speaker 1>So it becomes part of the furniture exactly.

135
00:05:58.720 --> 00:06:01.279
<v Speaker 2>Every time you open your tools, the variable is just there.

136
00:06:01.319 --> 00:06:03.639
<v Speaker 2>You don't have to retype it. It's a huge time

137
00:06:03.720 --> 00:06:07.240
<v Speaker 2>saver for setting up development environments. But again, you have

138
00:06:07.319 --> 00:06:09.319
<v Speaker 2>to be careful because if you set ux a typo,

139
00:06:09.480 --> 00:06:11.519
<v Speaker 2>that typo is now permanent until you go in and

140
00:06:11.560 --> 00:06:12.199
<v Speaker 2>fix it.

141
00:06:12.319 --> 00:06:16.040
<v Speaker 1>High stakes, high reward. Okay, so we've got our variables,

142
00:06:16.079 --> 00:06:18.800
<v Speaker 1>we're avoiding spaces. Now we need to talk about the

143
00:06:18.800 --> 00:06:21.040
<v Speaker 1>segment that actually made me laugh out loud while reading

144
00:06:21.439 --> 00:06:22.720
<v Speaker 1>the octal horror story.

145
00:06:22.879 --> 00:06:26.040
<v Speaker 2>This is the ultimate batbate. It's a story that perfectly

146
00:06:26.079 --> 00:06:28.279
<v Speaker 2>illustrates how fragile batch logic can be.

147
00:06:28.680 --> 00:06:31.399
<v Speaker 1>So the setup is this. The author has a script

148
00:06:31.399 --> 00:06:34.519
<v Speaker 1>that's been running perfectly for six months. It's a date calculator.

149
00:06:34.800 --> 00:06:36.839
<v Speaker 1>Its job is to figure out the previous.

150
00:06:36.519 --> 00:06:39.600
<v Speaker 2>Day, right, simple logic. If today is the fifth, yesterday

151
00:06:39.639 --> 00:06:41.439
<v Speaker 2>was the fourth. If today's the first, we need to

152
00:06:41.439 --> 00:06:42.680
<v Speaker 2>go back to the previous month.

153
00:06:42.759 --> 00:06:46.399
<v Speaker 1>And this works beautifully in January, February, March, all the

154
00:06:46.439 --> 00:06:50.199
<v Speaker 1>way through July. But then August first rolls around the

155
00:06:50.279 --> 00:06:53.040
<v Speaker 1>day of doom. The script wakes up, tries to calculate

156
00:06:53.040 --> 00:06:55.480
<v Speaker 1>the previous month. It takes the current month, which is

157
00:06:55.759 --> 00:06:59.199
<v Speaker 1>August represented as zero eight, and tries to subtract one

158
00:06:59.240 --> 00:07:03.600
<v Speaker 1>to get July or zero seven. Simple math eight minus one.

159
00:07:03.600 --> 00:07:05.560
<v Speaker 2>Equal seven, But the script crashes.

160
00:07:05.600 --> 00:07:09.439
<v Speaker 1>It just implodes why why on Earth would eight minus

161
00:07:09.480 --> 00:07:11.360
<v Speaker 1>one crash a computer program?

162
00:07:11.439 --> 00:07:13.680
<v Speaker 2>It comes down to a legacy holdover from the dawn

163
00:07:13.720 --> 00:07:18.120
<v Speaker 2>of computing, specifically from the C programming language in Unix.

164
00:07:18.680 --> 00:07:21.439
<v Speaker 2>In Batch, a leading zero on a number is a signal.

165
00:07:21.639 --> 00:07:25.000
<v Speaker 2>It tells the interpreter we are not using the decimal system.

166
00:07:24.759 --> 00:07:27.079
<v Speaker 1>The base ten system that humans use.

167
00:07:27.240 --> 00:07:29.920
<v Speaker 2>Right, it says we are using octal base eight.

168
00:07:30.079 --> 00:07:33.319
<v Speaker 1>Okay, let's unpack octal. Most listeners probably haven't thought about

169
00:07:33.360 --> 00:07:35.199
<v Speaker 1>base eight since high school computer science.

170
00:07:35.240 --> 00:07:37.959
<v Speaker 2>If ever, so, in our normal base ten system, we

171
00:07:38.000 --> 00:07:40.000
<v Speaker 2>have digit zero through nine. When we get to ten,

172
00:07:40.079 --> 00:07:43.000
<v Speaker 2>we roll over. In octal, you only have digit zero

173
00:07:43.079 --> 00:07:45.519
<v Speaker 2>through seven. That's it. There is no eight, there is

174
00:07:45.560 --> 00:07:47.680
<v Speaker 2>no eight, and there's no nine. In octaal you count

175
00:07:47.759 --> 00:07:50.639
<v Speaker 2>zero one, two, three, four, five, six, seven, and the

176
00:07:50.639 --> 00:07:51.560
<v Speaker 2>next number is ten.

177
00:07:51.720 --> 00:07:53.600
<v Speaker 1>So when the script saw zero eight, it.

178
00:07:53.600 --> 00:07:55.920
<v Speaker 2>Saw the zero and switched to octal mode. Then it

179
00:07:55.959 --> 00:07:58.519
<v Speaker 2>saw the eight and panicked. It's like trying to divide

180
00:07:58.519 --> 00:08:01.759
<v Speaker 2>by zero. To the back interpreter, zero eight is an

181
00:08:01.759 --> 00:08:05.519
<v Speaker 2>impossible number. It's a hallucination. It just doesn't exist.

182
00:08:05.639 --> 00:08:09.160
<v Speaker 1>That is wild. So literally, because the date was August

183
00:08:09.240 --> 00:08:11.720
<v Speaker 1>first on the calendar, the server process died.

184
00:08:11.959 --> 00:08:15.680
<v Speaker 2>Yes, And the author describes his reaction when he finally

185
00:08:15.680 --> 00:08:18.279
<v Speaker 2>figured this out. He's looking at the logs, he sees

186
00:08:18.319 --> 00:08:20.800
<v Speaker 2>the zero eight and he realizes it's the octal bug.

187
00:08:20.879 --> 00:08:23.120
<v Speaker 2>He just screams oscy tale at the sky.

188
00:08:23.399 --> 00:08:26.120
<v Speaker 1>He compares it to Captain Kirk screaming con in star

189
00:08:26.160 --> 00:08:26.639
<v Speaker 1>Trek two.

190
00:08:26.759 --> 00:08:29.680
<v Speaker 2>I can picture it perfectly, just sheer nerd rage.

191
00:08:29.920 --> 00:08:31.959
<v Speaker 1>So how do you fix that? Do you just cancel August?

192
00:08:32.159 --> 00:08:34.720
<v Speaker 2>You have to scrub the data. You use substring tricks

193
00:08:34.720 --> 00:08:36.320
<v Speaker 2>to look at the date. You say, if the first

194
00:08:36.399 --> 00:08:38.679
<v Speaker 2>character is a zero, delete it. You have to turn

195
00:08:38.840 --> 00:08:40.279
<v Speaker 2>zero eight into just eight.

196
00:08:40.600 --> 00:08:42.279
<v Speaker 1>And once it's eight without the.

197
00:08:42.320 --> 00:08:45.360
<v Speaker 2>Zero, Batch treats it as a decimal and everything is fine.

198
00:08:45.440 --> 00:08:48.600
<v Speaker 1>It really reinforces the idea that Batch is just a

199
00:08:48.720 --> 00:08:49.960
<v Speaker 1>language of workarounds.

200
00:08:50.279 --> 00:08:53.399
<v Speaker 2>Absolutely, it's ductate all the way down. And that leads

201
00:08:53.480 --> 00:08:57.279
<v Speaker 2>perfectly into the next topic, faking functionality. Because if you're

202
00:08:57.279 --> 00:09:00.559
<v Speaker 2>coming from Python or Java, you expect certain things. You

203
00:09:00.639 --> 00:09:01.159
<v Speaker 2>expect to.

204
00:09:01.120 --> 00:09:04.200
<v Speaker 1>Have boollions, true or false variables.

205
00:09:03.799 --> 00:09:08.240
<v Speaker 2>Right, and you expect to have floating point numbers, decimals.

206
00:09:07.840 --> 00:09:11.200
<v Speaker 1>And Batch has neither none, zero.

207
00:09:11.399 --> 00:09:14.080
<v Speaker 2>So how do you check if something is true or false?

208
00:09:14.320 --> 00:09:18.519
<v Speaker 1>You have to diyat. The book shows this clever workaround.

209
00:09:19.159 --> 00:09:22.559
<v Speaker 1>Instead of setting a variable to the abstract concept of true,

210
00:09:22.919 --> 00:09:26.039
<v Speaker 1>you set the variable to the string true equals equals true.

211
00:09:26.080 --> 00:09:29.600
<v Speaker 2>Wait, you set the variable to an actual equation exactly.

212
00:09:29.159 --> 00:09:31.600
<v Speaker 1>So later when you use an if command, you're basically

213
00:09:31.679 --> 00:09:34.639
<v Speaker 1>pasting that equation into the command, the interpreter checks does

214
00:09:34.639 --> 00:09:37.240
<v Speaker 1>the string true equal the string truth? Yes, so the

215
00:09:37.320 --> 00:09:39.559
<v Speaker 1>condition passes. It's crude, but it works.

216
00:09:39.720 --> 00:09:42.039
<v Speaker 2>That feels like hot wiring a car to get it started.

217
00:09:42.200 --> 00:09:44.639
<v Speaker 1>That is Batch in a nutshell, right, And it gets

218
00:09:44.679 --> 00:09:48.000
<v Speaker 1>even messier with math. Say you want to calculate sales tax.

219
00:09:48.240 --> 00:09:50.720
<v Speaker 1>You need decimals. You need to multiply by one point

220
00:09:50.759 --> 00:09:53.960
<v Speaker 1>oh seven. Batch can't do decimals. It truncates everything to

221
00:09:54.000 --> 00:09:54.679
<v Speaker 1>a whole number.

222
00:09:54.799 --> 00:09:56.799
<v Speaker 2>So how do you do it? The book mentions a

223
00:09:56.879 --> 00:10:01.200
<v Speaker 2>spade shovel analogy. Right. Mcclarney says, doing floating point math

224
00:10:01.240 --> 00:10:04.120
<v Speaker 2>in Batch is like digging a foundation with a spade shovel.

225
00:10:04.600 --> 00:10:06.360
<v Speaker 2>You can do it, but do you really want to?

226
00:10:06.759 --> 00:10:10.440
<v Speaker 2>The trick is what he calls digital anarchy. Digital anarchy,

227
00:10:10.559 --> 00:10:13.399
<v Speaker 2>You take your number, say one point ninety nine, You

228
00:10:13.440 --> 00:10:15.440
<v Speaker 2>treat it as a string of text. You remove the dot.

229
00:10:15.559 --> 00:10:16.799
<v Speaker 2>Now you have one ninety nine.

230
00:10:16.840 --> 00:10:19.600
<v Speaker 1>Okay, so now it's an integer. Batch can handle that, right.

231
00:10:19.639 --> 00:10:21.399
<v Speaker 2>You do your math on one ninety nine. Let's say

232
00:10:21.399 --> 00:10:24.120
<v Speaker 2>you double it to three ninety eight. Then you have

233
00:10:24.159 --> 00:10:27.679
<v Speaker 2>to use substring logic to forcefully paste the decimal point

234
00:10:27.840 --> 00:10:31.000
<v Speaker 2>back in before the last two digits. So you manually

235
00:10:31.039 --> 00:10:33.559
<v Speaker 2>turn three ninety eight back into three point ninety eight.

236
00:10:33.679 --> 00:10:35.639
<v Speaker 1>You are manually managing the decimal point.

237
00:10:35.759 --> 00:10:38.159
<v Speaker 2>You are the floating point processor. You are doing the

238
00:10:38.240 --> 00:10:39.799
<v Speaker 2>job the CPU usually does for you.

239
00:10:40.000 --> 00:10:42.720
<v Speaker 1>That is dedication. But I guess if it's the only

240
00:10:42.799 --> 00:10:44.519
<v Speaker 1>tool installed on the server, you do what you have

241
00:10:44.600 --> 00:10:44.840
<v Speaker 1>to do.

242
00:10:45.080 --> 00:10:47.000
<v Speaker 2>And that brings us to the feature that sounds the

243
00:10:47.000 --> 00:10:50.200
<v Speaker 2>most intimidating but is actually the secret weapon of Batch

244
00:10:50.279 --> 00:10:51.000
<v Speaker 2>power users.

245
00:10:51.200 --> 00:10:54.720
<v Speaker 1>Delayed expansion set local enabled delete expansion. Sounds like a

246
00:10:54.799 --> 00:10:55.799
<v Speaker 1>cheat code.

247
00:10:55.559 --> 00:10:58.440
<v Speaker 2>It basically is. To understand why you need it, you

248
00:10:58.519 --> 00:11:02.840
<v Speaker 2>have to understand how Batch reads code. Normally, Batch reads

249
00:11:02.879 --> 00:11:05.159
<v Speaker 2>a full line of code or a block of code

250
00:11:05.200 --> 00:11:07.759
<v Speaker 2>inside parenthesis and parses it all at once.

251
00:11:08.480 --> 00:11:10.240
<v Speaker 1>Explain that parsing process a bit.

252
00:11:10.360 --> 00:11:12.440
<v Speaker 2>Think of it like ordering at a restaurant. In a

253
00:11:12.480 --> 00:11:15.240
<v Speaker 2>normal language, you order appetizers, you eat them, then you

254
00:11:15.360 --> 00:11:19.000
<v Speaker 2>order the main course. In Batch without delayed expansion, you

255
00:11:19.080 --> 00:11:22.440
<v Speaker 2>have to order everything appetizers, main dessert the moment you

256
00:11:22.480 --> 00:11:22.960
<v Speaker 2>sit down.

257
00:11:23.080 --> 00:11:24.879
<v Speaker 1>So if I change my mind halfway through the meal,

258
00:11:24.960 --> 00:11:25.320
<v Speaker 1>too bad.

259
00:11:25.799 --> 00:11:28.559
<v Speaker 2>The order is already in. In coding terms, if you

260
00:11:28.679 --> 00:11:30.960
<v Speaker 2>change a variable inside a loop and then try to

261
00:11:31.000 --> 00:11:34.080
<v Speaker 2>read it inside that same loop. The interpreter won't see

262
00:11:34.080 --> 00:11:37.399
<v Speaker 2>the change. It already decided what that variable was before

263
00:11:37.480 --> 00:11:38.279
<v Speaker 2>the loop started.

264
00:11:38.399 --> 00:11:40.080
<v Speaker 1>That seems like a massive design flaw.

265
00:11:40.200 --> 00:11:42.240
<v Speaker 2>It's just how it's built in the eighties. But enabled

266
00:11:42.279 --> 00:11:45.559
<v Speaker 2>delayed expansion fixes it. It allows you to use exclamation

267
00:11:45.639 --> 00:11:50.759
<v Speaker 2>marks instead of percent signs, like exclamation point variable exclamation point.

268
00:11:51.240 --> 00:11:52.840
<v Speaker 2>This forces the interpreter to.

269
00:11:52.840 --> 00:11:53.720
<v Speaker 1>Wait, wait for what.

270
00:11:54.080 --> 00:11:57.120
<v Speaker 2>It tells the interpreter, don't check this variable when you

271
00:11:57.159 --> 00:12:00.440
<v Speaker 2>take the order, check it when you actually serve the dish.

272
00:12:00.759 --> 00:12:03.799
<v Speaker 2>It forces the variable to be evaluated at the exact

273
00:12:03.879 --> 00:12:04.879
<v Speaker 2>moment of execution.

274
00:12:05.279 --> 00:12:07.519
<v Speaker 1>Hence delayed expansion precisely.

275
00:12:07.759 --> 00:12:10.360
<v Speaker 2>And this unlocks something really cool that the author compares

276
00:12:10.399 --> 00:12:13.000
<v Speaker 2>to the movie Inception nested.

277
00:12:12.639 --> 00:12:14.799
<v Speaker 1>Variables, variables inside variable.

278
00:12:14.919 --> 00:12:18.919
<v Speaker 2>Yes, with delayed expansion, you can do something like exclamation

279
00:12:19.080 --> 00:12:21.879
<v Speaker 2>food percent city percent exclamation.

280
00:12:21.519 --> 00:12:24.159
<v Speaker 1>Okay, let's unpack that. That looks like a typo salad.

281
00:12:24.279 --> 00:12:26.879
<v Speaker 2>It does, but look at the order of operations. The

282
00:12:26.960 --> 00:12:30.320
<v Speaker 2>interpreter looks at the percent city percent first. Let's say

283
00:12:30.320 --> 00:12:34.159
<v Speaker 2>the city variable is Nashville. It resolves that part immediately. Now,

284
00:12:34.200 --> 00:12:39.320
<v Speaker 2>the overall variable name becomes exclamation food Nashville exclamation ah.

285
00:12:39.360 --> 00:12:41.279
<v Speaker 1>I see. So it construct the name of the variable

286
00:12:41.279 --> 00:12:42.559
<v Speaker 1>it wants to find exactly.

287
00:12:42.720 --> 00:12:45.320
<v Speaker 2>Then it looks up the value of food Nashville, which

288
00:12:45.399 --> 00:12:46.360
<v Speaker 2>might be hot chicken.

289
00:12:46.559 --> 00:12:50.240
<v Speaker 1>So you can dynamically change which variable you are looking

290
00:12:50.279 --> 00:12:53.440
<v Speaker 1>at based on the value of another variable exactly.

291
00:12:53.759 --> 00:12:56.799
<v Speaker 2>It allows for dynamic coding like arrays and lookups that

292
00:12:56.879 --> 00:13:00.080
<v Speaker 2>is actually really hard to do in some compiled languages.

293
00:13:00.360 --> 00:13:04.960
<v Speaker 2>It turns this clunky old scripting language into something surprisingly flexible.

294
00:13:05.080 --> 00:13:07.559
<v Speaker 1>I love that. It's like finding a secret compartment in

295
00:13:07.559 --> 00:13:08.960
<v Speaker 1>that rusted out model.

296
00:13:08.679 --> 00:13:11.399
<v Speaker 2>T a secret compartment that holds a supercomputer.

297
00:13:12.000 --> 00:13:14.919
<v Speaker 1>So we've covered the logic and the variables. Now we

298
00:13:15.000 --> 00:13:19.399
<v Speaker 1>need to talk about the heavy lifting moving files, because

299
00:13:19.399 --> 00:13:21.120
<v Speaker 1>at the end of the day, that's what most people

300
00:13:21.240 --> 00:13:25.279
<v Speaker 1>use Batch for backups, organizing folders, moving data.

301
00:13:25.320 --> 00:13:27.360
<v Speaker 2>And there is a clear hierarchy here. It's like an

302
00:13:27.360 --> 00:13:30.320
<v Speaker 2>evolutionary chart. At the bottom you have the copy command,

303
00:13:30.360 --> 00:13:33.440
<v Speaker 2>the primitive tool. The expert advice here is simple, do

304
00:13:33.600 --> 00:13:36.360
<v Speaker 2>not use copy for actual files. It's too basic. It

305
00:13:36.399 --> 00:13:38.919
<v Speaker 2>stops at the first sign of trouble. Its only real

306
00:13:39.000 --> 00:13:42.679
<v Speaker 2>use nowadays is concatenation, merging, text files together or creating

307
00:13:42.679 --> 00:13:43.679
<v Speaker 2>empty files.

308
00:13:43.440 --> 00:13:46.200
<v Speaker 1>Using the null device, So we graduate to s copy.

309
00:13:46.559 --> 00:13:49.679
<v Speaker 2>SKP is the workhorse. It's been around forever. It's great

310
00:13:49.720 --> 00:13:53.240
<v Speaker 2>for single files, and the book highlights two crucial flags

311
00:13:53.320 --> 00:13:56.080
<v Speaker 2>or options you need to know, slash y and slash F.

312
00:13:56.519 --> 00:14:00.360
<v Speaker 1>Slash y suppresses the conformation pumped right. Are you sure

313
00:14:00.399 --> 00:14:01.799
<v Speaker 1>you want to overwrite prompt yes.

314
00:14:02.559 --> 00:14:05.120
<v Speaker 2>If you are automating a backup that runs at three

315
00:14:05.159 --> 00:14:07.679
<v Speaker 2>in the morning, you cannot have the script pause to

316
00:14:07.720 --> 00:14:10.080
<v Speaker 2>ask a question. No one is there to answer it.

317
00:14:10.320 --> 00:14:12.840
<v Speaker 2>The script will just hang there forever. Slash y just

318
00:14:12.879 --> 00:14:16.279
<v Speaker 2>says yes to everything, and slash F full paths. It

319
00:14:16.360 --> 00:14:18.679
<v Speaker 2>forces the LUG to show you exactly where the file

320
00:14:18.720 --> 00:14:21.000
<v Speaker 2>came from and exactly where it went. Without it, your

321
00:14:21.000 --> 00:14:22.720
<v Speaker 2>flying blind if something goes wrong.

322
00:14:22.879 --> 00:14:28.080
<v Speaker 1>But then we reach the final form the robust copy robocopy.

323
00:14:28.159 --> 00:14:31.960
<v Speaker 2>Robocopy is an absolute beast. It's designed for serious automation.

324
00:14:32.159 --> 00:14:34.879
<v Speaker 2>It can mirror entire drives, it can resume file transfers

325
00:14:34.879 --> 00:14:37.600
<v Speaker 2>if the network cuts out. It's incredibly resilient.

326
00:14:37.240 --> 00:14:38.559
<v Speaker 1>And the logging is intense.

327
00:14:38.720 --> 00:14:43.519
<v Speaker 2>Oh it's beautiful. Header's speed statistics separate counts for skip files.

328
00:14:43.519 --> 00:14:46.879
<v Speaker 2>Mismatched files. But there is a batfeat here too. The

329
00:14:46.919 --> 00:14:47.639
<v Speaker 2>return codes.

330
00:14:47.759 --> 00:14:50.279
<v Speaker 1>We talked about this before the show. In SAT copy

331
00:14:50.320 --> 00:14:53.000
<v Speaker 1>a zero means success. Everything is good right.

332
00:14:53.399 --> 00:14:56.840
<v Speaker 2>In almost all of computing, zero means no error. But

333
00:14:56.960 --> 00:14:59.080
<v Speaker 2>robocopy it uses powers.

334
00:14:58.720 --> 00:15:00.879
<v Speaker 1>Of two logicwers of two, So.

335
00:15:01.039 --> 00:15:05.639
<v Speaker 2>If robic copyer returns to zero, it actually means no errors.

336
00:15:05.639 --> 00:15:06.840
<v Speaker 2>But I didn't copy anything.

337
00:15:06.919 --> 00:15:09.600
<v Speaker 1>Wait, so zero is essentially I did nothing right.

338
00:15:09.840 --> 00:15:12.840
<v Speaker 2>It means the files matched the destination already, so it

339
00:15:12.919 --> 00:15:13.519
<v Speaker 2>just skipped them.

340
00:15:13.600 --> 00:15:14.240
<v Speaker 1>Okay.

341
00:15:14.320 --> 00:15:16.720
<v Speaker 2>If it returns a one, it means I copied one

342
00:15:16.799 --> 00:15:18.080
<v Speaker 2>or more files successfully.

343
00:15:18.320 --> 00:15:19.639
<v Speaker 1>Okay, that sounds like success.

344
00:15:19.679 --> 00:15:23.240
<v Speaker 2>But then you have two four, eight, sixteen, and they

345
00:15:23.240 --> 00:15:25.799
<v Speaker 2>can be combined. This is bitmasking. So if you get

346
00:15:25.799 --> 00:15:28.759
<v Speaker 2>a return code of three, that means one files copied

347
00:15:29.000 --> 00:15:30.759
<v Speaker 2>plus two extra files detected.

348
00:15:30.919 --> 00:15:33.159
<v Speaker 1>So you literally have to do modulo math just to

349
00:15:33.159 --> 00:15:35.120
<v Speaker 1>figure out if your backup work you do.

350
00:15:35.360 --> 00:15:37.559
<v Speaker 2>You can't just check if aer a level equals zero.

351
00:15:37.679 --> 00:15:39.559
<v Speaker 2>You have to check if the air level is less

352
00:15:39.559 --> 00:15:42.919
<v Speaker 2>than eight. Essentially, it's bizarre, but it gives you a

353
00:15:42.919 --> 00:15:46.000
<v Speaker 2>granular level of detail that other commands just don't.

354
00:15:46.399 --> 00:15:49.000
<v Speaker 1>It seems like that's the theme of this entire deep dive.

355
00:15:49.399 --> 00:15:51.200
<v Speaker 1>Bizarre but useful, it really is.

356
00:15:51.279 --> 00:15:53.320
<v Speaker 2>It forces you to think differently.

357
00:15:52.919 --> 00:15:56.159
<v Speaker 1>Which brings us to the philosophy of the book. Mcclerney

358
00:15:56.200 --> 00:15:59.840
<v Speaker 1>compares being a batch coder to being a Sumerian priest.

359
00:16:00.120 --> 00:16:03.200
<v Speaker 2>I love this analogy. He says, reading batch code, especially

360
00:16:03.240 --> 00:16:05.799
<v Speaker 2>when you get into the messy syntax of four loops

361
00:16:05.799 --> 00:16:09.960
<v Speaker 2>and delayed expansion, is like reading cuneiform. It looks esoteric,

362
00:16:10.000 --> 00:16:12.679
<v Speaker 2>it looks cryptic, but if you can read it, you

363
00:16:12.799 --> 00:16:15.720
<v Speaker 2>have immense power over the machine. You are one of

364
00:16:15.759 --> 00:16:17.799
<v Speaker 2>the few who can speak the language of the temple.

365
00:16:18.200 --> 00:16:22.480
<v Speaker 1>And he quotes Woody Guthrie in the epigraph. Any fool

366
00:16:22.519 --> 00:16:26.159
<v Speaker 1>can make something complicated, it takes a genius to make

367
00:16:26.200 --> 00:16:26.759
<v Speaker 1>it simple.

368
00:16:27.440 --> 00:16:30.399
<v Speaker 2>Batch force is simplicity. You don't have libraries, you don't

369
00:16:30.399 --> 00:16:34.159
<v Speaker 2>have fancy IDEs helping you out. You have raw text commands.

370
00:16:34.200 --> 00:16:36.440
<v Speaker 2>You are forced to strip the problem down to its

371
00:16:36.440 --> 00:16:39.480
<v Speaker 2>bare metal logic. And there is something deeply satisfying about that.

372
00:16:39.759 --> 00:16:41.279
<v Speaker 1>It's digital minimalism.

373
00:16:41.399 --> 00:16:44.000
<v Speaker 2>It is, and the barrier to entry is zero. That's

374
00:16:44.039 --> 00:16:45.080
<v Speaker 2>the most important takeaway.

375
00:16:45.120 --> 00:16:46.960
<v Speaker 1>You don't need to install Python, you don't need to

376
00:16:46.960 --> 00:16:48.559
<v Speaker 1>set up a compiler, right now you.

377
00:16:48.519 --> 00:16:51.799
<v Speaker 2>Can open notepad, you can type echo Hello world, you

378
00:16:51.840 --> 00:16:54.320
<v Speaker 2>can save it as dot bat, and when you double

379
00:16:54.360 --> 00:16:56.840
<v Speaker 2>click it, you have written a program. You are officially

380
00:16:56.879 --> 00:16:57.519
<v Speaker 2>a programmer.

381
00:16:57.639 --> 00:16:59.919
<v Speaker 1>It's the garage door opener to the world.

382
00:16:59.679 --> 00:17:02.799
<v Speaker 2>Of codev And honestly, if you can master the logic

383
00:17:02.840 --> 00:17:06.880
<v Speaker 2>of preventing an octal crash or figuring out robocopy bit masks,

384
00:17:07.200 --> 00:17:10.400
<v Speaker 2>you can learn any other language easily. Batch teaches you

385
00:17:10.440 --> 00:17:11.359
<v Speaker 2>to think like the computer.

386
00:17:11.720 --> 00:17:13.920
<v Speaker 1>So here is a final thought for you to chew on.

387
00:17:14.440 --> 00:17:17.880
<v Speaker 1>We talked about how a simple date August first, could

388
00:17:17.920 --> 00:17:21.039
<v Speaker 1>crash a server because of a tiny logic quirk, and

389
00:17:21.079 --> 00:17:23.119
<v Speaker 1>how a number is interpreted.

390
00:17:22.720 --> 00:17:23.920
<v Speaker 2>The octal bug.

391
00:17:24.000 --> 00:17:27.599
<v Speaker 1>It makes you wonder what other invisible logic is running

392
00:17:27.599 --> 00:17:30.640
<v Speaker 1>the world right now. How many banking systems or traffic

393
00:17:30.720 --> 00:17:33.640
<v Speaker 1>lights or power grids are running on a dot bat

394
00:17:33.680 --> 00:17:36.720
<v Speaker 1>file written in nineteen ninety five, just waiting for a

395
00:17:36.759 --> 00:17:39.720
<v Speaker 1>specific date or a specific file name to trigger a

396
00:17:39.799 --> 00:17:40.400
<v Speaker 1>hidden trap.

397
00:17:40.519 --> 00:17:43.359
<v Speaker 2>That is a terrifying thought. The digital infrastructure of the

398
00:17:43.400 --> 00:17:45.920
<v Speaker 2>world is held together by duct tape and set local

399
00:17:46.119 --> 00:17:47.359
<v Speaker 2>enabled delayed expansion.

400
00:17:47.599 --> 00:17:49.720
<v Speaker 1>And on that note, maybe go check your backups. Thanks

401
00:17:49.759 --> 00:17:50.359
<v Speaker 1>for diving in with

402
00:17:50.400 --> 00:17:51.319
<v Speaker 2>Us always a pleasure,
