1 00:00:06,380 --> 00:00:08,790 Now I'm going to finish the first version of the Cat program. 2 00:00:10,010 --> 00:00:12,610 That's going to involve designing two functions. 3 00:00:12,610 --> 00:00:16,380 So, in that way it's going to be quite familiar, we'll go through the HTDF 4 00:00:16,380 --> 00:00:19,524 recipe twice. But we're going to be designing those 5 00:00:19,524 --> 00:00:22,879 functions in the context of a partially complete, larger program. 6 00:00:24,470 --> 00:00:27,940 That's something that gets to be more and more important as we go forward. 7 00:00:27,940 --> 00:00:31,544 As the programs get bigger, we often have lots of incomplete function that we need 8 00:00:31,544 --> 00:00:35,655 to finish before we're done. And the most important thing in this 9 00:00:35,655 --> 00:00:39,195 video is going to be how to use the wish list mechanism, to keep track of that 10 00:00:39,195 --> 00:00:44,263 work that remains to be done. We have a constants part of the file 11 00:00:44,263 --> 00:00:47,730 which we know corresponds to the constants part of the analysis. 12 00:00:48,860 --> 00:00:52,514 We have a data definitions part of the file that includes a world state type, 13 00:00:52,514 --> 00:00:55,936 cat, which we know corresponds to the changing information part of the 14 00:00:55,936 --> 00:01:00,716 analysis. We have a main function that calls 15 00:01:00,716 --> 00:01:03,500 Bigbang with two options, on-tick and to-draw. 16 00:01:03,500 --> 00:01:08,726 And now, if we've forgotten exactly what we have to do, I'll just search for three 17 00:01:08,726 --> 00:01:15,395 exclamation marks, and very quickly, I see exactly what I have to do. 18 00:01:15,395 --> 00:01:24,540 And if this program was larger, I could go here and say, Show Program Contour. 19 00:01:24,540 --> 00:01:27,190 And I'd see off to the right, a picture of the whole program. 20 00:01:27,190 --> 00:01:31,148 And you can barely see it there. But the places where the search has found 21 00:01:31,148 --> 00:01:34,860 three exclamation marks are highlighted. So, if I had a very big program, I could 22 00:01:34,860 --> 00:01:38,005 go over here, and quickly jump to those places like that. 23 00:01:38,005 --> 00:01:42,330 I will hide that for now because we don't have that bigger program. 24 00:01:43,550 --> 00:01:46,448 So, now what I have do, will this tells me, hey you are part way through an HTDF 25 00:01:46,448 --> 00:01:50,720 problem. Here's the problem, you've got a function 26 00:01:50,720 --> 00:01:58,440 that consumes a Cat and produces a Cat. This is an HTDF problem consuming Cat. 27 00:01:58,440 --> 00:02:01,991 It consumes Cat, produces Cat, produces the next Cat by advancing it one pixel to 28 00:02:01,991 --> 00:02:06,010 the right. If I'm a little bit unsure about what a 29 00:02:06,010 --> 00:02:11,590 cat is, I can scroll up here to the data definitions and see oh, a cat is number. 30 00:02:11,590 --> 00:02:15,980 And here's some good examples. And it's interpreted as the exposition of 31 00:02:15,980 --> 00:02:21,610 the cat in screen coordinate. Okay, while signature purpose stub, the 32 00:02:21,610 --> 00:02:26,130 next step is examples. Let's see, what's a good first example? 33 00:02:26,130 --> 00:02:33,395 We'll say check-expect advance-cat of, I don't know, 3? 34 00:02:33,395 --> 00:02:43,630 And we advance it by one pixel to the right, so that should produce 4. 35 00:02:43,630 --> 00:02:47,650 And let's see, this function is consistently, it behaves consistently 36 00:02:47,650 --> 00:02:53,570 independent of the number we gave it, so I really should only need one test. 37 00:02:53,570 --> 00:02:55,969 I'll run the test to make sure that they're well formed. 38 00:02:57,020 --> 00:03:01,710 The test is running, but failing, so it's well-formed. 39 00:03:01,710 --> 00:03:04,187 This was the stub. I'll comment it out. 40 00:03:04,187 --> 00:03:11,183 I'll say use template from Cat. I'll go up here and get the template. 41 00:03:11,183 --> 00:03:21,017 I'll copy it. I'll just label this as being the stub. 42 00:03:21,017 --> 00:03:27,523 And rename this to advance cat. And let's see. 43 00:03:27,523 --> 00:03:32,264 I've gotta fill in the dots. I advance it one pixel to the right. 44 00:03:32,264 --> 00:03:42,318 Oh, this is just plus C one. Or if you want there happens to be a 45 00:03:42,318 --> 00:03:48,134 function called add one, we could use that, but I'll just say plus c 1. 46 00:03:48,134 --> 00:03:53,138 Now, I'll run again my test passed. So, let's see, I've done that piece of 47 00:03:53,138 --> 00:03:56,717 the wish list. I go back again looking for three 48 00:03:56,717 --> 00:03:59,670 exclamation marks. Here's another function. 49 00:03:59,670 --> 00:04:04,478 It consumes Cat and produces Image. And it's supposed to render the cat image 50 00:04:04,478 --> 00:04:11,408 at an appropriate place on MTS. And now I say to myself, well what's the 51 00:04:11,408 --> 00:04:15,000 cat image. I'll look up in the constants. 52 00:04:17,070 --> 00:04:23,012 Oh yeah, there's a thing called CAT-IMG. And I'll say to myself well, what's the 53 00:04:23,012 --> 00:04:27,108 appropriate place? I'll go look at the Cat data definition. 54 00:04:27,108 --> 00:04:35,830 Cat is number; so Cat itself is a number, and I interpret that as the x position. 55 00:04:35,830 --> 00:04:40,347 So, I've got the x position. And I remember now that the y position 56 00:04:40,347 --> 00:04:43,370 doesn't change. So, I'll look in the constants for it 57 00:04:43,370 --> 00:04:45,440 too. There it is, CTR-Y. 58 00:04:47,350 --> 00:04:50,140 So, now I've got a pretty good idea about how this is going to work. 59 00:04:52,320 --> 00:04:58,340 Signature purpose stub, the next thing is example, so check, expect, render of some 60 00:04:58,340 --> 00:05:04,151 Cat, let's say 4. What's that supposed to produce? 61 00:05:04,151 --> 00:05:09,618 So, render 4 does what? Well, there is this primitive called 62 00:05:09,618 --> 00:05:14,640 place-image, and what we need to do is we ta, need to take the image of the cat 63 00:05:14,640 --> 00:05:20,310 which is CAT-IMG. We need to put it at a certain x,y 64 00:05:20,310 --> 00:05:29,741 location, which is 4 and CTR-Y. And the background that we're going to 65 00:05:29,741 --> 00:05:35,528 put it on is MTS. Now I wrote that quickly because I 66 00:05:35,528 --> 00:05:39,444 remember exactly how place-image works. If it takes you longer to write the 67 00:05:39,444 --> 00:05:43,680 expected result for our rendered function, don't worry about that all. 68 00:05:43,680 --> 00:05:47,400 You're figuring how the image functions work. 69 00:05:47,400 --> 00:05:50,510 What you're going to use in order to produce the image you want. 70 00:05:50,510 --> 00:05:56,136 Time spent here on this example translates into time saved when you do 71 00:05:56,136 --> 00:06:00,450 the actual function. So let me run this. 72 00:06:00,450 --> 00:06:06,100 And we have a failing test, which is what we'd expect. 73 00:06:06,100 --> 00:06:08,635 One thing that's nice to do with these render functions is actually look at the 74 00:06:08,635 --> 00:06:12,513 failing test. Lets see, we're getting an empty scene, 75 00:06:12,513 --> 00:06:15,240 because the stub always produces the empty scene. 76 00:06:15,240 --> 00:06:20,050 What's useful to do, and let me just make this bigger, is to look at the expected 77 00:06:20,050 --> 00:06:26,443 result, and see if our test makes sense. And that seems about right, we've got a 78 00:06:26,443 --> 00:06:30,320 cat there that's nose is a little bit off the edge. 79 00:06:30,320 --> 00:06:34,608 Remember, Place Image places the center of cat image In other words, kind of a 80 00:06:34,608 --> 00:06:39,730 center of this cat. At the specified position. 81 00:06:39,730 --> 00:06:42,890 So, it's putting this center of the cat at 4 and CTR-Y. 82 00:06:42,890 --> 00:06:46,546 The CTR-Y part is definitely right. And as I say, because the nose is a 83 00:06:46,546 --> 00:06:49,138 little bit off and I can see the beginning of that eye, I think it is 84 00:06:49,138 --> 00:06:52,074 about four. So that seems about right. 85 00:06:52,074 --> 00:06:57,242 We'll know for sure, soon. Okay, let's see. 86 00:06:57,242 --> 00:06:59,560 Let's finish up. This is the stub. 87 00:06:59,560 --> 00:07:12,342 We're going to use the template from Cat. Let's go get that template. 88 00:07:21,170 --> 00:07:23,621 [SOUND]. We'll rename this to render. 89 00:07:23,621 --> 00:07:26,763 And, let's see. We need to render the cat image in an 90 00:07:26,763 --> 00:07:33,278 appropriate place on MTS. Cat is itself the x coordinate, so 91 00:07:33,278 --> 00:07:41,050 looking at the signature, the purpose and the example, what I can see is that this 92 00:07:41,050 --> 00:07:50,388 is "place image cat image" C is itself the X coordinate. 93 00:07:50,388 --> 00:07:58,780 CTR-Y and MTS. I'll run that. 94 00:07:58,780 --> 00:08:02,485 Both my tests are passing, and now what I do, like to do is actually run the world 95 00:08:02,485 --> 00:08:06,588 program. So going back to main. 96 00:08:06,588 --> 00:08:11,170 I can call main, and the initial world-state is whatever cat I give it, 97 00:08:11,170 --> 00:08:17,408 whatever x coordinate I give it. So, it probably makes sense to maybe call 98 00:08:17,408 --> 00:08:21,848 it with zero to start. So, I run the program, and then I get 99 00:08:21,848 --> 00:08:28,404 this interaction window down here, and I go main of zero, and there's my cat. 100 00:08:28,404 --> 00:08:33,000 Walking across the screen. And now that I have a clear sense in my 101 00:08:33,000 --> 00:08:38,340 mind of what's a good default way to start this program, what I'm going to do 102 00:08:38,340 --> 00:08:47,210 is go back to the main function. And say start the world with main of 0. 103 00:08:47,210 --> 00:08:50,660 Just as a way of telling people what's a good way to start it. 104 00:08:50,660 --> 00:08:53,453 I actually could have put in that start the world with main zero at the 105 00:08:53,453 --> 00:08:56,442 beginning, because as soon as we knew what the cat data definition was, we knew 106 00:08:56,442 --> 00:09:01,395 that 0 would be a good default value. I just waited til the end here. 107 00:09:01,395 --> 00:09:04,641 So there we go. We've got a complete running world 108 00:09:04,641 --> 00:09:07,047 program. One of the things I hope you saw here is 109 00:09:07,047 --> 00:09:12,382 that by working systematically at any moment in time our work was very focused. 110 00:09:12,382 --> 00:09:18,930 Even though we did a lot, at every moment in time we were only doing one thing. 111 00:09:20,330 --> 00:09:23,880 That's what working systematically did for us. 112 00:09:23,880 --> 00:09:27,528 So, when we were working on the domain analysis, even then there were parts of 113 00:09:27,528 --> 00:09:30,260 it. We worked on the constant information, 114 00:09:30,260 --> 00:09:33,560 then we did the changing information, then we did the Bigbang options, and that 115 00:09:33,560 --> 00:09:39,900 gave us the domain analysis. As we started building the program, first 116 00:09:39,900 --> 00:09:43,484 we did the constants, then we did the data definition, for changing 117 00:09:43,484 --> 00:09:49,150 information. Then we set up the main function and the 118 00:09:49,150 --> 00:09:53,610 wish list for our big-bang option handlers. 119 00:09:53,610 --> 00:09:56,830 And then we work that wish list one function at a time. 120 00:09:58,310 --> 00:10:02,410 This is really important, as programs get big and remember, programs get big. 121 00:10:02,410 --> 00:10:05,025 Cars have millions of lines of code in them. 122 00:10:05,025 --> 00:10:09,185 The big benefit of having a systematic process is it lets you work on one thing 123 00:10:09,185 --> 00:10:13,424 at a time, and know that it's all going to work out. 124 00:10:13,424 --> 00:10:17,389 because in this case, when we were done, and we said, main of zero, bang, we got a 125 00:10:17,389 --> 00:10:22,486 running row program. And also let me repeat a point I made 126 00:10:22,486 --> 00:10:27,625 earlier about templates. Because we have a process, some parts of 127 00:10:27,625 --> 00:10:32,650 the work we do don't really necessarily end up as specific sub-parts of the final 128 00:10:32,650 --> 00:10:37,883 program. So, the domain analysis itself isn't in 129 00:10:37,883 --> 00:10:40,490 the program. It's something we wrote on a piece of 130 00:10:40,490 --> 00:10:43,616 paper. But it was part of the process that got 131 00:10:43,616 --> 00:10:46,840 us there. That's just like the template. 132 00:10:46,840 --> 00:10:50,424 The template kind of disappears into the final function definition, but the 133 00:10:50,424 --> 00:10:54,680 template is part of the process that gets us there. 134 00:10:54,680 --> 00:10:58,574 People who design, design methods, see that's a kind of meta design, that's one 135 00:10:58,574 --> 00:11:04,290 of the things they work on, is how can there be elements of the design. 136 00:11:04,290 --> 00:11:07,770 That get you there, even though they disappear in the final artifact. 137 00:11:08,940 --> 00:11:10,970 We'll talk more about that as we go along.