WEBVTT

00:00:00.800 --> 00:00:06.944
<v Andrew>Okay, guess time. Your phone's web browser. How many programming languages do you think it can understand?

00:00:06.994 --> 00:00:15.304
<v Ava>Oh, I love this. Um. It does everything, so, a lot. Python, Java, C, Swift... I'm going to say dozens.

00:00:15.354 --> 00:00:16.231
<v Andrew>Three.

00:00:16.281 --> 00:00:17.283
<v Ava>Three?

00:00:17.333 --> 00:00:28.106
<v Andrew>Three. That's it. Everything your browser shows and runs, every website you've ever visited, every app in a tab, every map, is built from just three languages.

00:00:28.156 --> 00:00:29.658
<v Ava>That feels fake.

00:00:29.708 --> 00:00:37.744
<v Andrew>It's completely true. And here's the twist. The site we're unpacking uses four languages. So where does the fourth one live?

00:00:37.794 --> 00:00:40.584
<v Ava>I hate that I want to know.

00:00:40.634 --> 00:00:42.590
<v Andrew>You and everyone else.

00:00:48.390 --> 00:00:51.784
<v Andrew>Welcome to SimpleFlock Unpacked. I'm Andrew.

00:00:51.834 --> 00:00:55.244
<v Ava>And I'm Ava. This is episode three, The Languages.

00:00:55.294 --> 00:01:07.726
<v Andrew>Last time, we followed a request across the web. A client asks, a server answers, and there's a directory called D N S that finds the address. And we learned that four oh four was never a room.

00:01:07.776 --> 00:01:10.287
<v Ava>I'm still recovering from that.

00:01:10.337 --> 00:01:15.921
<v Andrew>Today, we meet the languages the site is written in. Four of them, each with one narrow job.

00:01:17.473 --> 00:01:27.768
<v Andrew>So let's start with the three that a browser understands. H T M L, C S S, and JavaScript. Everything else is either turned into those before it arrives, or it lives on the server.

00:01:27.818 --> 00:01:30.540
<v Ava>So those are the three. What are they each for?

00:01:30.590 --> 00:01:42.656
<v Andrew>Think of the restaurant. H T M L describes what is on the page. This is a heading, this is a button, this is a list. It's the layout of the dining room. Where the tables are, where the menu sits.

00:01:42.706 --> 00:01:43.846
<v Ava>Okay. The structure.

00:01:43.896 --> 00:01:53.004
<v Andrew>And a detail about this site. In an app like this, you hardly ever write whole H T M L files. There's one file, and it's a nearly empty shell. The JavaScript fills it in.

00:01:53.054 --> 00:01:59.634
<v Ava>So the dining room starts as an empty room, and the staff set the tables up when you walk in.

00:01:59.684 --> 00:02:01.932
<v Andrew>Exactly. A bare room that furnishes itself.

00:02:01.982 --> 00:02:12.853
<v Andrew>Then C S S is how it looks. It's a list of rules. Every heading uses this font. Every card has this corner radius. That's the decor. The paint on the walls and the style of the chairs.

00:02:12.903 --> 00:02:14.082
<v Ava>And JavaScript?

00:02:14.132 --> 00:02:20.359
<v Andrew>JavaScript is how it behaves. The staff. When you tap a button, something happens. That's JavaScript.

00:02:20.409 --> 00:02:26.773
<v Ava>Wait. Hold on. I have to ask the question everyone asks. Is JavaScript the same as Java?

00:02:26.823 --> 00:02:28.534
<v Andrew>Ooh. Okay. You're about to love this.

00:02:29.890 --> 00:02:41.410
<v Andrew>JavaScript was created in nineteen ninety five, at a company called Netscape, by an engineer named Brendan Eich. And the famous story is that he built the first working version in about ten days.

00:02:41.460 --> 00:02:42.770
<v Ava>Ten days.

00:02:42.820 --> 00:02:53.262
<v Andrew>A working prototype, in May of that year. And it's true, with a catch. What came out of that sprint was a working demo, not a finished language. It was tweaked for a long time after that.

00:02:53.312 --> 00:02:57.557
<v Ava>And it was called JavaScript from the beginning?

00:02:57.607 --> 00:03:06.650
<v Andrew>No. First it was called Mocha. Then LiveScript. And then in December, Netscape did a deal with another company, Sun Microsystems, which was promoting a language called Java.

00:03:06.700 --> 00:03:08.331
<v Andrew>And suddenly, it was JavaScript.

00:03:08.381 --> 00:03:10.108
<v Ava>So the name was...

00:03:10.158 --> 00:03:18.810
<v Andrew>A marketing decision. Java was the hot new thing, and the name rode the buzz. The two languages share a name, some syntax, and very little else.

00:03:18.860 --> 00:03:21.346
<v Ava>So it's like ham and hamster.

00:03:21.397 --> 00:03:25.327
<v Andrew>Ham and hamster. Same letters, completely different thing.

