-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathchapter-04.srt
512 lines (400 loc) · 10.4 KB
/
chapter-04.srt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
1
00:00:00,000 --> 00:00:03,954
Chapter 4.
Sketching the API of a Target class.
2
00:00:04,834 --> 00:00:08,914
I'm just going to make a scratch
directory here and try something out.
3
00:00:11,620 --> 00:00:23,657
Yes, I'm thinking I want to do something
like this; I want to require './scratch/target'.
4
00:00:24,090 --> 00:00:37,897
And hello_js is a Target with a path.
5
00:00:40,845 --> 00:00:45,005
We are not doing Haskell,(whoops).
6
00:00:48,491 --> 00:00:54,468
The minimum... It has a path name
which is the file it's going to generate.
7
00:00:54,514 --> 00:01:05,440
and then it has a list of commands
that are how to generate that thing.
8
00:01:06,034 --> 00:01:08,685
TS: What do you mean by target here?
9
00:01:08,680 --> 00:01:17,165
JC: A target is a file (I guess I'm borrowing
some nomenclature from make here),
10
00:01:17,177 --> 00:01:23,211
but a target is any of the files in your system.
11
00:01:24,000 --> 00:01:30,160
So when you talk about hello.js is
derived from hello.coffee, hello.js is the target.
12
00:01:30,171 --> 00:01:33,390
hello.coffee could also be a
target that is derived from other things.
13
00:01:33,885 --> 00:01:41,325
They can either derived things or
primary things, like your source code.
14
00:01:41,942 --> 00:01:47,691
TS: I suppose in this case hello.js is both a target
and also it's going to be the input to the target.
15
00:01:47,690 --> 00:01:50,914
JC: Exactly. So there's a recursion there.
16
00:01:51,611 --> 00:01:58,280
And you want these things to compose in that
way so you can make targets out of other targets.
17
00:01:58,360 --> 00:02:03,645
[Silence]
18
00:02:03,737 --> 00:02:14,468
In Ruby you could do this, for example
by putting a block here. Like system... [he thinks]
19
00:02:14,697 --> 00:02:21,520
How did we do this... We ran... [he types].
20
00:02:38,720 --> 00:02:49,520
That would work, but I'm leaning toward
making this string be data rather than blocks.
21
00:02:49,657 --> 00:02:56,840
Just because it's quite common
to do, like in make you can...
22
00:02:56,960 --> 00:03:06,468
Here we've duplicated this pathname
example/src/hello.js. That's coffee isn't it.
23
00:03:11,577 --> 00:03:18,617
The idea here is that we've duplicated.
This is the directory that the target lives in.
24
00:03:18,731 --> 00:03:27,634
If you're doing make you can do that... So $@ is the
pathname of the target your currently building.
25
00:03:27,630 --> 00:03:34,457
And there's various functions so dir is the
function that gives you the directory of that.
26
00:03:34,740 --> 00:03:37,348
I'm not going to get do that yet,
27
00:03:37,405 --> 00:03:44,091
but it means that I don't necessarily want
to provide a block that just runs this code.
28
00:03:44,110 --> 00:03:45,931
I want to provide this code as data,
29
00:03:45,954 --> 00:03:51,980
because it might need to be further
interpreted by the system before being executed.
30
00:03:52,330 --> 00:03:56,491
TS: So if it's a block it's some opaque
code that can't then be modified.
31
00:03:56,530 --> 00:04:05,291
JC: Yes, I want it to be data.
So I'm going to put that in an array.
32
00:04:07,480 --> 00:04:12,491
TS: Is the expectation at this point
that you will pass that to system... Right now?
33
00:04:12,502 --> 00:04:14,662
JC: Exactly
34
00:04:20,662 --> 00:04:27,714
So if I make a target and build
it, then I want it to BE built.
35
00:04:27,710 --> 00:04:35,017
But the name of the thing I'm building and
the way in which it gets built are both data now,
36
00:04:35,040 --> 00:04:38,068
so you could put anything in it.
37
00:04:38,060 --> 00:04:40,685
TS: Why did you make it an array?
38
00:04:42,420 --> 00:04:46,525
JC: That's a good question, there's only one command.
39
00:04:46,560 --> 00:04:51,725
So we possibly don't need an array.
40
00:04:51,770 --> 00:05:01,554
There is one thing I've missed out, when I deleted
that code earlier, I left that directory out didn't I?
41
00:05:01,560 --> 00:05:07,165
So we need to make sure that directory
exists before we compile anything into it.
42
00:05:07,180 --> 00:05:17,520
So let's also make that directory part of the thing.
43
00:05:17,540 --> 00:05:22,651
You can see how this becomes repetitive because
you mention the same things over and over again.
44
00:05:22,860 --> 00:05:25,657
That ought to work from a clean slate now
45
00:05:25,691 --> 00:05:31,371
because that's all the commands that need
to be run to set up the directory and compile code.
46
00:05:31,474 --> 00:05:36,834
I want this script, when it's run, to make that file.
47
00:05:36,920 --> 00:05:52,377
[Silence]
48
00:05:52,457 --> 00:05:55,980
If I run this it will get no such file scratch/target.
49
00:05:55,980 --> 00:05:59,885
As I expected, scratch/target.rb. OK.
50
00:05:59,885 --> 00:06:03,725
So you need a Target class.
51
00:06:06,030 --> 00:06:10,400
And that's going to take the
pathname of the thing we're building.
52
00:06:10,480 --> 00:06:15,920
And some instructions.
53
00:06:16,102 --> 00:06:26,937
[Silence]
54
00:06:26,930 --> 00:06:28,640
OK
55
00:06:30,490 --> 00:06:34,240
So: undefined method build for Target... OK, that's fine.
56
00:06:36,171 --> 00:06:38,617
I want to build the thing.
57
00:06:38,628 --> 00:06:46,960
And like you said,we could pass each of those
strings into system and it ought to run them.
58
00:06:48,262 --> 00:06:54,845
So we can put @instruction.each do |instruction|
59
00:07:01,862 --> 00:07:04,811
I'm going to print what each instruction is.
60
00:07:04,880 --> 00:07:11,142
Because that's a helpful thing that make does, and it
helps you see what you build is actually doing.
61
00:07:11,154 --> 00:07:16,994
When we ran that shell script, another thing
it didn't do is show us what was going on.
62
00:07:17,382 --> 00:07:23,090
If you can see what's going on you can verify if
it's being lazy, not running the certain things.
63
00:07:23,100 --> 00:07:32,422
So we'll print each one and then pass
it to system, and that will be enough.
64
00:07:32,434 --> 00:07:38,148
I've made this `@output` variable,
partly because I'm anticipating that...
65
00:07:39,170 --> 00:07:46,320
If I'm calling puts, generally things that have
puts statements in them are not good for your tests,
66
00:07:46,365 --> 00:07:49,268
because they fill up the tests
with whatever is going on.
67
00:07:51,740 --> 00:07:58,057
It's a sort of habit I have... If I know that
something's going to need to be a parameter
68
00:07:58,080 --> 00:08:01,028
or maybe a constant or an instance variable later.
69
00:08:01,040 --> 00:08:09,794
I'll make it but then assign it
to a constant in the constructor.
70
00:08:09,817 --> 00:08:15,337
It means I don't need to go through all the code
later and go through the extraction process.
71
00:08:16,130 --> 00:08:22,342
This may be a bit premature but I can
see that coming up so I'll just do that.
72
00:08:23,337 --> 00:08:28,777
So it's printed what it's doing and
made the directory and the coffeescript.
73
00:08:28,940 --> 00:08:34,262
And now there should be
one file in lib which is hello.js
74
00:08:34,297 --> 00:08:43,337
And that should contain compiled code, which it does.
75
00:08:47,040 --> 00:08:55,131
So I guess that's a minimum
viable build system... I suppose.
76
00:08:55,154 --> 00:08:57,474
We've got this.
77
00:08:57,470 --> 00:09:06,560
And we can make another one out of complimenter.
78
00:09:06,760 --> 00:09:14,548
[Silence]
79
00:09:14,605 --> 00:09:19,337
And...Then we could build each of them.
80
00:09:22,742 --> 00:09:29,348
And then we could have one for the bundle.
81
00:09:29,500 --> 00:09:35,325
[Silence]
82
00:09:36,354 --> 00:09:40,520
Target.new('example/bundle.js')
is what's being built here.
83
00:09:40,594 --> 00:09:47,325
And build this... What did we do in our build script?
84
00:09:49,770 --> 00:09:55,325
We ran this command. So I'll just take that.
85
00:09:55,530 --> 00:09:58,525
[Silence]
86
00:09:58,520 --> 00:10:03,348
Put that there and then...
87
00:10:03,554 --> 00:10:07,291
Build it.
88
00:10:07,620 --> 00:10:13,257
[Silence]
89
00:10:13,291 --> 00:10:16,400
Ah! This doesn't exist yet because we didn't build it.
90
00:10:16,491 --> 00:10:19,382
ruby scratch/test.rb
91
00:10:21,040 --> 00:10:27,657
OK, so that's made the lib directory twice
and run the coffee twice with the two things.
92
00:10:27,691 --> 00:10:33,520
So let's run uglify so we get
our output as we wanted it.
93
00:10:39,657 --> 00:10:44,674
This is like enough of a system, that
you can do something useful with.
94
00:10:44,948 --> 00:10:47,188
TS: OK.
95
00:10:47,748 --> 00:10:53,977
How close is this to the generalized
instructions mention in the brief?
96
00:10:53,970 --> 00:11:00,800
Are these the generalised instructions or
are they not sufficiently general to count?
97
00:11:01,160 --> 00:11:06,125
JC: They are general in that you can put any
shell command in here, and it will be run.
98
00:11:06,160 --> 00:11:12,765
There wasn't a great way for supplying the input to
the system and there's a lot that it can't do yet.
99
00:11:12,857 --> 00:11:21,942
But this is a minimal thing for
modeling a file and how it gets created.
100
00:11:22,605 --> 00:11:27,165
We're still not using the pathname input to this yet.
101
00:11:27,211 --> 00:11:31,531
That will become more important when
things want to check that they're up to date,
102
00:11:31,554 --> 00:11:35,257
because they have to know where their target is.
103
00:11:35,290 --> 00:11:42,902
This target only runs shell commands, it doesn't
look at the output of those shell commands.
104
00:11:42,937 --> 00:11:46,662
And it doesn't relate them to
the output file in any way.
105
00:11:46,670 --> 00:11:51,737
But when it wants to know if something's up to date,
it's going to have to look at those files.
106
00:11:51,908 --> 00:11:57,348
TS: I thought it was interesting that you
didn't start by building the target class,
107
00:11:57,680 --> 00:12:02,091
but by USING the target class and
then you kind of dropped down...
108
00:12:02,091 --> 00:12:07,028
And every time you ran this it failed, so you
implemented a method on it till it worked.
109
00:12:07,074 --> 00:12:08,674
JC: Right.
110
00:12:08,700 --> 00:12:15,520
I have a vague idea where I'm going because it should
look like something I'm already familiar with.
111
00:12:17,680 --> 00:12:20,160
But I don't quite know what
models and functions I want yet.
112
00:12:20,182 --> 00:12:25,028
I'm just thinking, how would
you want to interact with this?