1 00:00:00,363 --> 00:00:02,754 When we write a program, we're figuring out a way to turn 2 00:00:02,754 --> 00:00:06,204 the brilliant ideas in our head into actual code. 3 00:00:06,414 --> 00:00:10,721 Here I want to talk about a technique that many programmers use to do that, 4 00:00:10,721 --> 00:00:13,262 and it's what we call "pseudocode." 5 00:00:13,262 --> 00:00:16,966 Now, "pseudocode" is probably a word you never heard before, 6 00:00:16,966 --> 00:00:21,406 but basically it's code that looks a lot like English 7 00:00:21,406 --> 00:00:24,600 or really whatever language you like to talk in. 8 00:00:25,220 --> 00:00:28,931 Well, okay, that may not make sense, so let's talk through an actual example. 9 00:00:29,571 --> 00:00:33,572 So let's say that I want to draw a nice symmetrical face. 10 00:00:33,572 --> 00:00:37,205 So I might start by looking at myself in the mirror and maybe sketching it out 11 00:00:37,205 --> 00:00:40,273 and seeing, okay, well I have this oval face. 12 00:00:40,273 --> 00:00:43,907 I have two eyes, and they're about at this level. 13 00:00:43,907 --> 00:00:46,766 And this is what the center of the face is 14 00:00:46,766 --> 00:00:51,271 and now I have an idea for what I want my face to look like. 15 00:00:51,271 --> 00:00:54,277 So I'll start writing it in pseudocode. 16 00:00:55,877 --> 00:00:59,285 So let's see, the first thing we'd want to do is draw the face, 17 00:00:59,285 --> 00:01:01,005 which is an oval, in the center. 18 00:01:02,145 --> 00:01:07,816 Then we'd want to draw the two eyes, which are two ovals, 19 00:01:07,816 --> 00:01:14,788 about two thirds up the face, and one fifth the size of the face. 20 00:01:15,048 --> 00:01:18,011 Not exact math there just looking at my own face. 21 00:01:18,011 --> 00:01:23,207 And then we draw the mouth, which is a line going halfway across the face, 22 00:01:24,117 --> 00:01:27,795 and maybe one third of the way up. 23 00:01:28,825 --> 00:01:32,589 So notice how I write my pseudocode as comments 24 00:01:32,589 --> 00:01:35,509 by starting each line with the two slashes here. 25 00:01:36,199 --> 00:01:40,017 That way I can write my pseudocode in the program itself 26 00:01:40,017 --> 00:01:43,100 and not have to worry about getting any syntax errors 27 00:01:43,100 --> 00:01:45,610 because the program will ignore comments. 28 00:01:46,670 --> 00:01:50,430 Now that I've written this in pseudocode, I can spend the time to turn 29 00:01:50,430 --> 00:01:54,995 each of these lines of pseudocode into actual bits of code 30 00:01:54,995 --> 00:01:58,375 Right? So let's see, for the face I need an oval in the center. 31 00:01:58,375 --> 00:02:03,295 For that I'll use the ellipse function for, and I'll, you know, figure out 32 00:02:03,295 --> 00:02:07,535 the center of the screen here, and figure out an eye size. 33 00:02:08,145 --> 00:02:09,709 Okay? That looks good. 34 00:02:09,709 --> 00:02:12,451 For the eyes once again those are ellipses. 35 00:02:12,451 --> 00:02:15,500 Everything on my face is an ellipse. I'm very round. 36 00:02:15,500 --> 00:02:21,739 And it's going to be, let's see, we'll do some math here to get the eyes 37 00:02:21,739 --> 00:02:26,844 at a nice place, and make them about a fifth the size. 38 00:02:26,844 --> 00:02:29,117 Okay, that looks good for the first eye. 39 00:02:29,117 --> 00:02:31,515 I'll just copy paste, make the next eye. 40 00:02:31,515 --> 00:02:32,642 Great! 41 00:02:32,642 --> 00:02:37,120 Now I can even leave my pseudocode for a friend to implement, 42 00:02:37,120 --> 00:02:38,620 and they probably could, because they can, you know, 43 00:02:38,620 --> 00:02:40,795 I have given this really nice description. 44 00:02:40,795 --> 00:02:44,708 So I'm going to do that here, because, you know, we're friends, right? 45 00:02:45,728 --> 00:02:48,572 So, you might think this is silly. 46 00:02:48,572 --> 00:02:51,792 Why are we going through the effort to write our program twice? 47 00:02:51,792 --> 00:02:54,877 First in human language and then in program language. 48 00:02:54,877 --> 00:02:59,047 Well, this example was pretty simple, but pretty soon you'll be building 49 00:02:59,047 --> 00:03:02,329 more complex programs, and it may be hard for you to keep 50 00:03:02,329 --> 00:03:05,459 the whole program in your head before coding it. 51 00:03:05,459 --> 00:03:09,301 So what I usually do is write the general idea in pseudocode first, 52 00:03:10,191 --> 00:03:15,121 and then I'll spend more time on the details of each part of that idea, 53 00:03:15,121 --> 00:03:19,012 converting each line of pseudocode into real code. 54 00:03:19,012 --> 00:03:22,420 I think you'll find that once you start using pseudocode 55 00:03:22,420 --> 00:03:24,303 you'll do it more and more. 56 00:03:24,303 --> 00:03:26,498 Try it in your next program and see.