summaryrefslogtreecommitdiffstats
path: root/2023/captions/emacsconf-2023-eval--editor-integrated-repl-driven-development-for-all-languages--musa-alhassy--main.vtt
blob: a024257793b744348412edb645976d626fdbe88e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
WEBVTT captioned by bhavin192

NOTE Introduction

00:00:04.880 --> 00:00:10.000
Hello, and welcome to EmacsConf 2023!

00:00:10.001 --> 00:00:12.109
My name is Musa Al-hassy,

00:00:12.109 --> 00:00:15.549
and I will be talking about "REPL-driven development."

00:00:15.549 --> 00:00:18.269
I like programming languages so much.

00:00:18.269 --> 00:00:20.269
I want to use them all over the place.

00:00:20.269 --> 00:00:23.069
I got a PhD in the topic.

00:00:23.069 --> 00:00:25.349
So let's just dive in.

00:00:25.349 --> 00:00:27.949
This is a lightning talk,

00:00:27.949 --> 00:00:31.309
so the details will be available in the repository.

00:00:31.309 --> 00:00:33.469
Links to longer videos and GIFs

00:00:33.469 --> 00:00:35.989
for those who are interested.

NOTE The wonders of C-x C-e

00:00:35.989 --> 00:00:37.309
So the wonderful thing about Emacs

00:00:37.309 --> 00:00:40.589
is that you can execute Lisp anywhere.

00:00:40.589 --> 00:00:42.829
For example, I can go to this piece of Lisp,

00:00:42.829 --> 00:00:45.576
press Ctrl-x Ctrl-e (`C-x C-e`)

00:00:45.576 --> 00:00:47.549
and get a little pop-up.

00:00:47.549 --> 00:00:49.669
Alright, so here I pressed `C-x C-e`

00:00:49.669 --> 00:00:51.389
and this is what it ran.

00:00:51.389 --> 00:00:52.776
And what this package gives you

00:00:52.776 --> 00:00:54.509
is the same ability

00:00:54.509 --> 00:00:56.909
for any language of your choosing.

00:00:56.909 --> 00:00:59.229
So for example, here is some Java,

00:00:59.229 --> 00:01:02.469
and I bound it to Ctrl-x, Ctrl-j (`C-x C-j`).

00:01:02.469 --> 00:01:07.149
So I say `C-x C-j`, and this runs some code,

00:01:07.149 --> 00:01:13.709
and over here I get a little pop-up.

00:01:13.709 --> 00:01:15.069
The wonderful thing about

00:01:15.069 --> 00:01:16.829
being able to run code from anywhere

00:01:16.829 --> 00:01:19.029
is that you can keep it in normal text files

00:01:19.029 --> 00:01:20.629
or any kind of file you like.

00:01:20.629 --> 00:01:23.669
For example, you can have hyperlinks,

00:01:23.669 --> 00:01:25.109
as it were…, like this one.

00:01:25.109 --> 00:01:28.549
`C-x C-e`, and now we can see this down here.

00:01:28.549 --> 00:01:30.789
Learn about it.

00:01:30.789 --> 00:01:34.189
But being able to run other languages besides Emacs

00:01:34.189 --> 00:01:36.149
lets us do some interesting things.

00:01:36.149 --> 00:01:39.589
For example, in the middle of a JavaScript program,

00:01:39.589 --> 00:01:43.429
you might write a line like this. `C-x C-n`.

00:01:43.429 --> 00:01:45.229
And that says down here

00:01:45.229 --> 00:01:47.269
`javascript-eval` in the mode line,

00:01:47.269 --> 00:01:49.643
and so this just checks that some endpoint

00:01:49.643 --> 00:01:51.189
is working as intended.

00:01:51.189 --> 00:01:52.749
So you don't need to use an external tool

00:01:52.749 --> 00:01:53.589
to check endpoints.

00:01:53.589 --> 00:01:57.469
You can just use Emacs in your favorite language.

00:01:57.469 --> 00:01:59.629
You know, you can keep your spirit up.

00:01:59.629 --> 00:02:03.709
So, `C-x C-a` runs `applescript-eval`.

