- 14 hours ago
UC Berkeley Computer Science Professor Sarah Chasins joins WIRED to answer the internet's burning questions about coding. How did programmers code the first ever code? What remnants of the early World Wide Web still exist online? Can someone still learn programming if they hate math? How do new programming languages get made? Why is debugging harder than writing code? How can computer scientists contribute to CRISPR? Professor Chasins answers these questions any many more on this episode of WIRED Tech Support: Coding Support.
Director: Justin Wolfson
Director of Photography: AJ Young
Editor: Richard Trammell
Expert: Sarah Chasins
Line Producer: Jamie Rasmussen
Associate Producer: Brandon White; Paul Guylas
Production Manager: Jonathan Rinkerman
Casting Producer: Nick Sawyer
Camera Operator: Nick Massey
Sound Mixer: Gloria "Glo" Hernandez
Production Assistant: Fernando Barajas
Post Production Supervisor: Christian Olguin
Post Production Coordinator: Stella Shortino
Supervising Editor: Eduardo Araujo
Assistant Editor: Billy Ward
Director: Justin Wolfson
Director of Photography: AJ Young
Editor: Richard Trammell
Expert: Sarah Chasins
Line Producer: Jamie Rasmussen
Associate Producer: Brandon White; Paul Guylas
Production Manager: Jonathan Rinkerman
Casting Producer: Nick Sawyer
Camera Operator: Nick Massey
Sound Mixer: Gloria "Glo" Hernandez
Production Assistant: Fernando Barajas
Post Production Supervisor: Christian Olguin
Post Production Coordinator: Stella Shortino
Supervising Editor: Eduardo Araujo
Assistant Editor: Billy Ward
Category
🤖
TechTranscript
00:00I am Sarah Chasens. I'm a professor of computer science at UC Berkeley. I am here today to answer
00:04your questions from the internet. This is Coding Support.
00:12TechGuy21, or it could be TechSky21, it depends on if it's a reference to LaTeX or not,
00:15says what remnants of the early World Wide Web are left. And it turns out that the first website
00:21that was ever put up is still available to us. So I actually have it here on my laptop right now.
00:25So this is a webpage put up in the early 90s by Tim Berners-Lee. It's describing what the World Wide Web
00:31is because Tim Berners-Lee is actually the person who created the World Wide Web. And we can see that
00:35it still displays in a totally readable and manageable manner in our modern web browsers,
00:39right? This is just Safari. But someone also actually recreated what it would have looked like
00:43in a browser of that time. So here we can see we've got the World Wide Web. It's all the same content,
00:48but of course it shows up very differently because the machinery they were working with at the time
00:52was working differently. The browsers they had made at the time were working differently. It's giving us
00:55instructions on how to actually browse through the rest of the page. If it's all the same content,
00:59obviously it's showing up a little bit differently.
01:01AdmirableLong9546 asks,
01:04New to coding, is it always this difficult? The easy answer, no.
01:07Every skill that you have ever learned in your life where parts of it became automatic over time,
01:12when you started riding a bike, it eventually became automatic. When you started playing guitar,
01:15it started becoming automatic. The exact same thing is going to happen with programming.
01:19NoConfidence5070, oh, I'm sorry about the username, asks,
01:21Can I still learn programming if I hate math? The answer is yes, absolutely, absolutely, 100%.
01:26So there are some kinds of math that make some kinds of programming easier,
01:30but it's not all kinds of math and it's not all kinds of programming. For that matter,
01:34there's some kinds of video games that give you practice with some of the things that make programming
01:38easier, right? Like there are lots of different skills out there that you might be practicing
01:41that might help you with some of the same things that you're going to need in order to do coding tasks.
01:46Math is one of them. Again, it's not even all math. There are certainly, there are some types
01:51of computer programming that you might want to do that probably would demand a little math from you.
01:56So there are parts of the computer programming world where you probably want to be comfortable
02:00with some parts of math, but no, you can absolutely, absolutely, absolutely get into programming,
02:04get really good at programming without being into math.
02:07Someone on the internet asks, what were the earliest computer viruses like?
02:10How did they infect and affect computers? In about the early 70s, computers had started to be sort
02:18of connected with each other through something called the ARPANET. We didn't have the internet yet.
02:21So you could go ahead and start spreading things that way. And there was this virus called the Creeper.
02:27It would print something out on the screen that said something like, I'm the Creeper, catch me if you can.
02:31Then they had to come up with the Reaper to go in and get rid of the Creeper program that was running on these machines.
02:36Demand2010 asks, how did programmers code the first ever code?
02:41Early, early on, there was the ENIAC. And the ENIAC was sort of the first computer that we all look at
02:47by modern standards and say, yep, to us, that looks like a general purpose computer.
02:51It looks a lot like sort of old school telephone switchboards where you're just plugging together
02:55wires and different parts of it. And that's actually how you're communicating what you want it to do.
02:59Eventually, folks figured out how to use punch cards, stiff piece of cardstock kind of a thing,
03:04and you're punching holes in it. And that was the way that we fed instructions into computers
03:09for a long time before we started storing programs in memory.
03:12So originally, the humans were just writing those ones and zeros.
03:15This was really painful. All this manual effort was really exhausting. It took months.
03:20And so this amazing thinker, Grace Hopper, developed the term compiler.
03:25Grace Hopper was this amazing early computing pioneer.
03:28She was a mathematician. She was incredible.
03:30And came up with the idea that instead of all these human people doing compilation,
03:35we should have a program on the machine that is actually going to do the compiling for us.
03:40And so that would be the compiler. And she invented this tool called A0 for putting together a bunch
03:45of different sort of portions of a program, a bunch of different sort of semi-related portions
03:49of code and getting them to talk to each other. And that was sort of the predecessor to the modern compiler.
03:54In fact, since that time, we have piled all this extra stuff on top of it.
03:58So the thing that Grace Hopper wrote in the early 50s actually no longer even looks like a compiler to us, right?
04:02It looks like one of the sort of sub-components of a compiler because we have all this other stuff
04:06that we've built up on top of it.
04:09BetterSir9013, what is the difference between programming languages?
04:12Why are some of them considered harder if they're all just same lines of code?
04:15There are lots of different things that can set programming languages apart.
04:19A big thing that I tend to think about is how much they sort of have your back.
04:22So a really common thing is for a programming language to be automatically trying to capture
04:27some kinds of bugs for you, trying to prevent you from running into some of the problems
04:31that might come back to bite you later.
04:33Some of them are saying, you know what?
04:35You're on your own.
04:36Like, just write what you want to write.
04:38Put in whatever bugs you want to put in.
04:40I'm going to run it for you.
04:41So an example of something in that general category would be C.
04:44There are other programming languages that are saying, you know what?
04:47I'm going to try to catch at least some bugs for you.
04:50Maybe not all the bugs, but I'm going to try to catch some bugs.
04:52And I'm going to try not to get in your way.
04:54I'm not going to try to demand a lot of extra information from you in order to do that.
04:58And so an example of something in that class would be maybe Python.
05:01And then you might have some other language over here
05:03that is really, really trying to have your back.
05:06It is going to try to catch as many bugs for you as it can possibly catch.
05:09And the way that it's going to do that is it's going to demand extra information from you.
05:13So it's going to make you work harder, but in exchange,
05:15it's going to catch a lot of those bugs for you.
05:16An example of something in that general zone would be Rust.
05:19Fainz Tai asks, working as a programmer, what do you actually do all day at work?
05:24Unfortunately, the answer is not as much programming as you might desire.
05:28In general, a lot of programmers get into programming because they like programming.
05:31And then it turns out that a lot of what they're spending their day-to-day on
05:34is talking with other programmers about how to get this person's piece of code
05:38to talk with this person's piece of code,
05:40how to make all of the sort of big code base work together,
05:43or you're talking to the client or the customer
05:44or someone who's going to be using this piece of code
05:47and you're figuring out what their needs are.
05:48You're having a bunch of meetings in order to figure out what the program should actually do.
05:52And then you're squeezing in as much of that actual coding time as you can
05:55because that's usually the fun part.
05:56DG Holmes asks,
05:57Is Python really the second best language for everything?
06:01I think probably whoever said this first,
06:04honestly, they were probably trying to get a dig in on Python a little bit,
06:07kind of trying to say it's not the first best language for anything.
06:10But the other way of reading this is to say that Python is very flexible.
06:13And it's true, Python is incredibly flexible.
06:15There's all kinds of programs that you could comfortably go and write them down in Python.
06:19You're probably going to have a good time.
06:20I have a personal fondness for Python.
06:22I have no bad feelings towards Python.
06:23So thumbs up, learn Python.
06:25A Reddit user asks,
06:26Is it worth learning C++ in 2025?
06:28The easy answer to this is absolutely.
06:30The follow-on answer is,
06:32If you're entering an existing code base and it's already written in C++,
06:35okay, great.
06:35It's already written in C++.
06:36You're going to probably use C++.
06:37On the other hand, if you are starting a new project,
06:40see if you could use Rust.
06:41Just take a look.
06:43Roy Rust Dev says,
06:44Why is Rust the most loved programming language in Stack Overflow surveys?
06:47Why do you love Rust?
06:48Do you try to convince others to learn Rust?
06:50Rust is...
06:51Probably one of the most exciting newish programming languages that we have available right now.
06:56They have been incredibly thoughtful about so many different parts of the design of this language.
06:59One of the things that people are really excited about is just they've been thoughtful about the error messages that you get when you do something wrong.
07:05Honestly, that does actually matter a lot when you are getting up and running with a language.
07:09But if you look even more deeply into the design of the language itself,
07:12it is bringing together sort of the best ideas from the past 20 years of new research in programming languages land.
07:19So there have been all of these really exciting ideas about how we can help programmers catch more bugs.
07:23This idea of the programming language should have your back.
07:25It should be looking out for the things that you might do wrong, and it should be catching those in advance.
07:29Rust is doing that at a level that the other languages out there kind of aren't really doing,
07:34while also being just incredibly fast.
07:36So if you are thinking about, oh, I'm going to have to use C in order to write this, in order to make sure that it's fast enough to run,
07:41you might also be thinking about Rust at this point, because it's high performance, but it's also, again, it's got your back.
07:48StarNight12 says JavaScript is a goaded language.
07:51I don't know why people hate it for no reason.
07:53I get what you're saying.
07:54I think in general there are some reasons to be a little bit skeptical of some of JavaScript's design choices.
07:59But, basically, if you're feeling dissatisfied with JavaScript, just learn TypeScript, right?
08:05If you're trying to write something out on the web and you're so frustrated at being locked into JavaScript,
08:09no problem, learn TypeScript, you're going to be happy.
08:11This is a very exciting one.
08:14BrilliantSir5729 asks, how on earth do programming languages get made?
08:17Someone has the idea for, I would like to write out this kind of program.
08:22I want the program text to say this, and here's what I want it to do.
08:24And then all of those steps that it takes in order to convert something in that high-level representation
08:29all the way down to the ones in zeros, you are now in charge of that.
08:32The process of doing that is called writing a compiler, or you might instead write an interpreter.
08:36There are multiple different ways of implementing a programming language.
08:38But, basically, yeah, what it takes is an idea.
08:40So, you don't necessarily have to generate assembly instructions,
08:43because it turns out we have all of these existing programming languages.
08:46And so you can take advantage of that in order to implement your new language in a way that's maybe easier for you.
08:52So, maybe I want to invent UnicornLang, right?
08:54I can go ahead and write my compiler that compiles from UnicornLang to Rust,
08:59which is an existing programming language.
09:01Now that I have this Rust program coming out the other end,
09:03I can then feed that into the existing Rust compiler
09:05and use that to actually get all the way down to the ones and zeros.
09:08So, you can start stacking together these different compilers.
09:11CheapLongStake says, why do computers just use the binary code zeros and ones?
09:16When we're writing numbers in our day-to-day life, we are using base 10.
09:19We have the digits zero through nine.
09:21Whereas, for computers, as we've talked about a bit, we are using zeros and one, base two.
09:26This is not necessarily innate.
09:28This is not enforced.
09:29The very first computer that we all sort of recognize as a computer, the ENIAC, actually used base 10.
09:34It can be done.
09:35You can totally do it.
09:36Remember that the way that we're representing this information inside the computer is by how much electricity is flowing through a part of the computer.
09:44And so, go ahead and imagine, I have put you in a room, there's a light bulb in the room, on the other side of the wall, I'm controlling a dimmer switch.
09:51I want you to tell me if we're at the low position of the dimmer switch or the high position of the dimmer switch.
09:55And I'm going to sort of mess around with that outside, and every time I yell out to you, you have to tell me low or high.
10:00If I'm just giving you low and high, you're probably going to be able to do that pretty reliably.
10:04I can be a little bit off in how much I've messed with the dimmer switch, and you're probably still going to be able to shout out low or high.
10:09Now, instead, say I say, I've picked these 10 spots on the dimmer switch, and I want you to be able to yell out 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9, based on where I've put it in there.
10:20But remember, you're in the other room, you're not seeing what I've actually done on the dimmer switch, you're just seeing the light bulb.
10:25So, say I stick it to 5, some of the time you're probably yelling out 5, some of the time you're probably yelling out 6, some of the time you're probably yelling out 4.
10:32It can be done to use base 10 inside the computer, but if you think about sort of, okay, we're really, we're trying to figure out how much electricity is flowing through this, it's a lot easier.
10:41It's going to be a lot more reliable if we just do the ones and zeros.
10:44Illustrious Run 4733 is asking, why is debugging harder than writing code?
10:48It is so much harder.
10:50Basically, the answer comes down to your mental model of what the program is doing versus what the program is doing.
10:55If you're going through the process of writing something up, right, doing the original draft of your program, you're not even necessarily at the point of testing if your mental model is aligned with the program.
11:06But basically, our sort of view of what's happening this entire time is, okay, this is what I'm expecting the program to do.
11:13You are keeping your mental model well aligned with what the program is doing, and so you're sort of building up the program bit by bit, continuing to make sure throughout that it is doing what you expect.
11:21If we hit the point where we are doing debugging, where we're trying to find something that has gone wrong, then our mental model and what the program is actually doing have diverged.
11:29Even harder if it's something that you didn't write, because then you're having to build up the mental model from scratch.
11:33You don't have any mental model in there to even start from, so you're having to go through and do that sort of difficult process of reading code to figure out, okay, what am I expecting this program to even do?
11:41Pleasant Relation 144 asks, how do you guys remember all the syntax?
11:45We don't necessarily.
11:46It turns out, you know, in contrast to, say, I am learning Spanish, right, I'm going to go and I'm going to be trying to speak to someone in Spanish.
11:53I'm not trying to be looking at my computer every time to translate a word.
11:57In contrast, if I am at the editor and I'm typing out my code, I've got the computer right there.
12:02If I've forgotten something, I can just look it up.
12:04It's no big deal.
12:05Red Pajamas asks, how do I know if I should learn back-end, front-end, or full-stack?
12:09The answer is you probably don't know in advance.
12:10You really probably just want to try it.
12:12So it could take a few years to be really, really comfortable and feeling really like an expert in any of these spaces.
12:17But to get a sense of what the day-to-day would look like, to just try it out, in a week or two, you can probably have a pretty good idea of what these programs look like and if you enjoy writing them.
12:25Covinda14 asks, how can computer scientists contribute to CRISPR?
12:28So I absolutely love this question because I'm really excited about work that does bring, I specifically think about programming languages work, but also computer science more broadly, into conversation with other disciplines.
12:38I think that's really powerful and really exciting and more folks should be thinking about it.
12:42But I think the actual answer here is go out and talk to the people who are doing the work you want to support.
12:48So one of the pieces of advice that I give my PhD students all the time, and they're amazing at doing this, is they will just go out and become apprentices to the teams that are doing the kind of work that they want to be supporting.
12:57So for example, I have an amazing PhD student who is currently basically embedded in a biology lab.
13:01You know, he's a computer scientist, but he's learned how to pipette, he's taken biology classes, he's in their labs helping with programming tasks.
13:07He is there doing the work of understanding their day-to-day.
13:10Because unfortunately, it's not quite as simple as, okay, we can just get everyone sort of from the bio side to type up one or two paragraphs about their problems and off we go.
13:18It takes work to figure out what are the real gaps there and what are the things we could do to fill it.
13:23So go spend time with the audiences, the communities that you are excited to serve.
13:28I think it's really powerful.
13:28So Senior Pineapple, or perhaps Senor Pineapple, asks, how hard would it be to build my own game engine from scratch?
13:35And the answer is, very hard.
13:37You will probably also have a really fun time, though.
13:39In general, a big thing that you're going to spend your time doing is deciding what abstractions you want your programmers to have access to.
13:46Basically, an idea or a word that they can use repeatedly if you have a pre-built snippet of code that is going to do one big long thing,
13:54but they get to call it by just a short name and reuse that code over and over again.
13:58And so what you're doing when you build your own game engine is trying to anticipate what are those snippets of code that people are going to need to reuse and reuse and reuse.
14:05But it turns out for building a real game, right, for building, especially if you're thinking about maybe a 3D game,
14:12it's going to be a lot of different things that the programmer is going to need to do, and it is going to take you some time to get there.
14:18The other thing is that there are certain parts of, depending on how low level you're deciding to go,
14:22like maybe you're building this on top of an existing game engine, in which case maybe you're not going to have to deal with this.
14:26But if you are going all the way down to deciding how every pixel is going to appear yourself,
14:31you're going to end up doing a lot of computer graphics type of computation, which involves some amount of math.
14:36So this process is super, super fun.
14:39And if you are interested in game programming, writing your own game engine is a very interesting exercise,
14:44but it's definitely not going to be the fastest route to a game.
14:47I think it comes down to whether you are personally interested in tasks where the goal is to put together words that look good together.
14:59If that is going to revolutionize your world, fantastic.
15:02ChatGPT is built on a kind of program called a large language model.
15:07A large language model is basically a program for putting together words that look good together.
15:12And so the approach that large language models designers actually took was,
15:17okay, what we're going to do is we're going to go out and collect all of the documents we can find on the web,
15:22all the web pages themselves, all the other documents we can rustle up.
15:25And these are basically, you know, words that humans have put together.
15:29And so we have some pretty good evidence that humans think these words look good together.
15:33And so we're going to make it play the fill-in-the-blank game on these documents.
15:37I might have a simple document.
15:39It says the dog has four legs, right?
15:42So I'm going to go ahead and feed that to the program.
15:44And I'm going to say blank dog has four legs.
15:47The first time it answers, it says sky.
15:49You say no, you silly program, not sky.
15:51The word is the.
15:52That's the word I want in there.
15:53You go again, you fill in the second word with a blank instead.
15:56So it's the blank has four legs.
15:58And it says swimming.
15:59You say no, you silly machine, not swimming.
16:01I want a dog there.
16:02So you repeat this process for about 300, 400 years of compute time.
16:06Because you can split up the work across a bunch of different computers
16:09and then get them together to sort of mash together their cheat sheets at the end.
16:13We've already sort of shown it the answer.
16:14You might say, Sarah, this doesn't seem okay.
16:16The program is going to be able to cheat.
16:18That is exactly the point, right?
16:20You are trying to get it to cheat.
16:21You want it to cheat.
16:23And so you are going ahead and you're giving this LLM, this large language model, a cheat sheet.
16:27And if you've ever heard something about sort of the number of parameters that a particular LLM has,
16:32that is about sort of the size of the cheat sheet that it was given.
16:35You make it play the fill in the blank game for about 300, 400 years of compute time.
16:40And then at the end of that, you have a program that is pretty good at fill in the blank.
16:44Now, this does not automatically give you ChatGPT, but it is pretty easy to turn one of these into a chatbot, right?
16:50Because now we just make a new document and it says something like, this is the transcript of a conversation between a human and a chatbot.
16:59And then the next part of the document says, the human has said, what is the capital of Sweden?
17:04The chatbot has said, colon, blank.
17:07And so it now fills in the blank because it's good at playing the fill in the blank game.
17:10And so maybe it says, the, and then you go again.
17:13But now it says, the chatbot says, colon, the, blank.
17:17And maybe now the next word it comes up with is capital.
17:19And you just keep going through that process, going through that process.
17:22And so that is what is going on with large language models.
17:25It's just programs for putting together words that look good together.
17:28GPT girl next door is asking, with AI advancing so fast, is it still worth learning to code deeply?
17:34Yes.
17:35You still need to be able to write code the old fashioned way for the most part in order to get programs out from these generative AI tools.
17:43So the first thing is that a really big skill that you learn over the course of a programming education
17:48is how to decompose programming problems, right?
17:51You're starting from this big, amorphous, sort of not super well specified, large problem.
17:57And you're figuring out, okay, well, I can break it into these two chunks.
18:00And then I can break that chunk into an even smaller chunk.
18:02And you keep doing this all the way down to something really small,
18:04small enough that you can actually answer it with a single line of code or a couple lines of code.
18:07If you haven't been trained to do that, it's not necessarily particularly easy to do.
18:12And so if you're just giving sort of these big, vague, open-ended things,
18:16it's really hard to turn that into a useful program that's actually going to work and run.
18:21The next big thing that comes up is the kinds of human language text, for example, English text,
18:26that I would write if I'm a non-programmer usually look different from what I would write if I was a programmer.
18:32Over the course of all the documents that got fed into the large language model
18:36in order to figure out what words look good together,
18:38the documents that had code in them were usually written by programmers.
18:42And so those were using the sort of programmer-style human language descriptions next to the code.
18:47And so even if the human language descriptions that a programmer would write might produce good code,
18:51the other alternative ways of describing those problems might not work.
18:54In order to use these tools, these generative AI tools,
18:58in order to actually generate useful programs,
19:00you mostly have to already know how to write programs the old-fashioned way.
19:03Which is frustrating for a lot of folks, but that seems to be the reality, at least right now.
19:07MinuteOrder4809 asks,
19:10What is the best way of using AI while coding?
19:12My first answer would be,
19:14Are you sure you have to?
19:15Double check.
19:15But if you've decided, yeah, I'm going for it,
19:17the thing you want to do is first break down your problem,
19:20whatever sort of shape that problem has,
19:23into the smallest portion of that problem that you can think of.
19:26Ideally, this should be something that's going to be about maybe five-ish lines of code,
19:29something like that.
19:31And then instead of writing it out in sort of standard human language,
19:34write it out in pseudocode.
19:35So pseudocode is basically where you're describing,
19:37this is exactly the thing that the computer is going to do,
19:39and then this is the thing the computer is going to do,
19:41and then this is the thing the computer is going to do.
19:43And it basically looks like writing in a programming language,
19:45except you're just not fussed about syntax.
19:46You're not worried about if you're missing a semicolon,
19:48or if the indentation is right, that kind of thing.
19:51Go ahead and feed that into your AI tool,
19:53and then you have to have a concrete plan
19:57for how you're going to persuade yourself
19:58that what comes out the other side is right.
20:00Do you have, you know, 20 tests that you're going to run?
20:03Do you have a friend who can look at this code
20:06and make sure that it's actually doing the right thing?
20:08Or if you are yourself a programmer,
20:10are you going to go through and make sure
20:11that it's actually doing the right thing?
20:12So have a concrete plan for how you're going to check it,
20:13or, you know, just don't use it.
20:16AdHistorical6271 is asking experienced developers,
20:19what has your experience been with vibe coding?
20:22Vibe coding is when we use one of those large language models
20:25or something like ChatGPT or one of the other tools
20:28built on top of that same underlying generative AI technology
20:31to generate a program,
20:33instead of writing it out the old-fashioned way
20:35by just typing a program in our programming language.
20:37Vibe coding seems to work okay
20:39if you are rewriting something
20:41that has already been written many, many, many times before.
20:44On the other hand, if you're trying to do anything new,
20:47that's probably not going to get you anywhere.
20:50The best bet really is to carve the problem up
20:52into teeny tiny chunks
20:53and then sort of use your own reasoning
20:55to actually do the program.
20:57There's actually, there's been some really interesting studies
20:58about this that looked at sort of the differences
21:01between whether it actually makes someone more productive
21:04versus whether they perceive
21:05that it makes them more productive.
21:06It turns out using an LLM-backed tool
21:09made them 20% slower,
21:11but even after doing the task with the tool,
21:14they all said they thought it had made them 20% faster.
21:16UlteriorKid324 asks,
21:19what does live coding actually look like?
21:21So basically, any time that you are programming,
21:24you're probably doing it live.
21:25I don't really know what the alternative is,
21:27so you're probably doing it live,
21:28but usually we use this term specifically
21:30when we were talking about doing it in front of an audience,
21:32like y'all.
21:33So I'm going to go ahead and do that right now,
21:35and we're basically going to use this as an opportunity
21:37to see what are some things you can do
21:39with honestly a pretty short, pretty simple program,
21:41but we're just going to talk it through step-by-step.
21:43So I'm now going to pull up an editor.
21:45We've got this tiny, tiny little program in here.
21:48So we have this URL,
21:50sort of an interestingly structured URL,
21:52but it's the same kind of URL
21:53that you might type into a browser.
21:54And then we have some country codes,
21:56and this one has a lot of them.
21:58But then here we have sort of a smaller list.
22:00We can see USA, Mexico, Canada.
22:02Let's start by just printing this out.
22:04So let's go ahead and print fewer country codes,
22:07and programmers love to start counting at zero instead of one.
22:12But that is, in fact, referring to the first item in the list.
22:14And we will copy that a couple of times
22:16because we're going to want to print all of the items.
22:19This is called TinyMap, so I will run TinyMap.
22:22You can see it has printed out those country codes.
22:24It's not an exciting program,
22:25but maybe I want to actually use those strings,
22:28those little pieces of text,
22:29in order to modify that original URL.
22:31So instead of just having the country code,
22:34let's instead copy this where it says USA in the sample URL.
22:38I'm going to go ahead and replace that
22:40with the country code that we are trying to use.
22:44Let's go ahead and pop that in there.
22:47We want to start with zero.
22:49And again, we're going to have to do the thing
22:50of copying and pasting a couple of times.
22:54Here we go, Python 3.
22:55We are now seeing our variants of the URL.
22:58We can see we've got the one that has USA.
22:59We've got the one that has Mexico.
23:00We've got the one that has Canada.
23:02But we probably aren't that interested
23:03in just printing out a URL.
23:05We are probably trying to actually do something
23:06interesting with that URL,
23:07like maybe get some data back from it
23:09the same way we would if we popped it into a browser.
23:11So let's go ahead and open something called a library.
23:15Basically, if some other programmer
23:17has made a bunch of little program snippets
23:19and they said to themselves,
23:20this is going to be useful for a lot of different people.
23:22I'm going to make it available.
23:23We would call that a library.
23:24So I'm going to go ahead and import requests.
23:27So instead of print,
23:29let's now have requests.get.
23:33And we will go ahead and repeat that process
23:35for all of these URLs.
23:38I'm starting at this point, personally,
23:40to get pretty bored of just retyping out
23:42this same big long string every single time.
23:44I'm starting to think maybe there's something
23:45that could help me avoid doing all that copying, pasting,
23:48maybe sort of automate for me
23:50the process of doing some of this.
23:51Let's get introduced to a loop.
23:53A loop is going to let us do something repeatedly
23:55for a bunch of different items
23:57that have some similar structure
23:58or for which we want to do the same kind of thing.
24:00So for i in range length of fewer country codes,
24:06let's go ahead and do something.
24:09Let's probably go ahead and do that requests,
24:12but I don't always want to do it
24:14for the first item in our country codes list.
24:17I'm probably going to want to do it
24:18for the ith item, right?
24:19The zeroth, then the first, then the third.
24:22Right now we're not having anything printed out,
24:24but I'm going to show that this is in fact
24:26going to run it for everything.
24:28So I know that requests is going to give me back some JSON.
24:31JSON is just one of those standard formats
24:32that we have that lets us represent data
24:34in a way that lots of different programs can understand.
24:37So if you have a standardized way,
24:38then your different programs can talk to each other.
24:40So let's go ahead and print out the JSON
24:42that we're getting back by running each of those requests.
24:45Okay, big messy JSON.
24:48Not super fun to read.
24:49Let's add ourselves a couple little sort of separators
24:51just to make it a little bit easier.
24:53We can run it again.
24:55Okay, we are now seeing these are split apart
24:58according to which of the three items
25:01they were associated with.
25:02I'm looking for this life expectancy data,
25:04and I know that this sort of particular part
25:06of the URL is that,
25:07and I know that the particular part
25:09that is going to tell me in this JSON
25:11what we're actually going to have as the value
25:14is this numeric value thing right here.
25:17So I'm going to go ahead and pop that into the code
25:19so that I don't have to just look through all of this.
25:21Let's give this a name.
25:22What shall we call this?
25:23We'll call this just the JSON,
25:24and then we can go ahead and get out from the JSON
25:27whatever is the portion that we are looking for.
25:30So JSON, I think this is inside the value,
25:34and we only want to get one item,
25:38this numeric value.
25:39So let's call that something.
25:40Let's maybe call that life expectancy.
25:42So now I want to go ahead and print out country code,
25:47this value right here,
25:49and we just have to make sure that we have stored it,
25:51we have saved it,
25:52we've given it that name before we actually use it.
25:54Let's print out both the country code
25:57and the life expectancy,
25:58and let's see if we're getting the data
26:00that we're expecting.
26:01Looks good.
26:01We can see the life expectancy
26:03for these three countries that we were looking at.
26:04Okay, let's go ahead and actually save that data,
26:07because maybe we want to do something else with it later.
26:09So let's make a new list.
26:11This one will be empty,
26:12and we're going to go ahead and fill it with the data
26:14that we're grabbing from these calls to the requests library,
26:18from going out to the web and saying,
26:19bring me back the data for this country.
26:21Let's keep on printing it too.
26:22Let's also go ahead and add it into data.
26:25So we will append to the data list,
26:27and we will go ahead and put in country code
26:30and life expectancy.
26:33Let's print out our data at the end of the process,
26:35just to make sure that this is actually looking
26:37like we're expecting it to look.
26:38I'll run the program again.
26:39Okay, we are seeing that data at the end.
26:41What if we put it on a map?
26:43Again, we're going to want to use a nice library
26:45that someone has built for us.
26:46So let's import plotly.express,
26:51and we'll call that px.
26:53So now, instead of just printing the data,
26:55let's also make a figure that represents the data.
26:58So fig equals px dot, I think it's chloropleth,
27:02and let's use our data.
27:03Now we're going to have to tell it what are the locations
27:05and what are the things that we want to visualize in this.
27:09So I'm going to say locations,
27:11and I'm going to have that be zero,
27:12meaning it's the zeroth item in each of these pairs.
27:14We can see that right here.
27:16We can see country code is on the left,
27:17so it's the zeroth item,
27:18and then life expectancy is the oneth item,
27:21or in the sort of more usual terminology
27:23that you and I would use day to day,
27:25it's the second item.
27:26So let's go ahead and say color equals one.
27:31And once we have actually got that,
27:33let's actually show the figure.
27:36So here we go.
27:37We've got our program ready to go.
27:40Fantastic.
27:41We can see our little map.
27:42Here it is.
27:43It's got those three countries colored.
27:45We probably are interested in doing it for all the countries,
27:48so I'm just real quick going to go in here
27:49and actually change which of these lists we're using.
27:52So you can see that we've just been using
27:53these fewer country codes, which just says the three,
27:55but why not run it for all the countries, right?
27:57The data's there.
27:58So let's go ahead and use some country codes
28:01instead of fewer country codes,
28:03and let's get rid of all these old unnecessary lines,
28:06and then we will have our final program.
28:10So here we go.
28:11It is going to talk to the internet.
28:12It's going to collect the information
28:13for all those different countries.
28:14After a few moments there,
28:16I think it was a little under a minute,
28:17we've got our map.
28:18It's got the data for a bunch of different countries.
28:19HGMIB926 asks, how do I read code?
28:23This is honestly an incredibly difficult question to answer
28:26because reading code is actually really hard.
28:28It's not like when we're sitting down to a piece of text.
28:30We're going to start on page one,
28:31we're going to go to page two,
28:32we're moving in this sort of linear manner.
28:33That's not how we typically do it when we're reading code.
28:36Don't take this advice if there's any chance
28:38that your code might be malicious,
28:39but if this code is not malicious,
28:41go ahead and run it.
28:42Take a look at a part of the output
28:43that you are interested in,
28:44you want to follow up on.
28:45Go figure out what part of that code
28:48actually created that output
28:50and then start working your way back, right?
28:52What were the outputs that came out
28:53of some earlier part of the code
28:55that ended up going into the process
28:56of making that output?
28:57There are even debuggers that are specially built
29:00to sort of help you work through
29:02individual executions of code.
29:04So one of my favorite kinds of debuggers
29:05that I really like is called time travel debugging.
29:07You've gone ahead,
29:08you've done an execution of your program
29:10that you're interested in,
29:10but maybe you actually want to walk it back,
29:12you want to travel back into the past
29:13to see what was happening before.
29:15You can go ahead and do that.
29:16If you don't want to travel ahead,
29:17you can do that, thus time travel.
29:19Vidro3 asks,
29:21how do computers understand code?
29:23I'm going to talk us through it
29:25with a specific concrete program.
29:26I'm going to show us how we get
29:27from something that looks kind of like
29:30a computer program
29:31that you might have seen places
29:32all the way down to the ones and zeros
29:33that you can then actually store in the machine.
29:36And we'll draw the four stages
29:37that we take it through.
29:39So this is going to be, you know,
29:40just the input to this entire process.
29:42So here we go.
29:42We've got one plus two plus four.
29:46Now, the very first thing that needs to happen
29:48is I have to figure out which portions of this
29:51to treat separately versus together.
29:54I'm going to just do that by underlining.
29:56So the left parenthesis is going to be on its own,
29:59but one is going to be on its own,
30:00the plus sign, the two,
30:01the right parenthesis, the plus, the four.
30:04You can see we've ignored these spaces.
30:06We've got our left parenthesis, our one,
30:09our plus, our two, our right parenthesis,
30:13our next plus, and our four.
30:14This stage, what I've just drawn out,
30:16that is called lexing or tokenizing
30:18because the things that you see in this list
30:20on the right are the tokens.
30:22So the next thing we're going to want to do
30:23is turn this into something
30:25that we can actually sort of use
30:27to understand something about
30:28the structure of this program.
30:30So here at the root of something
30:31that I'm going to call a tree,
30:33we're going to have the addition operator,
30:35and this is going to be the operation
30:36that's going to actually happen second
30:38because what we want to do
30:39is we want to make sure that that one
30:40and that two that we're adding together,
30:42we can see that those are in parens,
30:43we actually want to do that first, right,
30:45because that has been grouped.
30:46We'll have a one on the left
30:47and a two on the right.
30:48And then what we have on that last branch there
30:51of the top add is going to be that four.
30:53Now we can start to see
30:55that there's some structure happening here.
30:58We can see that sort of the one and the two
30:59are going to be grouped together by some operation,
31:01and then whatever we get out from that,
31:03operation, that's going to be grouped together with the four.
31:05But actually, a lot of folks know
31:06that what goes into the computer
31:07eventually has to be ones and zeros,
31:09and there's no clear way necessarily at this point
31:11to turn this into ones and zeros.
31:13So now we're going to turn it
31:14into something called instructions.
31:16And instructions are basically just going to be the things
31:19that the processor knows how to handle.
31:21So here we go.
31:22We're going to go ahead and write out move one, right,
31:24because that's the first value
31:25that we're dealing with into R8,
31:27one of the slots that the computer has available,
31:28and then maybe we will move into R9,
31:31another slot, the value two.
31:33We now have everything we need to do
31:34in order to run our first addition.
31:36So let's go ahead and do an add instruction,
31:39and we'll go ahead and add together
31:41what we've got from R8 and R9,
31:43and that is going to put that value inside R8.
31:46So now let's go ahead and move that four
31:48into one of these.
31:49So we're no longer using R9 anymore
31:51for the thing we were previously using.
31:53So let's go ahead and move into R9,
31:55the value four,
31:57and now if we do add R8, R9,
32:01we should get the result of the entire program in there.
32:03And then this phase,
32:04where we're actually taking
32:06that nice structured representation of the program
32:08and turning it into instructions,
32:09that is actually called code generation.
32:11But at some point,
32:12it actually has to turn into ones and zeros.
32:14So let me go ahead and highlight some common structure
32:17that we're seeing across these instructions.
32:18We can see that there's sort of this thing,
32:20and then there's this thing,
32:21and then there's this thing,
32:22and it turns out that we have a scheme
32:24for turning each of these into a binary number.
32:28And then we do the exact same process
32:29for all of those instructions,
32:31and finally what we have is just ones and zeros.
32:34So now I'm going to turn to the computer.
32:36All right.
32:37So here we are in something called x86-64 Playground.
32:42This is just a website.
32:44You can visit this on your browser.
32:46I have typed in the instructions
32:47that I was drawing over here on the iPad,
32:49and so we're now going to get to see
32:50what it actually does to a representation
32:52of the computer's state
32:53when we are running through these instructions.
32:55So here we go.
32:56We start with that first move instruction.
32:58You can see that over here in R8,
33:00we now have the value 1.
33:02So let's go ahead and run the next step.
33:04Fantastic.
33:04We can see that now inside R9,
33:06we've got that 2 value.
33:07If we keep going,
33:09we're now going to see that we've done the addition
33:10and the output from that addition,
33:12the value 3,
33:13that now lives inside R8.
33:15Fantastic.
33:16One more.
33:16We've got moving the 4 into R9.
33:19It's okay for us to reuse R9, right?
33:21We're not overwriting anything
33:22that we're going to need later,
33:23so it's totally fine.
33:24We can go ahead and get that value into R9,
33:27and then one more,
33:28and we can see that we've done that last addition
33:29and we've got the final output 7
33:31represented inside R8.
33:33And that is how the computer understands
33:35the code that you write.
33:36That's it.
33:36We have run out of questions today.
33:38I hope you all have learned something new.
33:41I hope you're excited about programming languages
33:42and maybe even about compilers.
33:45Until next time.
33:45R9.
Be the first to comment