0:00:00.363,0:00:02.754 When we write a program, [br]we're figuring out a way to turn 0:00:02.754,0:00:06.204 the brilliant ideas in our head [br]into actual code. 0:00:06.414,0:00:10.721 Here I want to talk about a technique [br]that many programmers use to do that, 0:00:10.721,0:00:13.262 and it's what we call "pseudocode." 0:00:13.262,0:00:16.966 Now, "pseudocode" is probably a word[br]you never heard before, 0:00:16.966,0:00:21.406 but basically it's code [br]that looks a lot like English 0:00:21.406,0:00:24.600 or really whatever language [br]you like to talk in. 0:00:25.220,0:00:28.931 Well, okay, that may not make sense, [br]so let's talk through an actual example. 0:00:29.571,0:00:33.572 So let's say that I want to draw [br]a nice symmetrical face. 0:00:33.572,0:00:37.205 So I might start by looking at myself [br]in the mirror and maybe sketching it out 0:00:37.205,0:00:40.273 and seeing, okay, well I have this oval face.[br] 0:00:40.273,0:00:43.907 I have two eyes, [br]and they're about at this level. 0:00:43.907,0:00:46.766 And this is what [br]the center of the face is 0:00:46.766,0:00:51.271 and now I have an idea for what[br]I want my face to look like. 0:00:51.271,0:00:54.277 So I'll start writing it in pseudocode. 0:00:55.877,0:00:59.285 So let's see, the first thing [br]we'd want to do is draw the face, 0:00:59.285,0:01:01.005 which is an oval, in the center. 0:01:02.145,0:01:07.816 Then we'd want to draw the two eyes,[br]which are two ovals, 0:01:07.816,0:01:14.788 about two thirds up the face, [br]and one fifth the size of the face. 0:01:15.048,0:01:18.011 Not exact math there [br]just looking at my own face. 0:01:18.011,0:01:23.207 And then we draw the mouth, which is [br]a line going halfway across the face, 0:01:24.117,0:01:27.795 and maybe one third of the way up. 0:01:28.825,0:01:32.589 So notice how I write [br]my pseudocode as comments 0:01:32.589,0:01:35.509 by starting each line[br]with the two slashes here. 0:01:36.199,0:01:40.017 That way I can write my pseudocode[br]in the program itself 0:01:40.017,0:01:43.100 and not have to worry about [br]getting any syntax errors 0:01:43.100,0:01:45.610 because the program will ignore comments. 0:01:46.670,0:01:50.430 Now that I've written this in pseudocode, [br]I can spend the time to turn 0:01:50.430,0:01:54.995 each of these lines of pseudocode [br]into actual bits of code 0:01:54.995,0:01:58.375 Right? So let's see, for the face [br]I need an oval in the center. 0:01:58.375,0:02:03.295 For that I'll use the ellipse function for,[br]and I'll, you know, figure out 0:02:03.295,0:02:07.535 the center of the screen here,[br]and figure out an eye size. 0:02:08.145,0:02:09.709 Okay?[br]That looks good. 0:02:09.709,0:02:12.451 For the eyes once again [br]those are ellipses. 0:02:12.451,0:02:15.500 Everything on my face is an ellipse. [br]I'm very round. 0:02:15.500,0:02:21.739 And it's going to be, let's see, [br]we'll do some math here to get the eyes 0:02:21.739,0:02:26.844 at a nice place, and make them[br]about a fifth the size. 0:02:26.844,0:02:29.117 Okay, that looks good for the first eye. 0:02:29.117,0:02:31.515 I'll just copy paste, make the next eye. 0:02:31.515,0:02:32.642 Great! 0:02:32.642,0:02:37.120 Now I can even leave my pseudocode [br]for a friend to implement, 0:02:37.120,0:02:38.620 and they probably could, [br]because they can, you know, 0:02:38.620,0:02:40.795 I have given this really nice description. 0:02:40.795,0:02:44.708 So I'm going to do that here, [br]because, you know, we're friends, right? 0:02:45.728,0:02:48.572 So, you might think this is silly. 0:02:48.572,0:02:51.792 Why are we going through the effort[br]to write our program twice? 0:02:51.792,0:02:54.877 First in human language [br]and then in program language. 0:02:54.877,0:02:59.047 Well, this example was pretty simple, [br]but pretty soon you'll be building 0:02:59.047,0:03:02.329 more complex programs, [br]and it may be hard for you to keep 0:03:02.329,0:03:05.459 the whole program in your head [br]before coding it. 0:03:05.459,0:03:09.301 So what I usually do is write the general[br]idea in pseudocode first, 0:03:10.191,0:03:15.121 and then I'll spend more time on[br]the details of each part of that idea, 0:03:15.121,0:03:19.012 converting each line [br]of pseudocode into real code. 0:03:19.012,0:03:22.420 I think you'll find that once you start[br]using pseudocode 0:03:22.420,0:03:24.303 you'll do it more and more. 0:03:24.303,0:03:26.498 Try it in your next program and see.