00:02:03.709 --> 00:02:06.376
[Computer]: You can do it, buddy.

00:02:06.376 --> 00:02:13.269
[Musa]: Maybe you heard that in the background?

00:02:13.269 --> 00:02:15.389
The cool thing is, your code immediately takes form.

00:02:15.389 --> 00:02:18.469
Right away, you see it doing things, you know,

00:02:18.469 --> 00:02:20.349
altering your environment.

00:02:20.349 --> 00:02:24.429
For example, this is JavaScript,

00:02:24.429 --> 00:02:28.349
and JavaScript here is gonna change Emacs for us.

00:02:28.349 --> 00:02:32.109
So `C-x C-n`. And you can see down here

00:02:32.109 --> 00:02:34.669
`javascript-eval` was invoked.

00:02:34.669 --> 00:02:38.789
It returned true, and this line of JavaScript

00:02:38.789 --> 00:02:41.709
altered our Emacs. So that's really nice.

00:02:41.709 --> 00:02:43.749
So you don't need to use just Emacs Lisp if you like.

00:02:43.749 --> 00:02:46.149
You can use other systems.

00:02:46.149 --> 00:02:50.069
As you saw, the output is shown in overlays.

00:02:50.069 --> 00:02:52.869
So here's, for example, `C-x C-p` to run

00:02:52.869 --> 00:02:54.109
some Python code.

00:02:54.109 --> 00:02:55.476
Notice it blinked in red

00:02:55.476 --> 00:02:56.869
because I thought red was nice.

00:02:56.869 --> 00:02:58.389
You can configure as you like.

00:02:58.389 --> 00:02:59.409
And if you hover over it,

00:02:59.409 --> 00:03:01.869
you can see the solution there,

00:03:01.869 --> 00:03:04.669
and you can see it in a variety of familiar ways

00:03:04.669 --> 00:03:08.709
if you use `C-x C-e` regularly.

00:03:08.709 --> 00:03:09.989
You can insert the results.

00:03:09.989 --> 00:03:14.269
You can find documentation about them.

00:03:14.269 --> 00:03:15.989
The idea here is that

00:03:15.989 --> 00:03:20.389
you have this familiar Lisp workflow

00:03:20.389 --> 00:03:24.989
with `C-x C-e`, and this package ports it over

00:03:24.989 --> 00:03:27.069
to your favorite language out.

00:03:27.069 --> 00:03:28.343
So you can eval things,

00:03:28.343 --> 00:03:30.789
you can insert them, and do as you like.

00:03:30.789 --> 00:03:35.809
I think that's really neat.

NOTE An overview of REPL Driven Development

00:03:35.809 --> 00:03:37.209
This package allows you to do

00:03:37.209 --> 00:03:39.109
REPL driven development.

00:03:39.109 --> 00:03:42.309
In that, you can use it to grow your program.

00:03:42.309 --> 00:03:43.709
You don't need to restart it.

00:03:43.709 --> 00:03:45.549
You can see changes live.

00:03:45.549 --> 00:03:50.149
So here's, for example, this is in a Java runtime.

00:03:50.149 --> 00:03:52.869
You can see some balls bouncing around.

00:03:52.869 --> 00:03:54.509
I don't really know which one is the second one,

00:03:54.509 --> 00:03:57.229
but let's increase its size. `C-x C-j`.

00:03:57.229 --> 00:04:00.189
And this one increased in size,

00:04:00.189 --> 00:04:02.189
and you can see down here I pressed `C-x C-j`.

00:04:02.189 --> 00:04:05.549
Let's change the color to blue,

00:04:05.549 --> 00:04:09.309
`C-x C-j`, the color is blue.

00:04:09.309 --> 00:04:12.376
So all these changes are happening live.

00:04:12.376 --> 00:04:14.429
Three balls isn't really a ball pit.

00:04:14.429 --> 00:04:18.989
Let's go to 50 balls. There you go.

00:04:18.989 --> 00:04:21.469
So it's nice that you can do this

00:04:21.469 --> 00:04:23.209
without leaving your environment,

00:04:23.209 --> 00:04:26.189
without building, you can rapidly modify and see.