00:03:26.700 --> 00:03:33.639
<v Andrew>Okay, and there's a story about C S S, too. Because for the first years of the web, there was no standard way to style a page.

00:03:33.689 --> 00:03:36.306
<v Ava>Really? So what did pages look like?

00:03:36.356 --> 00:03:38.442
<v Andrew>Every browser decided for itself.

00:03:38.492 --> 00:03:50.609
<v Andrew>In nineteen ninety four, an engineer at CERN named Hawkon Vee-um Lee noticed the web was starting to be used for publishing, but there was no way to describe even a newspaper-style layout.

00:03:50.659 --> 00:03:57.728
<v Andrew>So he proposed a style sheet language. The idea is a single set of rules that decide how the whole site looks.

00:03:57.778 --> 00:04:00.322
<v Ava>And the "cascading" part of the name?

00:04:00.372 --> 00:04:10.606
<v Andrew>That's about how rules can build on top of each other. But for SimpleFlock, the clever part is something else. The site uses one stylesheet, and it uses variables. Named values, like one called radius.

00:04:10.656 --> 00:04:17.091
<v Ava>So instead of writing the exact corner size on every card...

00:04:17.141 --> 00:04:27.726
<v Andrew>You name it once, and every card follows. And here's why it matters. The dark theme only changes those variables. So the whole app flips between day and night, without repeating a single rule.

00:04:27.776 --> 00:04:31.646
<v Ava>That's lovely. So it's one switch behind the walls.

00:04:31.696 --> 00:04:32.117
<v Andrew>Exactly.

00:04:33.510 --> 00:04:41.964
<v Andrew>Now, the third language. JavaScript is how the site behaves. But SimpleFlock doesn't write plain JavaScript. It writes something called TypeScript.

00:04:42.014 --> 00:04:43.499
<v Ava>Which is...?

00:04:43.549 --> 00:04:55.363
<v Andrew>JavaScript, with labels added, that say what kind of thing each value is. Let me show you with a tiny example. Imagine a function called days until, that works out how many days are left until a date.

00:04:55.413 --> 00:04:56.427
<v Ava>Okay.

00:04:56.477 --> 00:05:05.291
<v Andrew>In plain JavaScript, nothing stops you from handing it the wrong thing. Say you give it the words tomorrow-ish. It runs. And then it misbehaves.

00:05:05.341 --> 00:05:08.123
<v Ava>A very confident, very wrong answer.

00:05:08.173 --> 00:05:19.009
<v Andrew>Exactly. In TypeScript, you label the function so it says, I expect a date written as text. If you hand it the number forty two, your editor flags the mistake before you run anything.

00:05:19.059 --> 00:05:22.094
<v Ava>So it's like a spell checker for what kind of thing you're using.

00:05:22.144 --> 00:05:30.188
<v Andrew>That's perfect. Or, if you want it for a ten-year-old, it's a label on a jar. If the jar says sugar, nobody pours it into the soup thinking it's salt.

00:05:30.238 --> 00:05:33.990
<v Ava>Because the label tells you before you taste it.

00:05:34.040 --> 00:05:43.019
<v Andrew>Before you run it, yes. And here's a detail I like. When the code is packaged up, the labels disappear. The browser and the server run plain JavaScript.

00:05:43.069 --> 00:05:45.930
<v Andrew>The labels have one job, catching mistakes early.

00:05:45.980 --> 00:05:50.231
<v Ava>So the labels are scaffolding. They come down when the building's done.

00:05:50.281 --> 00:06:01.128
<v Andrew>Exactly. And the language has its own origin story. Microsoft announced it in October of twenty twelve, led by Anders Hejlsberg, who had also created C Sharp. The reason was very practical.

00:06:01.178 --> 00:06:09.776
<v Andrew>People were building huge applications in JavaScript, a language that began as small scripts for a web page, and they needed a way to make that scale.

00:06:09.826 --> 00:06:10.904
<v Ava>So it grew up.

00:06:11.440 --> 00:06:21.309
<v Andrew>And here's the part that matters for our site. TypeScript is used on the front end, in the browser, and also on the back end, on the server. One language on both halves.

00:06:21.359 --> 00:06:24.978
<v Ava>Okay, that's what I was waiting for. Why does that matter?

00:06:25.028 --> 00:06:36.093
<v Andrew>Because some of the rules can live in a shared folder that both halves import. So, for example, the list of kinds of groups can't get out of step between the page and the server. There's one list.

00:06:36.143 --> 00:06:37.352
<v Ava>One source of truth.

00:06:37.402 --> 00:06:48.132
<v Andrew>And the project runs the type checker twice, once for the front end and once for the server. The build command says, in effect, check the types first, and only if that passes, package the app.

00:06:48.182 --> 00:06:51.780
<v Ava>So the labels act like a gatekeeper.

00:06:51.830 --> 00:06:53.750
<v Andrew>A gatekeeper. Which brings us to the fourth language.

00:06:54.850 --> 00:07:04.889
<v Andrew>S Q L. Most people say, sequel. It's the language for asking the database for things. And it reads almost like English. For example, select name from roles where the group is three.