00:04:26.189 --> 00:04:29.776
I think that's nice.

00:04:29.776 --> 00:04:32.829
Unfortunately, I'm at the halfway point,

00:04:32.829 --> 00:04:35.309
so I won't be able to work through

00:04:35.309 --> 00:04:37.109
some of these nice problems,

00:04:37.109 --> 00:04:38.676
but you can see the videos

00:04:38.676 --> 00:04:41.509
or GIFs on the associated repo.

00:04:41.509 --> 00:04:42.709
Likewise for this one.

00:04:42.709 --> 00:04:43.909
This one would have been a lot of fun,

00:04:43.909 --> 00:04:46.509
but unfortunately, we're running short on time.

00:04:46.509 --> 00:04:51.143
Apologies.

NOTE REPL Driven Development with Java

00:04:51.143 --> 00:04:56.209
The neat thing here is: this package tries to

00:04:56.209 --> 00:05:00.269
bring the feeling of Lisp to other languages.

00:05:00.269 --> 00:05:03.509
So the idea of a REPL, or a Read Eval Print Loop

00:05:03.509 --> 00:05:06.949
is R and P are data interchange protocols.

00:05:06.949 --> 00:05:09.869
Unfortunately, not every language has those,

00:05:09.869 --> 00:05:12.709
but this package kind of encourages us to

00:05:12.709 --> 00:05:14.643
implement them if we don't have them.

00:05:14.643 --> 00:05:16.909
Let me show you an example.

00:05:16.909 --> 00:05:20.589
What do I mean here?

00:05:20.589 --> 00:05:22.709
This is a Java file.

00:05:22.709 --> 00:05:25.189
I've loaded this definition in.

00:05:25.189 --> 00:05:28.543
We can press `C-x C-j`,

00:05:28.543 --> 00:05:30.909
and you see it's a list of person.

00:05:30.909 --> 00:05:33.829
I didn't give this a name, so its name is $59.

00:05:33.829 --> 00:05:40.829
If I hover over it, we can see the definition again.

00:05:40.829 --> 00:05:44.429
So it's a person called Hamid, age 5,

00:05:44.429 --> 00:05:46.229
another person called Jaafar, age 6.

00:05:46.229 --> 00:05:52.229
This pretty printing is nice for me as a human,

00:05:52.229 --> 00:05:56.349
but I can't execute this. This isn't valid Java.

00:05:56.349 --> 00:06:00.609
So I could do `C-u C-x C-j`.

00:06:00.609 --> 00:06:05.109
If I have the help of a read protocol inserted.

00:06:05.109 --> 00:06:09.469
Sorry, `C-x C-j`. There it is.

00:06:09.469 --> 00:06:12.549
So look, it gives me a `new Person`

00:06:12.549 --> 00:06:14.349
with the construction everything.

00:06:14.349 --> 00:06:16.549
Now I can work with.

00:06:16.549 --> 00:06:17.949
Java can work with this.

00:06:17.949 --> 00:06:21.709
So this can be quite useful for regression testing

00:06:21.709 --> 00:06:25.749
or just to find out what your method spits out.

00:06:25.749 --> 00:06:29.869
We can do the same thing. Here's a bigger example.

00:06:29.869 --> 00:06:32.389
Trying to see it in the overlay is a bit cramped.

00:06:32.389 --> 00:06:34.589
We can say `C-u C-x C-j`.

00:06:34.589 --> 00:06:38.669
All right, and now we have executable code.

00:06:38.669 --> 00:06:40.876
Okay, this is neat.

00:06:40.876 --> 00:06:42.389
If you want to do something with it.

00:06:42.389 --> 00:06:45.789
I'm not really interested. I have four new persons.

00:06:45.789 --> 00:06:49.309
If I really want to look at this,

00:06:49.309 --> 00:06:55.649
I can say `M-x java-eval-navigate-output`,

00:06:55.649 --> 00:07:00.829
and now I see my output as this hierarchical tree.

00:07:00.829 --> 00:07:03.589
I go down, I can see what's inside these,

00:07:03.589 --> 00:07:06.709
what's the type of this thing, what's in there.