00:07:04.939 --> 00:07:12.662
<v Ava>That's genuinely readable. Give me the names from the roles list, for group three.

00:07:12.712 --> 00:07:24.549
<v Andrew>Exactly. It's how the kitchen talks to the pantry. And we'll spend a whole episode on it. So here's the full set. H T M L for what's on the page. C S S for how it looks. TypeScript for how it behaves.

00:07:24.599 --> 00:07:26.570
<v Andrew>And S Q L for asking the database.

00:07:26.620 --> 00:07:29.944
<v Ava>Four languages, four narrow jobs.

00:07:29.994 --> 00:07:34.588
<v Andrew>And the browser never sees the fourth. S Q L is sent to the database, not run by the browser.

00:07:36.252 --> 00:07:42.170
<v Ava>Okay. So, why TypeScript? Why not just JavaScript? Or something else entirely?

00:07:42.220 --> 00:07:51.594
<v Andrew>Let's go through it. TypeScript catches a whole class of mistakes before running. One language works for the browser and the server, so code and rules can be shared.

00:07:51.644 --> 00:08:01.532
<v Andrew>There's a huge ecosystem, and editors give excellent autocomplete. The downsides? Extra concepts to learn, and a compile step. And remember, the types are removed at runtime.

00:08:01.582 --> 00:08:06.443
<v Andrew>So data arriving from outside, like from the network, still has to be checked by hand.

00:08:06.493 --> 00:08:10.427
<v Ava>So it doesn't protect you from everything.

00:08:10.477 --> 00:08:20.908
<v Andrew>Right. Now, plain JavaScript. Nothing to compile, and the lowest barrier. But mistakes show up when someone uses the feature, often a user. And it gets harder to change safely as the code grows.

00:08:20.958 --> 00:08:24.014
<v Ava>What about Python? People love Python.

00:08:24.064 --> 00:08:35.942
<v Andrew>They do, for good reason. It's gentle to read, superb for data work and scripting, with mature web frameworks like Django, Flask and FastAPI. But you'd still need JavaScript for the browser.

00:08:35.992 --> 00:08:44.041
<v Andrew>Two languages. And it's not a natural fit for Cloudflare's lightweight edge runtime, which is where this site's server code runs.

00:08:44.091 --> 00:08:46.586
<v Ava>Okay. And the speedy ones. Go, Rust.

00:08:46.636 --> 00:08:51.836
<v Andrew>Very fast, very efficient, with strong correctness guarantees, especially in Rust.

00:08:51.886 --> 00:09:00.417
<v Andrew>But more to learn, two languages again, and honestly overkill for a site where the bottleneck is a few hundred people tapping buttons.

00:09:00.467 --> 00:09:02.698
<v Ava>And Ruby, PHP.

00:09:02.748 --> 00:09:10.937
<v Andrew>Ruby with Rails, and P H P with Laravel. Extremely productive for classic database-backed sites. But again, two languages, and they want a conventional server, not a tiny edge function.

00:09:10.987 --> 00:09:15.972
<v Ava>So the thread running through all of them is two languages.

00:09:16.022 --> 00:09:28.590
<v Andrew>It's the decisive point. For one person, one language everywhere beats the alternatives. Every hour you spend learning TypeScript pays off on both halves.

00:09:28.640 --> 00:09:32.132
<v Ava>Which is the third pillar. One person has to be able to maintain it.

00:09:32.182 --> 00:09:34.065
<v Andrew>Exactly. The choice follows the pillars.

00:09:35.490 --> 00:09:45.406
<v Andrew>So here's what to take with you. A browser understands three languages. H T M L for what's on the page, C S S for how it looks, and JavaScript for how it behaves.

00:09:45.456 --> 00:09:54.880
<v Andrew>SimpleFlock writes its JavaScript as TypeScript, which adds labels that catch mistakes before the code runs, and it uses the same language on both halves.

00:09:54.930 --> 00:09:59.186
<v Andrew>The fourth language, S Q L, is how the back end talks to the database.

00:09:59.236 --> 00:10:02.110
<v Ava>And JavaScript is not Java. The name was a marketing decision.

00:10:02.160 --> 00:10:04.152
<v Andrew>A very successful marketing decision.

00:10:04.202 --> 00:10:06.517
<v Ava>What's next time?

00:10:06.567 --> 00:10:15.915
<v Andrew>Next time, episode four, The Front End. A tool called React builds screens from small reusable pieces, and the app gets by with only four packages.

00:10:15.965 --> 00:10:19.559
<v Andrew>We'll look at why that's a feature, and not just a quirk.

00:10:19.609 --> 00:10:20.379
<v Ava>I'm Ava.

00:10:20.429 --> 00:10:23.898
<v Andrew>And I'm Andrew. Thanks for listening to SimpleFlock Unpacked.

00:10:23.948 --> 00:10:31.051
<v Ava>Music by Kevin MacLeod, at incompetech dot com, used under a Creative Commons Attribution four point oh license.