00:07:06.709 --> 00:07:09.349
All right, so that's nice.

00:07:09.349 --> 00:07:14.189
The idea is that we're not limited to

00:07:14.189 --> 00:07:15.629
just textual output.

00:07:15.629 --> 00:07:19.589
We can render output,

00:07:19.589 --> 00:07:22.229
thanks to the power of Emacs, in any way we want.

00:07:22.229 --> 00:07:26.749
In a browser, in a LaTeX file, in an Org mode (file),

00:07:26.749 --> 00:07:28.029
however we really desire.

NOTE Bring your own Read Protocol

00:07:28.029 --> 00:07:32.989
And if our language doesn't have an easy protocol,

00:07:32.989 --> 00:07:36.143
so what I did for Java in particular was:

00:07:36.143 --> 00:07:38.643
you take a blob, and you use some

00:07:38.643 --> 00:07:43.149
parsing expression grammars, or if you really want

00:07:43.149 --> 00:07:44.949
regular expression pattern matching,

00:07:44.949 --> 00:07:46.829
and you get some property list out,

00:07:46.829 --> 00:07:51.349
and then you construct an executable expression

00:07:51.349 --> 00:07:53.149
out of that. Like this `new Person`.

00:07:53.149 --> 00:07:56.749
It's nice that you can do these kind of things

00:07:56.749 --> 00:07:59.669
and that this software encourages you to do them.

NOTE Use Case: RDD & Job Interviews

00:07:59.669 --> 00:08:07.549
So one use case I actually use

00:08:07.549 --> 00:08:10.909
besides learning things is…

00:08:10.909 --> 00:08:14.776
oops oops oopsies oopsies showing you metadata

00:08:14.776 --> 00:08:15.509
you shouldn't be looking at.

00:08:15.509 --> 00:08:19.409
Don't look at my metadata. Sorry about that.

00:08:19.409 --> 00:08:23.209
One place I actually use this besides learning

00:08:23.209 --> 00:08:25.029
and trying new libraries and APIs

00:08:25.029 --> 00:08:26.776
and stuff like that is,

00:08:26.776 --> 00:08:29.509
for example, when I interviewed for jobs

00:08:29.509 --> 00:08:33.229
last year (I was changing jobs),

00:08:33.229 --> 00:08:34.676
I would share my screen,

00:08:34.676 --> 00:08:37.869
and if the interviewer gave me

00:08:37.869 --> 00:08:39.949
some inputs and outputs to play with,

00:08:39.949 --> 00:08:41.576
I could do essentially

00:08:41.576 --> 00:08:42.976
some sort of test driven development

00:08:42.976 --> 00:08:45.149
and constantly evaluate things

00:08:45.149 --> 00:08:46.589
right in front of the interviewer.

00:08:46.589 --> 00:08:49.949
For some design questions

00:08:49.949 --> 00:08:53.909
rather than sketching out my ideas in a Google Doc,

00:08:53.909 --> 00:08:55.509
I would share my screen and be like,

00:08:55.509 --> 00:08:57.989
"Hey, here's actual executable code,

00:08:57.989 --> 00:08:59.229
we can stub some things out

00:08:59.229 --> 00:09:00.576
and have some types,"

00:09:00.576 --> 00:09:03.476
and the idea is we can still check things

00:09:03.476 --> 00:09:05.643
and run them right there and then,

00:09:05.643 --> 00:09:08.143
which I thought was quite nice, and it helps to

00:09:08.143 --> 00:09:10.309
clarify your thought process, I guess.

00:09:10.309 --> 00:09:15.149
Anyhow, so that's my time,

00:09:15.149 --> 00:09:19.829
I hope you've enjoyed this little package,

00:09:19.829 --> 00:09:22.869
and again, sorry for the rush,

00:09:22.869 --> 00:09:24.149
it's a lightning talk.

00:09:24.149 --> 00:09:29.069
Feel free to find everything on the associated repo.

00:09:29.069 --> 00:09:34.389
And have a wonderful December Saturday.

00:09:34.389 --> 00:09:37.029
Take care! Bye bye, everyone.