1 00:00:00,506 --> 00:00:09,926 [ Silence ] 2 00:00:10,426 --> 00:00:12,386 >> Alright, welcome back. 3 00:00:12,476 --> 00:00:16,246 This is CS50 and this is the start of week 1. 4 00:00:16,246 --> 00:00:19,136 So just a couple of announcements, one, 5 00:00:19,136 --> 00:00:21,976 so Problem Set Zero is due tomorrow by noon, 6 00:00:22,416 --> 00:00:25,176 realize that there are two aspects to submitting, 7 00:00:25,176 --> 00:00:28,796 one is to actually upload to the Scratch website on MIT's domain. 8 00:00:29,036 --> 00:00:31,486 But also to submit the form and follow the instructions 9 00:00:31,486 --> 00:00:34,706 of that URL, that URL is in the PDF itself, 10 00:00:34,756 --> 00:00:35,756 just don't overlook it. 11 00:00:35,756 --> 00:00:38,956 It's at the very end of the P-set that says how to submit. 12 00:00:38,956 --> 00:00:41,916 If you've not yet taken advantage of such 13 00:00:41,916 --> 00:00:45,076 or did this week and want to in the future as well. 14 00:00:45,316 --> 00:00:46,606 Do realize that for every one 15 00:00:46,606 --> 00:00:50,366 of this problem sets there will code walkthroughs led by one 16 00:00:50,366 --> 00:00:52,746 of our teaching fellows Tommy MacWilliam and these are meant 17 00:00:52,746 --> 00:00:55,396 to be opportunities again to get you started 18 00:00:55,656 --> 00:00:58,826 on the P-sets specifically the standard edition thereof, 19 00:00:58,826 --> 00:01:00,746 though if you have questions on the hacker edition, 20 00:01:01,006 --> 00:01:03,406 Tommy is certainly happy to fill those. 21 00:01:03,406 --> 00:01:05,576 These walkthroughs take place in Maxwell Dworkin which is 22 00:01:05,576 --> 00:01:07,506 up the street at 33 Oxford Street. 23 00:01:07,766 --> 00:01:09,356 It will-- it always takes time 24 00:01:09,356 --> 00:01:11,106 to get everyone's ID card activated. 25 00:01:11,106 --> 00:01:13,296 So if you ever find yourself locked out of the building, 26 00:01:13,296 --> 00:01:15,306 just call 617-bug-CS50. 27 00:01:15,366 --> 00:01:19,676 Hit the secret option 0 and that will ring multiple folks 28 00:01:19,676 --> 00:01:22,126 on the teaching staff to help you solve that problem. 29 00:01:22,436 --> 00:01:25,706 Help.cs50.net, so do take advantage 30 00:01:25,706 --> 00:01:27,126 of this resource throughout the term. 31 00:01:27,126 --> 00:01:30,516 It's an opportunity to post questions, receive answers, 32 00:01:30,516 --> 00:01:33,516 and also see whether your classmates have asked similar 33 00:01:33,516 --> 00:01:34,436 questions as well. 34 00:01:34,736 --> 00:01:37,576 Office hours too debuted two nights ago, and tonight 35 00:01:37,576 --> 00:01:40,266 and tomorrow, they'll be taking placer in law house. 36 00:01:40,556 --> 00:01:45,366 Upon arrival simply pull out your laptop and go to q.cs50.net 37 00:01:45,566 --> 00:01:48,286 and if and when you have a question that you'd like to ask 38 00:01:48,286 --> 00:01:49,136 of the TFs and CAs, 39 00:01:49,356 --> 00:01:51,696 simply follow the simple three-step process. 40 00:01:51,696 --> 00:01:53,516 What are you working on, what's your question 41 00:01:53,516 --> 00:01:55,416 and click raise your hand. 42 00:01:55,416 --> 00:01:59,076 The cs50 greeter's iPad will then list your name in the order 43 00:01:59,076 --> 00:02:01,016 in which you've raised your hand and he 44 00:02:01,016 --> 00:02:03,826 or she will then touch your name and that of a staff member 45 00:02:04,036 --> 00:02:05,306 as soon as someone's available 46 00:02:05,306 --> 00:02:07,366 and your browser will start beeping and flashing 47 00:02:07,366 --> 00:02:09,616 at you saying, it's your turn for help. 48 00:02:09,766 --> 00:02:12,016 So that is q.cs50.net. 49 00:02:12,366 --> 00:02:15,096 Realize too that we do hold office hours not only tonight 50 00:02:15,346 --> 00:02:16,446 but again tomorrow night. 51 00:02:16,446 --> 00:02:18,356 So that if you do decide to cash in one 52 00:02:18,356 --> 00:02:20,186 of your four late days per the syllabus, 53 00:02:20,396 --> 00:02:22,416 you still have a support structure in place 54 00:02:22,416 --> 00:02:25,796 to take advantage of tomorrow evening as well, 55 00:02:25,796 --> 00:02:28,676 so refer to the syllabus for the details on how 56 00:02:28,676 --> 00:02:30,576 to cash in such things. 57 00:02:30,976 --> 00:02:33,936 Lastly, resources available in general, 58 00:02:34,176 --> 00:02:36,836 so realize that retroactively after a lecture, 59 00:02:36,836 --> 00:02:40,466 we will post a canonical set of scribe notes wherein by one 60 00:02:40,466 --> 00:02:42,776 of our teaching fellows Andrew Sellergren who has been 61 00:02:42,776 --> 00:02:45,476 with the course for some time and is very good 62 00:02:45,566 --> 00:02:48,066 at documenting what happens in class as well 63 00:02:48,066 --> 00:02:49,936 as making snarky remarks in the footnotes. 64 00:02:49,936 --> 00:02:52,336 So hopefully you will enjoy reading the PDFs 65 00:02:52,336 --> 00:02:55,236 that will always be posted a few days after lecture 66 00:02:55,496 --> 00:02:58,086 on the course's website particularly around quiz time 67 00:02:58,366 --> 00:03:00,456 where they're a useful set of-- 68 00:03:00,716 --> 00:03:03,046 a useful guide to what actually happened in class. 69 00:03:03,046 --> 00:03:05,296 Which you'll also see appearing soon alongside the videos 70 00:03:05,296 --> 00:03:07,656 of lectures online is verbatim transcripts 71 00:03:07,656 --> 00:03:09,636 of every word that's uttered on stage here 72 00:03:09,826 --> 00:03:12,496 so that you can search for keywords, topics of interest. 73 00:03:12,496 --> 00:03:14,986 If you didn't quite catch something, you can read as well 74 00:03:14,986 --> 00:03:17,176 as listen to and watch it online. 75 00:03:17,696 --> 00:03:19,326 And lastly, with regard to lectures, 76 00:03:19,326 --> 00:03:20,736 in interest of preserving trees, 77 00:03:20,986 --> 00:03:22,716 we tend not to print many handouts except 78 00:03:22,716 --> 00:03:24,246 for last week during shopping period. 79 00:03:24,446 --> 00:03:27,476 But realize PDFs of the slides, PDFs of source code, 80 00:03:27,476 --> 00:03:29,986 programing code that we'll start writing this week will always be 81 00:03:29,986 --> 00:03:31,976 available online if you wanna print it yourselves, 82 00:03:32,226 --> 00:03:36,186 or bring it on a laptop to tinker with it during class. 83 00:03:37,076 --> 00:03:38,746 Any questions of any sort? 84 00:03:41,266 --> 00:03:42,036 Anything at all? 85 00:03:42,896 --> 00:03:46,426 Alright, so, you've probably if you're an upper class-- 86 00:03:46,426 --> 00:03:47,926 oh in sectioning, one last FYI, 87 00:03:48,076 --> 00:03:50,566 sectioning will commence this weekend but more 88 00:03:51,046 --> 00:03:52,936 on that this coming Friday at class. 89 00:03:53,096 --> 00:03:55,726 So indeed we have one final Friday lecture this week. 90 00:03:55,986 --> 00:03:58,676 Thereafter we are back on our Monday, Wednesday schedule. 91 00:03:59,006 --> 00:04:00,326 So [inaudible] if you're an upper class, 92 00:04:00,326 --> 00:04:02,486 I mean you've walked past this thing for like three years 93 00:04:02,486 --> 00:04:04,436 in the science center and never want to really thought-- 94 00:04:04,496 --> 00:04:06,076 stop to think about what it actually is. 95 00:04:06,076 --> 00:04:08,006 Maybe you indulged during prefrosh 96 00:04:08,006 --> 00:04:10,446 and actually read the little tourist friendly signs 97 00:04:10,486 --> 00:04:11,666 describing what this thing is. 98 00:04:11,976 --> 00:04:17,326 But this is one-- this is the first electro-mechanic computers 99 00:04:17,326 --> 00:04:21,156 named the Mark 1 from many years ago that was actually invented 100 00:04:21,156 --> 00:04:23,576 by a professor and a graduate student by the name 101 00:04:23,576 --> 00:04:25,966 of Howard Aiken here in physics and it was meant 102 00:04:25,966 --> 00:04:27,956 to be an automatic calculator. 103 00:04:27,956 --> 00:04:31,286 I thought I'd read off a few fun facts here namely one, 104 00:04:31,556 --> 00:04:33,616 it did indeed handle some nontrivial amounts 105 00:04:33,616 --> 00:04:36,296 of math namely up to 23 significant digits. 106 00:04:36,296 --> 00:04:38,226 So that in it of itself is impressive 107 00:04:38,226 --> 00:04:39,966 and that could take a human some amount of time. 108 00:04:40,306 --> 00:04:45,396 But in terms of the weight, this thing was 10,000 pounds 109 00:04:45,496 --> 00:04:47,776 and what you see in the science center is only a portion of it, 110 00:04:47,906 --> 00:04:49,706 most of it is actually been dismantled. 111 00:04:49,976 --> 00:04:51,436 And in terms of its performance, 112 00:04:51,726 --> 00:04:53,876 a multiplication took six seconds, 113 00:04:54,226 --> 00:04:57,386 a division took 15.3 seconds, and a logarithm 114 00:04:57,386 --> 00:05:00,226 or trigonometric function took over one minutes. 115 00:05:00,446 --> 00:05:03,206 So of course contrast this with your Dell laptops, 116 00:05:03,206 --> 00:05:05,316 your MacBook airs and what not which, you know, 117 00:05:05,316 --> 00:05:07,986 maybe are annoying when they're 5 pounds these days to carry 118 00:05:07,986 --> 00:05:10,386 around in your backpack and surely, mathematically, 119 00:05:10,616 --> 00:05:12,656 they can perform these calculations instantly. 120 00:05:12,946 --> 00:05:14,716 But I thought I would give you a sense 121 00:05:14,716 --> 00:05:17,856 of just how exciting technology was some years ago. 122 00:05:17,856 --> 00:05:20,966 I'll replete with not only black and white footage and that voice 123 00:05:20,966 --> 00:05:23,506 that seems to be on the present from '30s and '40s. 124 00:05:23,506 --> 00:05:26,676 This is a little look back it's about a minute long 125 00:05:26,856 --> 00:05:29,256 as to the history and the utility 126 00:05:29,506 --> 00:05:31,296 of that Mark 1 computer you've been ignoring 127 00:05:31,296 --> 00:05:31,946 for some years here. 128 00:05:32,516 --> 00:05:45,866 [ Pause ] 129 00:05:46,366 --> 00:05:47,246 >> User error. 130 00:05:47,246 --> 00:05:47,526 [ Background Music ] 131 00:05:47,526 --> 00:05:54,026 >> A triumph of mathematical 132 00:05:54,506 --> 00:05:58,276 and mechanical skill is this great new automatic calculator 133 00:05:59,156 --> 00:06:00,156 at Harvard University. 134 00:06:00,156 --> 00:06:02,356 Intricate problems in mathematics put 135 00:06:02,356 --> 00:06:03,946 through the machine in coded form 136 00:06:03,946 --> 00:06:07,176 on tape are accurately solved in a minute fraction 137 00:06:07,176 --> 00:06:09,956 of the time required for human calculations. 138 00:06:10,516 --> 00:06:20,516 [ Music ] 139 00:06:21,016 --> 00:06:21,083 [ Background Music ] 140 00:06:21,083 --> 00:06:23,856 >> Designed to expedite all forms of mathematical 141 00:06:23,856 --> 00:06:24,866 and scientific research. 142 00:06:25,306 --> 00:06:27,486 The giant mechanical brain will work 143 00:06:27,606 --> 00:06:29,956 for the United States Navy until war's end. 144 00:06:30,516 --> 00:06:38,716 [ Music ] 145 00:06:39,216 --> 00:06:40,256 >> It was a magical time. 146 00:06:40,536 --> 00:06:43,186 So do if nothing else, thank you. 147 00:06:43,186 --> 00:06:43,253 [ Applause ] 148 00:06:43,253 --> 00:06:47,556 >> Do if nothing else, perhaps take a little more interest 149 00:06:47,556 --> 00:06:48,956 when walking past that machine 150 00:06:48,956 --> 00:06:51,526 and cause there actually is a lot of compelling history there. 151 00:06:51,526 --> 00:06:54,516 And you might have heard terms like punch cards and tape 152 00:06:54,716 --> 00:06:57,566 with regard to how you actually feed input into a computer. 153 00:06:57,566 --> 00:06:59,576 Back in the day you actually toggled switches 154 00:06:59,576 --> 00:07:02,936 and you'd literally fed in cards, pieces of paper with hole 155 00:07:02,936 --> 00:07:05,206 in them that represented zeroes and ones 156 00:07:05,206 --> 00:07:06,316 and other such instructions. 157 00:07:06,496 --> 00:07:08,036 We've moved beyond that certainly now 158 00:07:08,036 --> 00:07:09,226 with our keyboards and such. 159 00:07:09,366 --> 00:07:11,736 But there's a lot of history on this campus in particular. 160 00:07:11,736 --> 00:07:14,726 So perhaps at least pause the next time you walk past. 161 00:07:15,276 --> 00:07:17,676 Last week, we introduced not only the course, 162 00:07:17,676 --> 00:07:19,816 and not only Scratch, but some of these fundamentals 163 00:07:19,816 --> 00:07:21,606 that we're gonna now start to take for granted. 164 00:07:21,606 --> 00:07:24,436 Namely how to represent information and it's not 165 00:07:24,436 --> 00:07:27,346 that we're gonna dwell on things like zeroes and ones and bits 166 00:07:27,396 --> 00:07:28,356 in such in this course. 167 00:07:28,356 --> 00:07:30,586 We're very quickly gonna start taking them for granted 168 00:07:30,846 --> 00:07:32,346 that somehow we have this ability 169 00:07:32,346 --> 00:07:33,566 to store numbers and data. 170 00:07:33,846 --> 00:07:36,906 But just to tie this week to last week, I thought I'd see 171 00:07:36,906 --> 00:07:40,406 if we could get eight brave volunteers to join me up here 172 00:07:40,406 --> 00:07:42,676 to hammer home one of last week's lessons. 173 00:07:42,676 --> 00:07:46,986 So how about you three there in the center four, five, six-oh-- 174 00:07:47,336 --> 00:07:52,476 it's over here seven, and Rob, eight, come on up. 175 00:07:52,476 --> 00:07:55,296 So you have to be comfortable as always appearing here on camera. 176 00:07:55,296 --> 00:07:58,756 We have eight pieces of paper, one for each of you here. 177 00:07:59,026 --> 00:08:01,526 And if you could each align yourselves on stage, 178 00:08:01,726 --> 00:08:03,446 consistent with the order here. 179 00:08:03,856 --> 00:08:09,046 Rob you will be let's say the-- Rob will be number 1. 180 00:08:10,096 --> 00:08:12,696 Over there on the right, if you wanna to be two's place, 181 00:08:13,606 --> 00:08:15,556 you'd like to be eight's place. 182 00:08:15,556 --> 00:08:16,836 I'll find the four's place in a moment. 183 00:08:17,886 --> 00:08:19,426 You'd like to be the four's place. 184 00:08:20,606 --> 00:08:22,396 How about the-- let's see the-- 185 00:08:22,616 --> 00:08:28,366 come on, 16's place and three more, 186 00:08:28,366 --> 00:08:32,576 32's place 64's place and 128's place. 187 00:08:32,576 --> 00:08:34,026 So if you wanna go ahead in front 188 00:08:34,026 --> 00:08:35,646 of the stage so we all can see. 189 00:08:35,886 --> 00:08:37,716 Indeed hold you number outwardly. 190 00:08:37,936 --> 00:08:40,186 What these guys each have-- and Rob, do you mind shifting 191 00:08:40,186 --> 00:08:41,146 down just a little bit? 192 00:08:43,006 --> 00:08:46,456 So we have now places 1 through 128 and recall 193 00:08:46,456 --> 00:08:49,776 when in the takeaways last week is that this system of binary 194 00:08:49,776 --> 00:08:51,676 of base 2 is not all that dissimilar 195 00:08:51,676 --> 00:08:52,956 to what we've been using for years. 196 00:08:52,956 --> 00:08:55,946 Namely base 10 or decimal where we have the ones place, 197 00:08:55,986 --> 00:08:57,846 the tens place hundreds place and so forth. 198 00:08:58,046 --> 00:08:59,406 Instead in the world of computers, 199 00:08:59,406 --> 00:09:00,666 we tend to use powers of two. 200 00:09:00,926 --> 00:09:04,256 The two really deriving from the binary nature of bits zeroes 201 00:09:04,256 --> 00:09:07,406 and ones and so our column place holders are the ones place, 202 00:09:07,616 --> 00:09:09,696 the two's place, the four's, eight, 16, 203 00:09:09,976 --> 00:09:11,076 in other words instead of multiple 204 00:09:11,076 --> 00:09:12,676 by 10 you multiplied by 2. 205 00:09:13,006 --> 00:09:15,876 But we built up from this numeric capability last week. 206 00:09:15,876 --> 00:09:17,406 To actually express numbers. 207 00:09:17,406 --> 00:09:20,446 And does anyone recall what the code or the system was 208 00:09:20,446 --> 00:09:23,386 that maps numbers to letters in computers typically? 209 00:09:23,386 --> 00:09:28,016 So it's something called ASCII, A-S-C-I-I which is just a code, 210 00:09:28,016 --> 00:09:30,826 a mapping between numbers and letters and recall 211 00:09:30,826 --> 00:09:32,886 that that mapping looked a little something like this 212 00:09:32,886 --> 00:09:35,336 and the chart itself is certainly not worth memorizing. 213 00:09:35,586 --> 00:09:40,096 But a few key values like 65 for capital letter A, 214 00:09:40,096 --> 00:09:43,126 97 for lower case A. A few of those tend 215 00:09:43,126 --> 00:09:45,456 to be useful just a kind of ingrain in your mind 216 00:09:45,456 --> 00:09:47,706 so that they can be handy when we're actually writing code. 217 00:09:47,956 --> 00:09:49,746 Now, these guys have on the backs of each 218 00:09:49,746 --> 00:09:51,846 of their sheets here, a little cheat sheet. 219 00:09:51,976 --> 00:09:55,236 So round 1, round 2, round 3, and in each of these rounds, 220 00:09:55,236 --> 00:09:56,746 their little cheat sheet advises them 221 00:09:56,746 --> 00:09:59,206 to either raise their hand or just stand there. 222 00:09:59,376 --> 00:10:00,656 If they've raised their hand, they're meant 223 00:10:00,656 --> 00:10:03,196 to be representing a one, if they're just standing there, 224 00:10:03,196 --> 00:10:04,826 they're means to be representing a zero. 225 00:10:05,056 --> 00:10:06,896 >> We've got a three-letter word to represent 226 00:10:06,896 --> 00:10:10,606 with an eight-bit bytes an ASCII character if you will. 227 00:10:10,606 --> 00:10:12,976 So let's see what three-letter word we can spell 228 00:10:12,976 --> 00:10:13,766 with these folks here. 229 00:10:13,766 --> 00:10:16,366 So if you all as our volunteers, round 1, could raise 230 00:10:16,366 --> 00:10:22,886 or not raise your hand as instructed by your cheat sheet. 231 00:10:23,146 --> 00:10:25,566 What? Number first is being represented 232 00:10:25,566 --> 00:10:27,016 by these eight volunteers? 233 00:10:27,016 --> 00:10:28,336 [ Inaudible Remarks ] 234 00:10:28,336 --> 00:10:29,436 >> Yeah, 66, right. 235 00:10:29,436 --> 00:10:31,886 'Cause we've got the 64's place plus the two's place, 236 00:10:31,886 --> 00:10:34,086 add them together get 66 and that letter then maps to? 237 00:10:34,086 --> 00:10:35,316 >> Capital B. 238 00:10:35,316 --> 00:10:36,346 >> Capital B, alright. 239 00:10:36,346 --> 00:10:37,036 So we're on our way. 240 00:10:37,036 --> 00:10:38,766 How about round two? 241 00:10:41,696 --> 00:10:44,296 What are we representing now? 242 00:10:44,796 --> 00:10:47,116 [ Inaudible Remarks ] 243 00:10:47,616 --> 00:10:50,006 >> That's definitely not universal agreement. 244 00:10:50,706 --> 00:10:51,516 How about again? 245 00:10:51,516 --> 00:10:53,096 [ Inaudible Remarks ] 246 00:10:53,096 --> 00:10:55,056 >> Okay, I heard more 79's. 247 00:10:55,216 --> 00:10:57,146 So if you just stole the person next you number, 248 00:10:57,146 --> 00:10:57,676 you are correct. 249 00:10:58,046 --> 00:11:00,686 So the number 79 maps to what letter here? 250 00:11:00,686 --> 00:11:00,866 [ Inaudible Remarks ] 251 00:11:00,866 --> 00:11:03,096 >> BO, okay. 252 00:11:03,096 --> 00:11:08,666 So now, the third and final round, round three, go. 253 00:11:09,196 --> 00:11:10,476 What number do we have here? 254 00:11:11,636 --> 00:11:12,006 >> 87. 255 00:11:12,276 --> 00:11:13,336 >> Yeah, so we've 87. 256 00:11:13,336 --> 00:11:15,646 And again you can get this by adding up the numbers in front 257 00:11:15,646 --> 00:11:18,156 of anyone with our hand raised, 87 maps to? 258 00:11:18,156 --> 00:11:20,016 [ Inaudible Remarks ] 259 00:11:20,016 --> 00:11:24,056 >> A W? So W and so we have a nice word here, BOW, 260 00:11:24,406 --> 00:11:26,366 often pronounced by last year's classes BOW 261 00:11:26,366 --> 00:11:27,726 which didn't really make for good ending. 262 00:11:27,766 --> 00:11:30,856 But if you would take your BOW, we've indeed spelled out B-O-W, 263 00:11:30,856 --> 00:11:32,796 so congrats to these guys here. 264 00:11:32,796 --> 00:11:32,863 [ Applause ] 265 00:11:32,863 --> 00:11:36,896 >> If you want to head off in the stage to the left, 266 00:11:36,896 --> 00:11:38,906 we have a little parting gift for you 267 00:11:39,036 --> 00:11:40,376 in the way of a waiver form. 268 00:11:40,376 --> 00:11:41,176 [ Laughter ] 269 00:11:41,176 --> 00:11:47,496 >> So we now have this ability to express numbers, 270 00:11:47,566 --> 00:11:50,146 to express letters and so now let's start taking this 271 00:11:50,146 --> 00:11:50,806 for granted. 272 00:11:50,806 --> 00:11:53,416 And indeed let's transition from last week's exploration 273 00:11:53,416 --> 00:11:56,736 of Scratch which was very user friendly and graphical. 274 00:11:56,956 --> 00:11:59,806 But also very limited, even if you've never programmed before, 275 00:11:59,806 --> 00:12:02,226 you probably found it or are finding it 276 00:12:02,226 --> 00:12:05,606 or will find it difficult to do certain things 277 00:12:05,656 --> 00:12:08,406 because the program isn't necessarily as expressive 278 00:12:08,406 --> 00:12:09,776 as you might like it to be. 279 00:12:09,906 --> 00:12:12,726 Or that or you're just not very ac-- familiar with it yet, 280 00:12:12,726 --> 00:12:15,526 so it just takes some time finding your way around. 281 00:12:15,526 --> 00:12:17,316 And allow me to emphasize at this point 282 00:12:17,316 --> 00:12:20,046 in the course right before study card are due, 283 00:12:20,286 --> 00:12:22,346 there's quite the spectrum of students in this course. 284 00:12:22,346 --> 00:12:24,516 And in the weeks zero through two, 285 00:12:24,686 --> 00:12:27,776 we typically run this risk historically of why they're kind 286 00:12:27,776 --> 00:12:30,246 of boring those more comfortable because they're coming 287 00:12:30,246 --> 00:12:31,226 in with more background. 288 00:12:31,466 --> 00:12:34,096 The goal of lectures in particular is to start filling 289 00:12:34,096 --> 00:12:35,586 in any holes that you might have 290 00:12:35,586 --> 00:12:37,456 from your prior experience whether formal 291 00:12:37,456 --> 00:12:38,876 in classes or just self-taught. 292 00:12:39,036 --> 00:12:41,796 And for those less comfortable, making sure that we equip you 293 00:12:42,006 --> 00:12:45,396 with the same basic mental model and understanding of some basics 294 00:12:45,606 --> 00:12:47,176 so that all of us in just a week's 295 00:12:47,176 --> 00:12:49,686 or two time can start having a conversation 296 00:12:49,686 --> 00:12:50,986 on exactly the same level. 297 00:12:51,186 --> 00:12:53,826 Now if you're finding that even Scratch is kind of stressing you 298 00:12:53,826 --> 00:12:57,376 out is taking a ridiculous amount of time, realize that all 299 00:12:57,376 --> 00:13:00,496 of these things get easier and consistently every year, 300 00:13:00,496 --> 00:13:02,896 even when I took it myself, the best strategy in general, 301 00:13:02,896 --> 00:13:04,576 and maybe it's too late for this first P-set, 302 00:13:04,876 --> 00:13:06,236 is to start these things early. 303 00:13:06,446 --> 00:13:07,866 They'll typically go out the door-- 304 00:13:08,196 --> 00:13:10,166 they'll go out the door by Friday's each week, 305 00:13:10,166 --> 00:13:11,546 which means you have the weekend if you'd 306 00:13:11,546 --> 00:13:12,906 like to sort of ease into it. 307 00:13:13,036 --> 00:13:14,626 The walkthroughs are on Sundays. 308 00:13:14,846 --> 00:13:17,626 And really the key to programming is not to start 309 00:13:17,936 --> 00:13:20,906 on say, Wednesday night and say, "I'm gonna finish this 310 00:13:20,906 --> 00:13:22,216 by morning or by midnight." 311 00:13:22,456 --> 00:13:25,186 'Cause it's just not fun and you can't think necessarily clearly 312 00:13:25,366 --> 00:13:27,546 and there's just a huge advantage to being able 313 00:13:27,546 --> 00:13:29,416 to walk away from some problem. 314 00:13:29,416 --> 00:13:30,776 I've lost count over the years 315 00:13:30,996 --> 00:13:33,866 of just how many bugs I've solved just by randomly thinking 316 00:13:33,866 --> 00:13:36,656 about them passively through out the and I'm like, "Oh, 317 00:13:36,716 --> 00:13:38,296 so that was what I was doing wrong." 318 00:13:38,296 --> 00:13:39,176 And to allow yourself 319 00:13:39,176 --> 00:13:41,076 that opportunity honestly makes things easier, 320 00:13:41,076 --> 00:13:41,906 makes things more fun 321 00:13:42,156 --> 00:13:44,876 and certainly eliminates the stress that's inevitably induced 322 00:13:45,246 --> 00:13:47,636 in any course by postponing things to last minute. 323 00:13:47,736 --> 00:13:50,796 So let me get off that soap box there and now start 324 00:13:50,796 --> 00:13:53,766 to transition us to this programming language C. 325 00:13:53,766 --> 00:13:55,596 So today we begin a more traditional 326 00:13:55,636 --> 00:13:56,756 programming language. 327 00:13:56,946 --> 00:14:00,326 It's an older language but it's the one the really sets the 328 00:14:00,326 --> 00:14:02,476 direction of a lot of today's modern languages 329 00:14:02,476 --> 00:14:04,736 which we'll then begin to visit toward the end of this semester 330 00:14:04,736 --> 00:14:07,036 in the form of PHP and JavaScript 331 00:14:07,286 --> 00:14:08,666 and some other things as well. 332 00:14:08,666 --> 00:14:11,476 And what's nice about C as we'll soon see is 333 00:14:11,476 --> 00:14:12,756 that it's relatively simple. 334 00:14:12,756 --> 00:14:14,756 And it's not gonna feel that way particularly 335 00:14:14,756 --> 00:14:17,706 to those less comfortable, most likely the first week or so. 336 00:14:17,966 --> 00:14:21,276 But relatively speaking, you can learn this language 337 00:14:21,496 --> 00:14:22,466 in just a few weeks. 338 00:14:22,466 --> 00:14:25,196 Contrast that with some human language, a spoken language, 339 00:14:25,456 --> 00:14:27,326 you typically don't master a new language 340 00:14:27,326 --> 00:14:29,386 after just a few weeks of practice. 341 00:14:29,386 --> 00:14:31,836 It can take months, it can take semesters, it can take years. 342 00:14:32,056 --> 00:14:35,236 So just realize that the scope of the languages we're 343 00:14:35,236 --> 00:14:37,796 about to learn is actually fairly narrow. 344 00:14:38,056 --> 00:14:40,256 So here's a little program that we saw last week 345 00:14:40,526 --> 00:14:43,296 when green flag clicked, say "Oh hi world" something 346 00:14:43,296 --> 00:14:46,056 to that effect, so these was a script, 347 00:14:46,366 --> 00:14:48,776 the purple piece there was a statement 348 00:14:48,826 --> 00:14:51,686 and statements again just do something, we'll just kind 349 00:14:51,686 --> 00:14:55,096 of tease you with how we're gonna start translating was very 350 00:14:55,096 --> 00:14:58,236 user friendly and very sort of graphical and playful 351 00:14:58,396 --> 00:15:00,276 into something that's a little more easy 352 00:15:00,276 --> 00:15:01,936 for a machine to understand. 353 00:15:02,306 --> 00:15:05,716 Starting TNA and beyond, if you want to write a program 354 00:15:05,926 --> 00:15:08,106 that just says something silly like "oh hi world", 355 00:15:08,276 --> 00:15:11,626 you're actually gonna type in a text editor like Notepad 356 00:15:11,626 --> 00:15:13,986 or TextEdit, whatever or more fancy programs 357 00:15:13,986 --> 00:15:17,636 that we'll introduce something like this, int, main, void, 358 00:15:17,636 --> 00:15:19,046 some curly braces printf. 359 00:15:19,046 --> 00:15:21,916 And we mentioned printf last time in "oh hi world". 360 00:15:22,096 --> 00:15:24,476 So there's some crazy syntax in here, semi colon, 361 00:15:24,476 --> 00:15:27,166 curly braces things that take a little getting used to. 362 00:15:27,166 --> 00:15:28,956 But you start to see these things recurring. 363 00:15:29,246 --> 00:15:32,146 So when you start to see code like this today and beyond, 364 00:15:32,356 --> 00:15:34,736 just realize, ah, it's really just Scratch, 365 00:15:34,736 --> 00:15:37,456 it's really just those two puzzle pieces we saw last week. 366 00:15:37,716 --> 00:15:40,146 But the syntax now is a little more cryptic, 367 00:15:40,216 --> 00:15:42,786 it's nearly as user friendly, but you get good at it, 368 00:15:43,016 --> 00:15:44,686 I dare say relatively quickly. 369 00:15:45,046 --> 00:15:48,066 So statements in general, this was a statement, oh hi world. 370 00:15:48,346 --> 00:15:50,116 This would translate more directly just 371 00:15:50,116 --> 00:15:51,776 to this one line of code. 372 00:15:51,776 --> 00:15:54,656 So when we say things like code and source code, 373 00:15:54,696 --> 00:15:56,556 programming code, any of these sorts of-- 374 00:15:56,556 --> 00:15:59,456 any of this sort of jargon we're talking about lines like that. 375 00:15:59,806 --> 00:16:01,236 And in most programming languages 376 00:16:01,236 --> 00:16:03,686 when you want the computer to do something you express it 377 00:16:03,686 --> 00:16:05,566 in the form of a line of code. 378 00:16:05,566 --> 00:16:08,116 And sometimes the line gets a little long, but in general, 379 00:16:08,176 --> 00:16:09,836 one line means do something. 380 00:16:09,836 --> 00:16:12,206 Just like one puzzle piece means, do something. 381 00:16:12,476 --> 00:16:13,256 Well what about loops? 382 00:16:13,366 --> 00:16:16,816 Last week we saw something like this, forever say "oh hi", 383 00:16:16,816 --> 00:16:18,796 it's just gonna say this, and say this, and say this, 384 00:16:18,796 --> 00:16:19,786 and say this, and say this. 385 00:16:19,786 --> 00:16:22,636 The syntax this week and beyond is gonna look a little more 386 00:16:22,636 --> 00:16:24,886 cryptic but we can express the same idea. 387 00:16:25,126 --> 00:16:26,986 We're gonna have keyword called while. 388 00:16:27,236 --> 00:16:29,246 We're gonna have kind of a stupid structure here 389 00:16:29,246 --> 00:16:30,896 where we say while true. 390 00:16:31,166 --> 00:16:33,416 And then in the curly braces, we're just gonna say printf 391 00:16:33,726 --> 00:16:36,496 which as you can kind of infer means print this to the screen. 392 00:16:36,676 --> 00:16:37,986 And what are we gonna print? 393 00:16:38,396 --> 00:16:40,506 Oh hi. Now while true, 394 00:16:40,656 --> 00:16:43,226 why is this equivalent functionally to forever? 395 00:16:43,406 --> 00:16:47,016 Well true is always true so it's just as though you're saying, 396 00:16:47,016 --> 00:16:48,106 do this again, and again, 397 00:16:48,106 --> 00:16:50,106 and again 'cause there's no variable there. 398 00:16:50,106 --> 00:16:53,646 There is just what we'll call a constant, the keywords true. 399 00:16:53,676 --> 00:16:57,176 And it's like saying while one, while one, while one, while one, 400 00:16:57,416 --> 00:17:00,496 one is always not zero which means it's always true. 401 00:17:00,576 --> 00:17:03,756 So again one and true and yes are all synonyms 402 00:17:03,826 --> 00:17:05,096 for our purposes thus far. 403 00:17:05,436 --> 00:17:07,296 Well what about loops like this? 404 00:17:07,696 --> 00:17:10,186 Repeat 10 times, say "oh, hi", 405 00:17:10,396 --> 00:17:12,106 well we need is slightly different construct 406 00:17:12,106 --> 00:17:15,346 because while true kind of implies an infinite loop. 407 00:17:15,546 --> 00:17:18,036 But there's this syntax in C called the for loop. 408 00:17:18,186 --> 00:17:19,916 And again we'll come back to this, this doesn't all have 409 00:17:19,916 --> 00:17:22,726 to sink in now but you say something like for int, 410 00:17:22,726 --> 00:17:24,076 and int's gonna means integer. 411 00:17:24,076 --> 00:17:25,956 Int I, I is gonna be a variable. 412 00:17:26,216 --> 00:17:29,386 So set I equal to zero, then do this loop 413 00:17:29,386 --> 00:17:31,036 so long as I is less than 10. 414 00:17:31,296 --> 00:17:33,076 And every time you do something, go ahead 415 00:17:33,076 --> 00:17:34,936 and increment I with plus, plus. 416 00:17:35,306 --> 00:17:37,506 So there's gonna be shorthand notation like this, plus, 417 00:17:37,576 --> 00:17:39,146 plus which just means increment. 418 00:17:39,256 --> 00:17:41,906 Add one to a variable and we had a puzzle piece quite 419 00:17:41,906 --> 00:17:43,486 like that in Scratch. 420 00:17:44,016 --> 00:17:46,366 Add one to some variable puzzle piece. 421 00:17:46,646 --> 00:17:48,856 Well variables in Scratch looked indeed like this, 422 00:17:48,856 --> 00:17:51,436 set counter to zero forever do this. 423 00:17:51,956 --> 00:17:54,076 Say counter, change counter by one. 424 00:17:54,276 --> 00:17:58,976 So this should just say 1, 2, 3, 4, 5, 6, infinitely long? 425 00:17:58,976 --> 00:18:00,946 How can we implement that in C? 426 00:18:01,256 --> 00:18:02,186 Well, we need a variable. 427 00:18:02,186 --> 00:18:05,036 So it's gonna look like this, int counter gets zero, 428 00:18:05,296 --> 00:18:09,166 or it equals zero, while true and now we kind 429 00:18:09,166 --> 00:18:11,256 of steal some syntax from previous examples. 430 00:18:11,256 --> 00:18:14,596 The printf, the plus plus, but the idea is the same. 431 00:18:14,596 --> 00:18:17,086 So again, even-- had we shown you the text in white 432 00:18:17,346 --> 00:18:19,386 in the first week it's kind of overwhelming, 433 00:18:19,386 --> 00:18:21,606 it's kinda confusing, it's not all that intuitive at all, 434 00:18:21,726 --> 00:18:23,876 but the ideas are exactly the same. 435 00:18:23,876 --> 00:18:26,256 And this is why we start with Scratch because it gets 436 00:18:26,256 --> 00:18:28,776 across the ideas without these stupid distractions 437 00:18:29,016 --> 00:18:31,396 of what's ultimately some arbitrary syntax 438 00:18:31,426 --> 00:18:34,646 that humans decided on that we all just need to acclimate to. 439 00:18:34,646 --> 00:18:36,356 But we will and quite quickly. 440 00:18:36,606 --> 00:18:40,066 So Boolean expressions, Boolean expression were what in-- 441 00:18:40,176 --> 00:18:40,946 how do you define them? 442 00:18:40,946 --> 00:18:42,136 [ Inaudible Remarks ] 443 00:18:42,136 --> 00:18:43,066 >> Yeah, so true or false? 444 00:18:43,066 --> 00:18:44,146 Something that's yes or no? 445 00:18:44,146 --> 00:18:45,216 One or zero? 446 00:18:45,216 --> 00:18:46,026 True or false? 447 00:18:46,026 --> 00:18:47,816 So they look like this in Scratch. 448 00:18:47,856 --> 00:18:49,196 Is X less than Y? 449 00:18:49,506 --> 00:18:51,766 Is X less than Y and Y less than Z? 450 00:18:51,936 --> 00:18:54,536 Well we can do the same sort of expression in C, 451 00:18:54,746 --> 00:18:57,186 we use some parenthesis, we use some angle brackets 452 00:18:57,256 --> 00:18:58,046 but it looks like this. 453 00:18:58,446 --> 00:19:02,666 X less than Y or is X less than Y ampersand ampersand, 454 00:19:02,716 --> 00:19:05,476 and ampersand ampersand happens to represent the notion 455 00:19:05,476 --> 00:19:08,726 of Boolean and, like to and in things together. 456 00:19:09,066 --> 00:19:11,496 It's distinct as we'll see from a single ampersand. 457 00:19:11,496 --> 00:19:12,786 So there are some oddities like that 458 00:19:13,046 --> 00:19:14,866 but it's the exact same idea. 459 00:19:15,366 --> 00:19:17,836 So we can do a few others with conditions. 460 00:19:17,836 --> 00:19:18,836 We had something like this. 461 00:19:19,286 --> 00:19:24,046 If X is less than Y, say X is less than Y. Else if, 462 00:19:24,266 --> 00:19:27,006 so remember we could embed one puzzle piece in another 463 00:19:27,216 --> 00:19:28,826 to have multiple forks in the road. 464 00:19:28,826 --> 00:19:31,916 Not just one or two or three, we could keep doing this. 465 00:19:31,916 --> 00:19:33,396 Well, we can do this in C as well. 466 00:19:33,666 --> 00:19:36,386 In this case, I'm essentially saying if X is less than Y, 467 00:19:36,516 --> 00:19:39,906 then say as much, else if X is greater than Y say 468 00:19:39,906 --> 00:19:42,166 as much else say they're equal, 469 00:19:42,166 --> 00:19:46,396 'cause that's the only possible alternative if it's neither less 470 00:19:46,466 --> 00:19:47,486 than nor greater than. 471 00:19:47,806 --> 00:19:48,786 So it's translates to this. 472 00:19:49,176 --> 00:19:53,166 If X less than Y, curly braces, printf, else if X greater 473 00:19:53,166 --> 00:19:55,426 than Y printf, else printf. 474 00:19:55,736 --> 00:19:58,886 And the curly braces kind of-- just like the if conditions 475 00:19:58,886 --> 00:20:00,696 and the else condition in Scratch kind 476 00:20:00,696 --> 00:20:03,826 of have these embracing yellow bars similarly 477 00:20:03,826 --> 00:20:05,976 to the curly braces, conjure up that same idea. 478 00:20:06,126 --> 00:20:09,566 >> It's enclosing one or more statements inside of them. 479 00:20:09,866 --> 00:20:11,026 Well what about arrays? 480 00:20:11,026 --> 00:20:12,266 We only talked briefly about these, 481 00:20:12,266 --> 00:20:13,966 maybe you've deployed them in your program. 482 00:20:14,326 --> 00:20:15,866 But an array is what in English? 483 00:20:15,866 --> 00:20:16,506 [ Inaudible Remarks ] 484 00:20:16,506 --> 00:20:20,276 >> Yeah, it's like a list, it's some kind of data structure, 485 00:20:20,276 --> 00:20:21,896 data storage, it's a container 486 00:20:21,896 --> 00:20:24,346 in which you can put zero or more things. 487 00:20:24,636 --> 00:20:26,986 This is in contrast with the simple variable, 488 00:20:26,986 --> 00:20:28,936 'cause with a variable, you can just put one thing. 489 00:20:29,336 --> 00:20:33,116 So if you wanted to store like in the game of Fruit Craft RPG 490 00:20:33,116 --> 00:20:34,566 which we played briefly last week. 491 00:20:34,856 --> 00:20:37,076 If you wanted to the collect the apple and the orange 492 00:20:37,076 --> 00:20:39,956 and the pear and what not, you could have an apple variable, 493 00:20:39,956 --> 00:20:41,696 an orange variable, a pear variable, 494 00:20:41,826 --> 00:20:44,266 but your program very quickly gets bloated with all 495 00:20:44,266 --> 00:20:47,076 of these darn variables, all of which are related and 496 00:20:47,076 --> 00:20:49,136 yet you need to sort of independently define them. 497 00:20:49,136 --> 00:20:52,746 An array, let's you say, I need multiple such fruits and I want 498 00:20:52,746 --> 00:20:56,296 to keep them somehow together in sort of 1 bigger variable 499 00:20:56,516 --> 00:20:59,836 but still get at individual components as we did 500 00:20:59,836 --> 00:21:01,186 with the Fruit Craft RPG. 501 00:21:01,316 --> 00:21:03,066 So how do we translate this to C? 502 00:21:03,066 --> 00:21:04,846 It takes a couple of lines this time. 503 00:21:05,196 --> 00:21:07,636 But add orange to inventory might map 504 00:21:07,796 --> 00:21:08,696 to something like this. 505 00:21:09,046 --> 00:21:12,036 A string inventory bracket 1, and we'll come 506 00:21:12,216 --> 00:21:15,056 to this next week, but string is synonymous with word 507 00:21:15,056 --> 00:21:16,236 or phrase or sentence. 508 00:21:16,236 --> 00:21:18,586 It's some number of characters that a human might type. 509 00:21:19,026 --> 00:21:20,876 Inventory is just the name of this variable 510 00:21:20,876 --> 00:21:23,416 and the bracket 1 probably denotes what? 511 00:21:23,416 --> 00:21:23,483 [ Inaudible Remarks ] 512 00:21:23,483 --> 00:21:26,276 >> Yeah, the size in this case. 513 00:21:26,276 --> 00:21:27,236 And we'll see this is kind 514 00:21:27,236 --> 00:21:29,416 of a stupid array 'cause I'm only storing one thing 515 00:21:29,416 --> 00:21:30,816 but it's meant to be a simple example. 516 00:21:31,076 --> 00:21:35,626 This just means give me an array of strings of words of size one. 517 00:21:35,726 --> 00:21:36,806 So again it's stupid in that, 518 00:21:36,986 --> 00:21:38,916 yeah I could just use a single variable for this, 519 00:21:39,156 --> 00:21:42,456 but we could just change that one to a two or 10 or a 100 520 00:21:42,646 --> 00:21:45,606 and that little character on the screen could then collect two 521 00:21:45,606 --> 00:21:47,426 or 10, 100 pieces of fruit. 522 00:21:47,726 --> 00:21:49,696 It wouldn't necessarily be bounded by one. 523 00:21:49,986 --> 00:21:53,756 And then inventory, open bracket zero equals "orange", 524 00:21:53,996 --> 00:21:55,536 we'll see next week, this is just the way 525 00:21:55,536 --> 00:21:59,016 of saying put the string, the word orange inside 526 00:21:59,016 --> 00:22:01,936 of location zero in the inventory. 527 00:22:02,166 --> 00:22:04,456 Now here we see one of the first curiosities 528 00:22:04,456 --> 00:22:07,486 of computer scientist turns out computer scientists, 529 00:22:07,486 --> 00:22:10,226 programmers more generally typically count starting 530 00:22:10,226 --> 00:22:10,926 at zero. 531 00:22:11,176 --> 00:22:14,496 Why? Well, if you think about our discussion last week a bit 532 00:22:14,496 --> 00:22:17,216 and even just now, what's the smallest number you can 533 00:22:17,216 --> 00:22:19,336 represent with the bit? 534 00:22:19,336 --> 00:22:21,536 Zero, what the smallest number you can represent with 8 bits? 535 00:22:21,686 --> 00:22:23,796 Zero, just zero, zero, zero, zero, zero, 536 00:22:23,796 --> 00:22:26,486 zero so why not just start counting at zero. 537 00:22:26,486 --> 00:22:29,106 Why waste this bit arbitrarily like humans do 538 00:22:29,106 --> 00:22:30,406 in speech counting at one. 539 00:22:30,706 --> 00:22:33,166 So in general, it's just easier and it's definitely conventional 540 00:22:33,436 --> 00:22:34,736 to start counting at zero. 541 00:22:34,736 --> 00:22:36,596 Thus was born problems at zero. 542 00:22:36,596 --> 00:22:39,456 Thus was born Week Zero last week and so forth. 543 00:22:39,456 --> 00:22:41,466 We've just preserved the same tradition. 544 00:22:41,986 --> 00:22:44,936 And so, Scratch however does not do this, 545 00:22:44,936 --> 00:22:47,536 realize they made pedagogical decision particularly 546 00:22:47,536 --> 00:22:48,516 for the target audience 547 00:22:48,736 --> 00:22:50,676 to actually start counting most things at one. 548 00:22:50,676 --> 00:22:52,166 So realize this is not universal, 549 00:22:52,166 --> 00:22:53,486 but it is quite common. 550 00:22:54,286 --> 00:22:55,816 So here's the complete program. 551 00:22:56,046 --> 00:22:59,026 So this is again, a language called C, this is a program 552 00:22:59,026 --> 00:23:01,486 that I might write using a simple text editor, 553 00:23:01,716 --> 00:23:04,826 how do I actually get to the point of writing this program? 554 00:23:05,016 --> 00:23:07,376 How do I get to the point of translating this program 555 00:23:07,376 --> 00:23:08,566 into the zeroes and ones 556 00:23:08,936 --> 00:23:11,976 that the computer actually understands? 557 00:23:12,406 --> 00:23:14,326 Well, first let's tease this apart. 558 00:23:14,326 --> 00:23:16,046 Just to get some jargon out of the way. 559 00:23:16,046 --> 00:23:18,116 Even though some of it we'll just keep taking for granted 560 00:23:18,116 --> 00:23:21,066 until it more naturally fits into the conversation. 561 00:23:21,366 --> 00:23:25,096 So this is a simple program, and in C, just like in Scratch, 562 00:23:25,136 --> 00:23:27,596 there is this when green flag clicked block, 563 00:23:27,596 --> 00:23:30,286 that kinda kick starts the whole program in C 564 00:23:30,286 --> 00:23:31,586 as in a lot of languages. 565 00:23:31,586 --> 00:23:35,716 Java, C plus plus and others main is sort of the equivalent 566 00:23:35,716 --> 00:23:37,266 of the when green flag is clicked. 567 00:23:37,686 --> 00:23:40,456 If you have a main function we'll call it, 568 00:23:40,456 --> 00:23:42,766 Scratch call them scripts we'll call them functions. 569 00:23:42,806 --> 00:23:44,896 But they're essentially the same for today's purposes. 570 00:23:45,296 --> 00:23:47,866 So long as you're programmed, the text file you're typing 571 00:23:47,866 --> 00:23:50,126 in on your computer, Mac, PC or whatever, 572 00:23:50,536 --> 00:23:54,996 contains the keyword main it's probably an executable program. 573 00:23:54,996 --> 00:23:57,206 Something you can run, something you can double click on. 574 00:23:57,386 --> 00:23:59,246 Now you can't just type main, you have to adhere 575 00:23:59,246 --> 00:24:00,666 to some annoying conventions 576 00:24:00,666 --> 00:24:04,096 and among those conventions C are first, you have to say 577 00:24:04,096 --> 00:24:06,516 that main return something. 578 00:24:06,516 --> 00:24:07,366 And we'll com back to this. 579 00:24:07,546 --> 00:24:09,466 But for now, just take for granted 580 00:24:09,466 --> 00:24:13,296 that main must be prefixed with the keyword int, I-N-T. 581 00:24:13,816 --> 00:24:15,766 Now as in aside, what is this all about? 582 00:24:16,026 --> 00:24:18,686 Well if you'd ever used your own Mac or PC or Linux Fox 583 00:24:18,686 --> 00:24:20,596 and something weird or bad has happened, 584 00:24:20,596 --> 00:24:22,946 you get some error message, it freezes. 585 00:24:22,946 --> 00:24:25,496 Odds are you've seen this little text box on the screen 586 00:24:25,786 --> 00:24:27,536 that says something like an error has occurred, 587 00:24:27,536 --> 00:24:29,356 you must reboot, or your changes were lost. 588 00:24:29,356 --> 00:24:31,626 And then it will often say something like error, 589 00:24:31,826 --> 00:24:35,756 negative one or error 253 or some random number that's 590 00:24:35,756 --> 00:24:39,126 of no value to any of us, it's probably of some value 591 00:24:39,126 --> 00:24:41,156 to the programmer who wrote that program. 592 00:24:41,396 --> 00:24:45,246 Because programs or specifically functions can return numeric 593 00:24:45,246 --> 00:24:48,686 values which are not often useful to people like us, 594 00:24:48,826 --> 00:24:51,056 but they're useful to the programmers or other parts 595 00:24:51,056 --> 00:24:52,806 of the program and generally, 596 00:24:53,186 --> 00:24:55,566 zero means everything went perfectly. 597 00:24:55,866 --> 00:24:58,046 Zero is-- it's a little counter intuitive 598 00:24:58,046 --> 00:25:02,036 in that zero we typically say is false or no but zero is perfect 599 00:25:02,106 --> 00:25:02,976 and why is it perfect? 600 00:25:03,266 --> 00:25:05,656 Well so long as you choose zero to mean success, 601 00:25:05,796 --> 00:25:08,386 this program works great, it quit without any problems, 602 00:25:08,676 --> 00:25:11,616 you have a seemingly endless supply of error codes 603 00:25:11,846 --> 00:25:14,776 that your program can return if something's indeed broken 604 00:25:14,776 --> 00:25:16,886 so when you see these error messages on the screen 605 00:25:16,886 --> 00:25:19,586 and you see some numeric value there are almost never the 606 00:25:19,586 --> 00:25:23,136 number zero, it's the number one, or two or negative one 607 00:25:23,136 --> 00:25:25,506 or negative three and that's so that Microsoft and Apple 608 00:25:25,506 --> 00:25:28,496 and others have again so many possibilities 609 00:25:28,496 --> 00:25:29,946 for error codes to return. 610 00:25:30,246 --> 00:25:32,266 Now it's not always error codes, we'll see other uses 611 00:25:32,266 --> 00:25:35,046 but for now the reason that main returns a number 'cause it's 612 00:25:35,046 --> 00:25:36,656 some way for an individual program 613 00:25:36,656 --> 00:25:39,576 to tell the OS it worked great or there is a problem. 614 00:25:39,976 --> 00:25:42,676 So what else is there void, I'm gonna wave my hand out for now 615 00:25:42,676 --> 00:25:45,896 but know that program can take input when you run them 616 00:25:45,946 --> 00:25:49,196 by typing a command or by double clicking them void just means 617 00:25:49,226 --> 00:25:50,836 um-um, this program takes no input. 618 00:25:50,836 --> 00:25:52,586 It's so simple, it just does something, 619 00:25:52,826 --> 00:25:54,376 doesn't take any input from human, 620 00:25:54,616 --> 00:25:56,896 the currently braces are what keep everything together just 621 00:25:56,896 --> 00:25:59,586 like the yellow structure of most Scratch blocks, 622 00:26:00,006 --> 00:26:03,736 printf is what we're gonna call function, so main is a function, 623 00:26:03,856 --> 00:26:06,586 printf is a function and what's nice here is 624 00:26:06,586 --> 00:26:09,606 that printf a function can call another function. 625 00:26:10,086 --> 00:26:11,056 Now what's a function? 626 00:26:11,056 --> 00:26:12,526 And you can kind of infer it from the name, 627 00:26:12,706 --> 00:26:15,396 it's like a miniature program that just does something, 628 00:26:15,396 --> 00:26:18,616 it has some functionality so printf's purpose 629 00:26:18,616 --> 00:26:21,036 in life is turns out to print something to the screen, 630 00:26:21,286 --> 00:26:22,816 main's function in life is 631 00:26:22,846 --> 00:26:26,056 to kick start a program the moment it starts running, 632 00:26:26,246 --> 00:26:29,406 main is what it's suppose to do first, now functions here, 633 00:26:29,406 --> 00:26:33,426 printf has this parenthesis and then another parenthesis inside 634 00:26:33,426 --> 00:26:35,696 of which is a quote, unquote and just to see 635 00:26:35,696 --> 00:26:37,236 if we can tie the conversations together, 636 00:26:37,236 --> 00:26:40,016 what would you call perhaps the thing inside quotes here? 637 00:26:40,016 --> 00:26:40,566 >> A string. 638 00:26:40,786 --> 00:26:41,706 >> Yes so it's a string, 639 00:26:41,936 --> 00:26:43,436 so we've used the word string before 640 00:26:43,436 --> 00:26:46,416 to just generally say a word, a phrase so indeed, 641 00:26:46,416 --> 00:26:48,606 printf can take as input, a string 642 00:26:48,866 --> 00:26:51,406 and that string is what's printed on the screen 643 00:26:51,746 --> 00:26:53,996 and that's it, all this conversations just 644 00:26:53,996 --> 00:26:55,996 to say here is how you implement hello-- 645 00:26:55,996 --> 00:26:59,376 Oh hi world on a computer but it gets us to the point now 646 00:26:59,376 --> 00:27:01,336 of being able to write and run this. 647 00:27:01,846 --> 00:27:03,516 So we need the ability now to write 648 00:27:03,516 --> 00:27:05,576 and run a program, so how we do this? 649 00:27:05,856 --> 00:27:07,336 Well those of you who are coming at this 650 00:27:07,336 --> 00:27:10,226 with prior program experience, you probably use something 651 00:27:10,226 --> 00:27:13,216 like Eclipse or NetBeans, or Emacs 652 00:27:13,216 --> 00:27:15,496 or there is seemingly infinite number of programs 653 00:27:15,736 --> 00:27:18,746 with which you can write software, write programs. 654 00:27:19,046 --> 00:27:21,996 But again I can do this on my Mac, I could open 655 00:27:21,996 --> 00:27:25,736 up a stupid little program called TextEdit, it's analogous 656 00:27:25,736 --> 00:27:27,736 on a PC it's a notepad.exe 657 00:27:27,826 --> 00:27:33,586 and I could just start typing includes standard IO int, main, 658 00:27:33,676 --> 00:27:40,736 void, printf, I'm literally just transcribing what we saw before 659 00:27:40,736 --> 00:27:44,076 Oh hi, I think I did that yesterday too, "Oh hi world". 660 00:27:44,076 --> 00:27:46,846 And again there's some syntax in here, I'm waving my hand 661 00:27:46,846 --> 00:27:49,596 at the back slash N, the semi colon but we'll come back 662 00:27:49,736 --> 00:27:52,856 to that, all I need to write software is a text editor 663 00:27:52,856 --> 00:27:53,256 like this. 664 00:27:53,256 --> 00:27:56,106 You can even use Microsoft Word so long as you don't save it 665 00:27:56,106 --> 00:27:59,566 as a dot doc but you save it like a dot txt file or something 666 00:27:59,566 --> 00:28:02,046 like that but that's not the right program to use, 667 00:28:02,176 --> 00:28:04,636 really you want a program dedicated to programming 668 00:28:04,636 --> 00:28:05,686 as we'll soon introduce. 669 00:28:06,066 --> 00:28:10,816 So unfortunately, this is not quite zeroes and ones, right, 670 00:28:10,816 --> 00:28:14,726 I could if I really wanted to create a nightmare 671 00:28:14,726 --> 00:28:18,686 for myself write "Oh hi world" by expressing myself with zeroes 672 00:28:18,686 --> 00:28:21,556 and ones saving that file with a special program 673 00:28:21,766 --> 00:28:24,016 and then double clicking its icon, or running some command, 674 00:28:24,016 --> 00:28:26,606 but this is obviously not human friendly nor is it human 675 00:28:26,606 --> 00:28:28,606 friendly to feed punch cards or tape 676 00:28:28,916 --> 00:28:31,526 into a machine instead we write programs 677 00:28:31,526 --> 00:28:34,796 in higher level languages like C that look like this, 678 00:28:35,106 --> 00:28:36,656 but what do you need especially 679 00:28:36,656 --> 00:28:38,246 if you have some prior background what do you need 680 00:28:38,246 --> 00:28:41,166 to do with this source code in order to convert it 681 00:28:41,166 --> 00:28:42,306 into those zeroes and ones? 682 00:28:42,306 --> 00:28:43,206 [ Inaudible Remark ] 683 00:28:43,206 --> 00:28:45,846 >> Yeah, so there is this other utility that's out there 684 00:28:45,846 --> 00:28:48,946 and it's called the compiler and it's not a text editor, 685 00:28:48,946 --> 00:28:50,346 it doesn't like you write programs, 686 00:28:50,636 --> 00:28:53,796 but it lets you prepare programs for running so step one 687 00:28:53,796 --> 00:28:56,666 in writing a program is just write the program in your choice 688 00:28:56,666 --> 00:28:58,246 of language, for now we use C, 689 00:28:58,506 --> 00:29:01,256 later on the semester we use PHP, and JavaScript, 690 00:29:01,416 --> 00:29:04,036 we just need to type it at our keyboard in some simple program 691 00:29:04,286 --> 00:29:05,946 but step two usually at least 692 00:29:05,946 --> 00:29:09,516 with the language called C we have to convert this into zeroes 693 00:29:09,516 --> 00:29:13,256 and ones by passing this file as input to another program 694 00:29:13,406 --> 00:29:16,556 that will essentially convert this to zeroes and ones 695 00:29:16,556 --> 00:29:18,046 and then once I have those zeroes 696 00:29:18,046 --> 00:29:22,286 and ones then I have a .exe on my desktop to borrow Windows B 697 00:29:22,286 --> 00:29:24,196 or I have a .app on my desk top 698 00:29:24,196 --> 00:29:28,496 to borrow Mac OS' speak whereby I can now run this program 699 00:29:28,746 --> 00:29:29,646 so how do we do this? 700 00:29:29,646 --> 00:29:33,116 Well, if you have a Mac you can go to the Mac store these days, 701 00:29:33,116 --> 00:29:35,516 you can download the program called Xcode for free, 702 00:29:35,776 --> 00:29:37,616 or if you have Lion, you can pay some money 703 00:29:37,616 --> 00:29:41,596 if you an older version and you can then install a compiler 704 00:29:41,836 --> 00:29:44,326 and again a program called Xcode and you can do all of this. 705 00:29:44,766 --> 00:29:47,146 Windows, there is no Xcode, that's an Apple product 706 00:29:47,146 --> 00:29:50,136 so instead on Windows, you go and buy Visual Studio 707 00:29:50,136 --> 00:29:53,196 from Microsoft or NetBeans or Eclipse or some other tool 708 00:29:53,196 --> 00:29:55,296 that there are freely available alternatives 709 00:29:55,586 --> 00:29:57,736 but that too is kind of a pain and that it doesn't come 710 00:29:57,736 --> 00:29:58,756 with the operating system. 711 00:29:58,996 --> 00:30:01,426 And in a class of this size, we have all sorts 712 00:30:01,426 --> 00:30:04,856 of people using all sorts of versions of Mac OS and Windows 713 00:30:04,856 --> 00:30:06,526 and even Linux and other OSes 714 00:30:06,786 --> 00:30:09,496 and my God it would be a nightmare all using different 715 00:30:09,496 --> 00:30:11,916 computers trying to get all of our codes to work 716 00:30:12,096 --> 00:30:14,006 on completely different hardware 717 00:30:14,266 --> 00:30:16,936 and so thus was born the CS50 appliance. 718 00:30:17,356 --> 00:30:19,316 >> And we made a mention of this last week 719 00:30:19,566 --> 00:30:22,766 but the CS50 appliance is our way of saying ah, use your Mac, 720 00:30:22,766 --> 00:30:26,356 use your PC, use your Fedora machine, your bunting machine 721 00:30:26,756 --> 00:30:29,576 and instead install inside of a window 722 00:30:29,576 --> 00:30:31,926 on your computer our operating system, 723 00:30:32,096 --> 00:30:35,386 now the CS50 appliance is going to be an operating system 724 00:30:35,556 --> 00:30:37,946 that runs inside of a window on your own computer 725 00:30:38,156 --> 00:30:40,146 that operating system happens to be called Linux 726 00:30:40,146 --> 00:30:42,096 with which you're probably familiar with by name, 727 00:30:42,096 --> 00:30:44,676 it's freely available, very popular, super popular 728 00:30:44,956 --> 00:30:47,806 in the world of websites and running servers primarily 729 00:30:47,806 --> 00:30:49,636 because it's free and high performing, 730 00:30:50,016 --> 00:30:53,446 we're using a specific flavor of Linux called Fedora, 731 00:30:53,446 --> 00:30:56,696 there's also a competing alternatives Fedora in Ubuntu 732 00:30:56,696 --> 00:30:58,806 and all these big names, we chose Fedora 733 00:30:58,806 --> 00:31:00,806 but it doesn't really matter which one you use 734 00:31:00,876 --> 00:31:02,476 but once you install this things, 735 00:31:02,706 --> 00:31:05,746 we will all have no matter what OS you brought to campus 736 00:31:05,746 --> 00:31:08,986 or what computer you brought to campus a similar environment 737 00:31:08,986 --> 00:31:11,336 that looks a little something like this and it actually looks 738 00:31:11,506 --> 00:31:14,696 like Mac OS or Windows, all of these manufacturer kind 739 00:31:14,696 --> 00:31:16,726 of put the menus in different places 740 00:31:16,726 --> 00:31:19,266 and the icons might be called something trash or recycle bin 741 00:31:19,266 --> 00:31:20,986 but at the end of the day, they're all stealing ideas 742 00:31:20,986 --> 00:31:24,156 from each other and at the end it all kind of looks the same. 743 00:31:24,156 --> 00:31:27,216 So if you look at top left here, you have a home directory, 744 00:31:27,216 --> 00:31:29,716 this is gonna be like My Computer or MacIntosh HD, 745 00:31:29,716 --> 00:31:32,416 you have file system which is everything, 746 00:31:32,416 --> 00:31:36,006 you have the trash can and the bottom left corner you'll see 747 00:31:36,006 --> 00:31:39,206 that we don't have a Start menu, we have a CS50 menu and inside 748 00:31:39,206 --> 00:31:40,786 of that is gonna be links to programs 749 00:31:40,786 --> 00:31:43,826 and so long story short, even if you're using Mac OS or Windows, 750 00:31:44,066 --> 00:31:45,576 starting this week and beyond, 751 00:31:45,616 --> 00:31:48,766 we're all gonna be running the same OS inside of a window 752 00:31:49,096 --> 00:31:51,176 on our own computer so how do you do this? 753 00:31:51,606 --> 00:31:53,546 Well, we'll provide you with instructions 754 00:31:53,546 --> 00:31:56,526 with the first problem set but no for now, 755 00:31:56,846 --> 00:31:58,606 but you'll download a free program happens 756 00:31:58,636 --> 00:32:02,116 to be called Virtual Box, this is a program that exists 757 00:32:02,116 --> 00:32:05,076 for Windows, for Mac OS, for Linux, for Solaris, 758 00:32:05,296 --> 00:32:06,806 are you unfamiliar with some of those? 759 00:32:06,806 --> 00:32:09,046 They're just other operating systems and when you run 760 00:32:09,046 --> 00:32:11,646 in on your computer, it looks a little something like this 761 00:32:11,976 --> 00:32:16,176 on the left hand side you see a list of all the virtual machines 762 00:32:16,316 --> 00:32:20,326 that you have installed on your computer and you see 763 00:32:20,516 --> 00:32:22,586 on the right the virtual specifications 764 00:32:22,856 --> 00:32:25,256 of those computers, of those virtual machines, 765 00:32:25,526 --> 00:32:26,836 so what is a virtual machine? 766 00:32:27,176 --> 00:32:31,646 It is just a computer running inside of a window being tricked 767 00:32:31,646 --> 00:32:33,616 into thinking that it's actually running 768 00:32:33,616 --> 00:32:37,036 on a physical hardware CPU with physical RAM 769 00:32:37,036 --> 00:32:41,356 and a physical hard drive but no we've gone so sophisticated 770 00:32:41,356 --> 00:32:43,786 as a society that we can actually trick Windows 771 00:32:43,786 --> 00:32:46,546 and trick Linux and even with some effort trick Mac OS 772 00:32:47,066 --> 00:32:51,026 to thinking that those operating systems are not running on-- 773 00:32:51,086 --> 00:32:54,346 that those operating systems are running on a piece of hardware, 774 00:32:54,346 --> 00:32:56,686 a computer that you bought at the store or online 775 00:32:57,116 --> 00:33:00,656 but in reality you're actually running it inside of a window 776 00:33:00,656 --> 00:33:03,796 on a computer that you bought online or in some store 777 00:33:03,966 --> 00:33:05,506 and you can really mess with your mind if you think 778 00:33:05,506 --> 00:33:07,626 about running a virtual machine in a virtual machine 779 00:33:07,626 --> 00:33:10,296 in a virtual machine but that tends not to work so well, 780 00:33:10,296 --> 00:33:11,836 so you kind of do it once, you leave it at that, 781 00:33:12,296 --> 00:33:13,576 but what's the advantage here? 782 00:33:14,126 --> 00:33:16,446 Well, just as an aside and this is really just a teaser 783 00:33:16,446 --> 00:33:19,586 for things to come, these days most of your laptops 784 00:33:19,586 --> 00:33:24,636 if relatively new have probably one CPU but multiple cores, 785 00:33:24,636 --> 00:33:27,396 you might have two cores typically, well these days 786 00:33:27,396 --> 00:33:30,706 for servers you might have 16 cores, 32 cores 787 00:33:30,706 --> 00:33:34,036 and that's essentially equivalent to having two or 32 788 00:33:34,036 --> 00:33:36,506 or more brains inside of your computer all 789 00:33:36,506 --> 00:33:39,416 of which can do something which is literally simultaneously, 790 00:33:39,416 --> 00:33:41,786 now the world is not in very good at taking advantage 791 00:33:41,786 --> 00:33:44,716 of 32 CPUs even two CPUs we humans, 792 00:33:44,716 --> 00:33:46,276 we don't check our e-mail all 793 00:33:46,276 --> 00:33:47,836 that quickly despite what you might think, 794 00:33:47,886 --> 00:33:51,366 you don't need 2 gigahertz of power times 2 to check your mail 795 00:33:51,576 --> 00:33:54,546 so even our computers have a lot of spare resources at least 796 00:33:54,546 --> 00:33:57,216 if they're 3, 4 or years old or newer 797 00:33:57,536 --> 00:34:00,326 and so what virtual machines take advantage of is all 798 00:34:00,326 --> 00:34:03,136 of the spare brain power and memory and disk space 799 00:34:03,136 --> 00:34:04,716 that we just don't typically use, 800 00:34:04,716 --> 00:34:06,646 you don't use all your computer's resources 801 00:34:06,936 --> 00:34:09,526 for Microsoft Word, instant messaging, for Facebook, 802 00:34:09,526 --> 00:34:13,116 and the like so the virtual machine is going to borrow some 803 00:34:13,116 --> 00:34:15,656 of your CPU cycles so to speak, some of you RAM, 804 00:34:16,076 --> 00:34:18,856 some of your disk space, so what you see here 805 00:34:18,856 --> 00:34:22,706 in the CS50 appliance, you will download essentially a zip file 806 00:34:22,876 --> 00:34:24,566 compressed file from the courses' website 807 00:34:24,566 --> 00:34:27,206 for the next P-set, when you follow the instructions, 808 00:34:27,206 --> 00:34:29,996 you'll see that the virtual machine you're installing has 809 00:34:30,186 --> 00:34:33,846 turns out 768 megabytes of RAM, now by modern standards, 810 00:34:33,846 --> 00:34:35,636 that's actually not all that much and we could crank it 811 00:34:35,636 --> 00:34:39,126 down even further cause most of your laptops have at least a gig 812 00:34:39,126 --> 00:34:40,996 or two or four or eight, 813 00:34:41,396 --> 00:34:44,336 these days so realize these are all configurable 814 00:34:44,336 --> 00:34:47,946 but once you then double click CS50 appliance at top left, 815 00:34:47,996 --> 00:34:51,616 voila, your Mac becomes Linux, or your PC becomes Linux 816 00:34:51,816 --> 00:34:53,376 and if you maximize the screen, 817 00:34:53,576 --> 00:34:55,986 you don't even realize what operating system you're actually 818 00:34:55,986 --> 00:34:59,606 running and so now we're all on the same page, now as an aside, 819 00:34:59,696 --> 00:35:03,756 I've also had this icon here, I just for fun installed Windows 820 00:35:03,806 --> 00:35:07,556 in advance on my Mac inside of a window so that also 821 00:35:07,556 --> 00:35:10,186 in class moving forward if we ever want to have a conversation 822 00:35:10,186 --> 00:35:12,536 about what something looks like on a Mac or PC, I don't need 823 00:35:12,776 --> 00:35:14,426 to have a two separate computers, 824 00:35:14,636 --> 00:35:16,296 I can use just the Mac by default 825 00:35:16,296 --> 00:35:18,136 but then open a Windows window 826 00:35:18,346 --> 00:35:20,506 and we can see what it would look like for the half of you 827 00:35:20,506 --> 00:35:23,286 or so that run Windows 7 or XP or Vista 828 00:35:23,286 --> 00:35:25,566 so realize that's another advantage as well 829 00:35:25,566 --> 00:35:27,956 to run multiple operating systems at once. 830 00:35:28,496 --> 00:35:30,956 So, enough about what the technology is, 831 00:35:30,956 --> 00:35:33,486 let's actually use it and do something interesting. 832 00:35:33,486 --> 00:35:36,406 So, once I double click this icon a few seconds 833 00:35:36,406 --> 00:35:38,356 or minutes later the operating system would boot 834 00:35:38,356 --> 00:35:40,876 up in a window, if I maximize it here, 835 00:35:40,916 --> 00:35:43,406 I now have my home directory like, My Computer 836 00:35:43,696 --> 00:35:46,466 and I have the trash, I have this menu at bottom left 837 00:35:46,776 --> 00:35:49,686 and I have all sorts of programs which we'll explore over time 838 00:35:49,956 --> 00:35:52,876 but the one that I care about first happens to be 839 00:35:52,876 --> 00:35:55,536 under programming and you'll see there's a few things 840 00:35:55,536 --> 00:35:58,076 under programming, one of-- is called GEdit, 841 00:35:58,606 --> 00:35:59,516 there's a few other things. 842 00:35:59,516 --> 00:36:00,906 We actually installed Scratch 843 00:36:00,936 --> 00:36:03,206 in the appliance even though you didn't need the appliance 844 00:36:03,206 --> 00:36:03,966 for the first P-set. 845 00:36:03,966 --> 00:36:05,106 We just put it there so that 846 00:36:05,286 --> 00:36:08,016 in theory you can take the whole course inside of this appliance. 847 00:36:08,376 --> 00:36:10,736 We'll see a program called Eclipse later in the semester 848 00:36:10,736 --> 00:36:13,326 which is an even fancier tool with which to write programs. 849 00:36:13,546 --> 00:36:16,846 And we'll see Terminal as well but for now I just want GEdit. 850 00:36:17,006 --> 00:36:21,006 GEdit is going to be a slightly better version of TextEdit 851 00:36:21,006 --> 00:36:25,176 on a Mac and Notepad on a PC and it's still pretty simple, 852 00:36:25,436 --> 00:36:28,126 I mean it's mostly a white screen with very few menus 853 00:36:28,366 --> 00:36:30,366 but it's in this area here in the middle 854 00:36:30,656 --> 00:36:33,206 that I'm actually gonna start writing my programs and it's 855 00:36:33,206 --> 00:36:35,596 at the bottom of my screen here where it says, 856 00:36:35,596 --> 00:36:38,566 J. Harvard at appliance and there's this blinking prompt, 857 00:36:38,886 --> 00:36:40,706 that's where I'm gonna run my programs. 858 00:36:40,966 --> 00:36:44,256 So, typically in a Linux environment you don't have 859 00:36:44,416 --> 00:36:47,186 to double click icons, you can actually type the name 860 00:36:47,186 --> 00:36:49,786 of the name of the program at a prompt, hit Enter 861 00:36:49,786 --> 00:36:52,476 and that program will run and that's where we'll start 862 00:36:52,726 --> 00:36:53,676 to keep things simple. 863 00:36:54,256 --> 00:36:55,246 So, let's give this a try. 864 00:36:55,316 --> 00:36:58,646 I'm gonna go ahead and first increase the font size here just 865 00:36:58,646 --> 00:37:00,726 so we can zoom in, but this is just 866 00:37:00,726 --> 00:37:02,476 for the sake of lecture here. 867 00:37:03,506 --> 00:37:05,766 So now we've got a bigger font and I'm just go ahead 868 00:37:05,766 --> 00:37:08,326 and save this file like I would on any operating system, 869 00:37:08,326 --> 00:37:11,106 Save As, I'm gonna go to my desktop just for kicks 870 00:37:11,106 --> 00:37:13,656 and again all the this looks a little different from Mac OS 871 00:37:13,656 --> 00:37:15,596 or Windows but it's the same thing once you get used to it, 872 00:37:15,956 --> 00:37:19,446 hello.c, so the convention when writing programs in C is 873 00:37:19,446 --> 00:37:22,176 to call them something dot C. So, 874 00:37:22,176 --> 00:37:24,046 now I'm gonna save this on my desktop. 875 00:37:24,326 --> 00:37:25,896 The file itself contains nothing, 876 00:37:25,896 --> 00:37:28,176 let's just do a sanity check, if I minimize this window 877 00:37:28,176 --> 00:37:30,936 for a moment, there it is, it's just a file, just like Mac OS 878 00:37:30,936 --> 00:37:32,066 or Windows, there's nothing 879 00:37:32,066 --> 00:37:34,506 in it 'cause it's just this big blank text file. 880 00:37:34,806 --> 00:37:37,076 So, let's start coding, let's start programming, 881 00:37:37,336 --> 00:37:41,376 include standard Io.h. We'll come back to that in a moment, 882 00:37:41,896 --> 00:37:45,356 int, main, void, I remember type-- seeing that before. 883 00:37:45,706 --> 00:37:50,526 Here's some curly braces and then the command was, printf, 884 00:37:50,906 --> 00:37:54,196 ohhiworld!N; now I've done this sometime 885 00:37:54,196 --> 00:37:58,546 so it kinda gets easier overtime but that is a transcription 886 00:37:58,796 --> 00:38:00,016 of what we had before. 887 00:38:00,246 --> 00:38:01,596 So, it's very underwhelming, 888 00:38:01,696 --> 00:38:04,036 it even though it might be syntactically be a bit ugly 889 00:38:04,216 --> 00:38:05,796 but let's actually run this thing. 890 00:38:05,966 --> 00:38:08,436 So, first I'm gonna hit Save either with Control S 891 00:38:08,436 --> 00:38:10,776 or I can do it sort of old school file Save 892 00:38:10,926 --> 00:38:12,776 and now I've saved the file on my desktop. 893 00:38:13,106 --> 00:38:16,056 But now I need to run it but not yet, 894 00:38:16,056 --> 00:38:17,466 what needs to happen before you can run it? 895 00:38:18,146 --> 00:38:18,446 >> Compile. 896 00:38:18,446 --> 00:38:19,406 >> We need to compile it. 897 00:38:19,856 --> 00:38:23,326 So, it turns out that in a Linux environment and also 898 00:38:23,326 --> 00:38:26,286 in a Mac environment and also in a Windows environment 899 00:38:26,336 --> 00:38:28,296 if you download the appropriate software but it's, 900 00:38:28,636 --> 00:38:30,836 the instructions vary by operating system so again, 901 00:38:30,836 --> 00:38:32,056 we're standardizing here. 902 00:38:32,356 --> 00:38:35,416 Notice that at the bottom of this screen, inside of GEdit, 903 00:38:35,736 --> 00:38:37,756 I have this again blinking prompt. 904 00:38:38,066 --> 00:38:40,206 So, what the appliance does when you boot it 905 00:38:40,206 --> 00:38:43,236 up is even though we could give you all unique user names, 906 00:38:43,276 --> 00:38:45,816 it's just kind of a pain to create a user name and password 907 00:38:46,096 --> 00:38:48,226 for a program that's running on your own computer 908 00:38:48,416 --> 00:38:50,586 so instead we decided that everyone will take 909 00:38:50,586 --> 00:38:52,696 on the identity by default of John Harvard 910 00:38:52,926 --> 00:38:55,626 and John Harvard's user name is jharvard and so 911 00:38:55,626 --> 00:38:57,746 when John Harvard is automatically logged in, 912 00:38:57,956 --> 00:39:01,196 you have his blinking prompt and his home directory, 913 00:39:01,196 --> 00:39:03,716 his folder of storage but when you submit, 914 00:39:03,716 --> 00:39:06,236 well that's at the point we'll ask you your actual name 915 00:39:06,326 --> 00:39:07,066 and so forth. 916 00:39:07,066 --> 00:39:10,486 But for now only you can access this account and notice 917 00:39:10,486 --> 00:39:12,896 at this prompt, I can do certain things. 918 00:39:13,016 --> 00:39:15,006 In Linux, and this is what we're seeing now, 919 00:39:15,086 --> 00:39:19,216 the operating system Linux is very often navigated by way 920 00:39:19,216 --> 00:39:21,996 of textual commands not by clicking and pointing 921 00:39:22,286 --> 00:39:24,886 and so the textual command we'll say first is LS, 922 00:39:25,516 --> 00:39:29,086 LS is short hand notation for "List" and when you hit LS 923 00:39:29,256 --> 00:39:32,546 and hit Enter, what you see is a list of all of the files 924 00:39:32,546 --> 00:39:36,676 and folders in John Harvard's default directory or folder. 925 00:39:36,976 --> 00:39:38,436 John Harvard's default directory 926 00:39:38,436 --> 00:39:41,016 or folder is conventionally called his home folder. 927 00:39:41,016 --> 00:39:43,186 So, in Windows this would be My Documents, 928 00:39:43,186 --> 00:39:44,886 in Mac OS this would be Documents, 929 00:39:44,886 --> 00:39:46,696 in Linux it's Home Directory. 930 00:39:46,976 --> 00:39:48,816 So, we're in my Home Directory and you can see 931 00:39:48,816 --> 00:39:50,266 that you have a desktop folder 932 00:39:50,446 --> 00:39:52,206 and also 'cause I was doing a bit of prep work, 933 00:39:52,206 --> 00:39:55,266 I also created a lecture folder and they're in bold just 934 00:39:55,266 --> 00:39:56,576 to kinda convey to me, the human, 935 00:39:56,576 --> 00:39:58,146 that these are directories. 936 00:39:58,636 --> 00:40:01,876 So, I wanna actually go where to compile this program? 937 00:40:03,196 --> 00:40:04,836 >> So, it's on my desktop indeed, 938 00:40:04,836 --> 00:40:07,776 it's not in this directory so instead of double clicking 939 00:40:07,776 --> 00:40:09,346 which we could do, again we're starting 940 00:40:09,346 --> 00:40:14,236 at the simplest form here, I can do CD desktop and then hit Enter 941 00:40:14,506 --> 00:40:17,146 and notice what happens, my prompt just changed. 942 00:40:17,146 --> 00:40:19,026 So, in the interest of user friendliness, 943 00:40:19,286 --> 00:40:22,186 we've pre-configured the appliance to always remind you 944 00:40:22,246 --> 00:40:25,016 where you are by just telling you parenthetically what 945 00:40:25,016 --> 00:40:26,736 directory you're in otherwise it's very quickly 946 00:40:26,736 --> 00:40:29,516 to kinda get lost or forget where you CDed into. 947 00:40:29,796 --> 00:40:31,736 So, now I'm in desktop so if I type LS, 948 00:40:32,256 --> 00:40:33,926 I'll see the file I created. 949 00:40:34,086 --> 00:40:37,156 I don't see trash, I don't see file system, 950 00:40:37,156 --> 00:40:39,176 I don't see those fake icons that are just there 951 00:40:39,176 --> 00:40:41,876 to be user friendly, I only actual files 952 00:40:41,876 --> 00:40:43,226 and folders that I put there. 953 00:40:43,556 --> 00:40:46,836 So, there's hello.c. So, now I need to compile this. 954 00:40:47,256 --> 00:40:49,546 So, how do you go about compiling a program? 955 00:40:49,866 --> 00:40:51,386 Well, there's actually a few ways 956 00:40:51,976 --> 00:40:53,766 but they all produce the same result. 957 00:40:54,386 --> 00:40:58,526 The simplest way to translate a program written in C to zeros 958 00:40:58,526 --> 00:41:00,796 and ones is with a command called GCC, 959 00:41:01,066 --> 00:41:05,006 GNU Compiler Collection, it's very, it's very popular, 960 00:41:05,006 --> 00:41:06,996 very standard, very robust program 961 00:41:07,226 --> 00:41:10,326 that simply makes you type GCC space the name 962 00:41:10,326 --> 00:41:13,036 of the program you wanna compile and that's it, 963 00:41:13,176 --> 00:41:15,106 it does all the conversion for you. 964 00:41:15,296 --> 00:41:18,656 So, if I go back to GEdit here and then let me zoom in just 965 00:41:18,656 --> 00:41:23,416 so it's nice and big and I type GCC hello.c, enter, 966 00:41:23,416 --> 00:41:27,626 the fact that nothing happened is actually wonderful in fact 967 00:41:27,736 --> 00:41:29,736 when you just sit down to write your first program 968 00:41:29,736 --> 00:41:32,146 and something does happen that means you made a mistake 969 00:41:32,206 --> 00:41:34,616 because what you'll see is a whole bunch of error messages, 970 00:41:34,616 --> 00:41:37,566 you left off a semicolon or you did something wrong 971 00:41:37,746 --> 00:41:40,496 where as Scratch isn't quite as pedantic and doesn't yell 972 00:41:40,496 --> 00:41:44,006 at you it just doesn't work, GCC will check your code and say, 973 00:41:44,206 --> 00:41:46,146 "Um-um, I can't-- I'm not converting that to zeros 974 00:41:46,146 --> 00:41:48,076 and ones, there' some mistake or mistakes." 975 00:41:48,276 --> 00:41:51,186 But no error messages is good if I now type LS, 976 00:41:51,696 --> 00:41:54,606 you'll see two things, I have just created a program 977 00:41:54,606 --> 00:41:58,016 that by convention is called, a.out this is something like, 978 00:41:58,286 --> 00:42:00,656 whatever .exc in Mac OS-- 979 00:42:00,656 --> 00:42:04,326 in Windows or whatever .app in Mac OS. 980 00:42:04,856 --> 00:42:08,766 So, a.out is just a default name for a program so to run it, 981 00:42:09,086 --> 00:42:11,136 double clicking on this is not gonna have any effect, 982 00:42:11,136 --> 00:42:14,746 this is just text, I can run, . 983 00:42:14,746 --> 00:42:19,936 /a.out. So, a.out and then just as in the side, the dot slash is 984 00:42:19,936 --> 00:42:22,946 for the following reason because this is a stupid little program 985 00:42:22,946 --> 00:42:25,896 I myself wrote and it didn't come with the operating system, 986 00:42:25,896 --> 00:42:27,996 I didn't run an installer because it's 987 00:42:27,996 --> 00:42:31,056 in my current directory, I can't just type its name 988 00:42:31,056 --> 00:42:33,206 like I typically can on a computer and it just knows 989 00:42:33,206 --> 00:42:36,726 where to look, I have to tell it where to look and so in Linux, 990 00:42:36,786 --> 00:42:39,586 in Mac Os and even in Windows if you use the right tools, 991 00:42:39,876 --> 00:42:41,626 dot is short hand notation 992 00:42:41,626 --> 00:42:44,186 for the current directory wherever I'm in, 993 00:42:44,186 --> 00:42:46,776 whatever folder I opened and as aside, 994 00:42:46,916 --> 00:42:48,976 anyone know what the parent directory is 995 00:42:48,976 --> 00:42:49,986 if you want to go backwards? 996 00:42:51,136 --> 00:42:53,716 It's gonna be dot dot, so we're gonna see conventions like this 997 00:42:53,756 --> 00:42:56,146 but for now dot just means look here 998 00:42:56,416 --> 00:43:01,186 and slash just means here slash, file name so enter, oh my God, 999 00:43:01,266 --> 00:43:05,416 I wrote my first program, like a.out contains now zeros 1000 00:43:05,416 --> 00:43:08,076 and ones and they're in a nice specific pattern that's 1001 00:43:08,076 --> 00:43:10,856 understood not only by the operating system but also 1002 00:43:10,856 --> 00:43:14,806 by the CPU, Intel Inside is relevant here because the zeros 1003 00:43:14,806 --> 00:43:18,246 and ones that GCC outputted are structured in such a way 1004 00:43:18,246 --> 00:43:20,916 that these zeros and ones mean print, these and zeros 1005 00:43:20,916 --> 00:43:23,796 and ones mean quit, these zeros and ones mean add, these zeros 1006 00:43:23,796 --> 00:43:25,576 and ones mean subtract and so forth. 1007 00:43:25,766 --> 00:43:27,356 They're our conventions that Intel 1008 00:43:27,356 --> 00:43:29,186 and others have decided on. 1009 00:43:29,756 --> 00:43:33,046 So, unfortunately this is kind of a stupid name for a program 1010 00:43:33,046 --> 00:43:35,386 so I can actually improve upon it so that 1011 00:43:35,386 --> 00:43:37,566 when I write my programs I don't have to brag to my friends, 1012 00:43:37,566 --> 00:43:39,236 "I just wrote a.out" which would be nice 1013 00:43:39,286 --> 00:43:40,976 to give it a name like, "Hello." 1014 00:43:41,276 --> 00:43:42,616 So, to compile a program 1015 00:43:42,616 --> 00:43:45,506 with a specific name we just introduce one new idea. 1016 00:43:45,976 --> 00:43:48,716 Most programs that you run by typing their names 1017 00:43:48,716 --> 00:43:52,146 at a prompt take what are called Commands Line Arguments 1018 00:43:52,206 --> 00:43:55,866 or options or switches any of these jargon is relevant 1019 00:43:56,136 --> 00:44:00,286 and here we're saying, GCC-O, the O happens 1020 00:44:00,286 --> 00:44:02,706 to represent outputs and I know that just 1021 00:44:02,706 --> 00:44:03,896 from reading the documentation. 1022 00:44:04,096 --> 00:44:09,326 So, GCC-O Hello then hello.c with spaces 1023 00:44:09,326 --> 00:44:13,166 in between are saying, compile hello.c and output it 1024 00:44:13,166 --> 00:44:15,196 to a file not called a.out, the default, 1025 00:44:15,376 --> 00:44:17,506 output it to a file called Hello. 1026 00:44:17,766 --> 00:44:20,596 So, now if I go back to my prompt and zoom in, 1027 00:44:20,866 --> 00:44:25,716 I can recompile this with GCC-O Hello then the name 1028 00:44:25,716 --> 00:44:29,136 of the source code, hello.c, Enter, nothing seems 1029 00:44:29,136 --> 00:44:32,946 to have happened, LS though, there's Hello but, um-um, 1030 00:44:33,616 --> 00:44:34,866 that doesn't work, why? 1031 00:44:34,866 --> 00:44:35,496 >> Dot slash. 1032 00:44:36,706 --> 00:44:38,516 >> Right, so dot slash is important only 1033 00:44:38,516 --> 00:44:40,746 because again this is not a standard program that I bought 1034 00:44:40,746 --> 00:44:42,866 and installed or downloaded rather I wrote it, 1035 00:44:42,866 --> 00:44:45,336 it's in my own little directory which means I need 1036 00:44:45,336 --> 00:44:46,736 to be more explicit and . 1037 00:44:47,006 --> 00:44:50,606 /hello indeed runs that program there. 1038 00:44:50,606 --> 00:44:53,206 So, you know we can actually simplify even further 1039 00:44:53,206 --> 00:44:57,096 because you'll soon see that GCC-O Hello, one, 1040 00:44:57,296 --> 00:44:58,456 just gets hard to remember. 1041 00:44:58,456 --> 00:45:00,306 Two, it just gets tedious, my God, 1042 00:45:00,306 --> 00:45:02,766 just to compile your program you have to type all these commands 1043 00:45:03,096 --> 00:45:05,626 but as an aside realize that Linux comes 1044 00:45:05,626 --> 00:45:07,756 with all these tricks, right now I'm hitting the up and the 1045 00:45:07,756 --> 00:45:09,376 down arrow on my keyboard 1046 00:45:09,506 --> 00:45:12,136 and it's remembering seemingly an infinite supply 1047 00:45:12,136 --> 00:45:14,456 of things I've typed before so there's lot's 1048 00:45:14,456 --> 00:45:15,436 of little tricks like this. 1049 00:45:15,436 --> 00:45:18,036 If you want to do what you just did, you can typically hit up 1050 00:45:18,036 --> 00:45:19,936 and hit Enter and it will just do it again 1051 00:45:20,276 --> 00:45:21,676 but I can do better than that. 1052 00:45:21,676 --> 00:45:24,926 To compile a program, I can also just make it. 1053 00:45:25,186 --> 00:45:29,956 There's another program in Linux called, Make and Make figures 1054 00:45:29,956 --> 00:45:33,706 out for you typically what types of GCC commands need 1055 00:45:33,706 --> 00:45:35,136 to be executed in order 1056 00:45:35,136 --> 00:45:37,716 to compile your programs 'cause we're doing something fairly 1057 00:45:37,716 --> 00:45:41,166 simple right now but if I actually do make hello this will 1058 00:45:41,286 --> 00:45:43,566 actually make a program called Hello and figure 1059 00:45:43,566 --> 00:45:44,936 out what to type for me. 1060 00:45:44,936 --> 00:45:48,056 So, let's do this, I'm gonna go ahead and just type make hello, 1061 00:45:48,276 --> 00:45:51,526 notice the dichotomy here, I'm not typing make hello.c, 1062 00:45:51,666 --> 00:45:54,746 I'm typing just make hello and the program's gonna assume 1063 00:45:54,746 --> 00:45:58,716 if I've said hello, it will look for a file called hello.c, 1064 00:45:58,906 --> 00:46:01,806 I hit Enter, okay well that's even more friendly, it's saying, 1065 00:46:02,016 --> 00:46:04,946 um-um, I don't even need to compile this into zeros 1066 00:46:04,946 --> 00:46:06,326 and ones 'cause you just did this. 1067 00:46:06,616 --> 00:46:07,856 Well I really wanted to do it 1068 00:46:07,856 --> 00:46:11,216 so let me remove those files I created, the command in Linux 1069 00:46:11,216 --> 00:46:13,456 to remove files is RM, remove, 1070 00:46:13,776 --> 00:46:15,016 so there's a pattern here, right? 1071 00:46:15,016 --> 00:46:17,036 Rather than ever type really a whole word, 1072 00:46:17,186 --> 00:46:19,146 the folks who invented Linux and Unix 1073 00:46:19,146 --> 00:46:20,636 and these other operating systems tried 1074 00:46:20,636 --> 00:46:23,996 to make the command as compact as possible so RM means remove. 1075 00:46:24,256 --> 00:46:27,256 So, I can remove Hello, I'm gonna also remove a.out 1076 00:46:27,296 --> 00:46:29,116 for good measure, so just putting a space 1077 00:46:29,116 --> 00:46:31,946 and separating them on the same line will then prompt me, 1078 00:46:32,026 --> 00:46:34,326 remove regular file hello, whatever that means. 1079 00:46:34,456 --> 00:46:39,056 So, Y for yes, Enter, remove regular a.out, Y for yes, Enter. 1080 00:46:39,256 --> 00:46:42,356 Now, if I do LS notice we're just back to where I've started 1081 00:46:42,586 --> 00:46:47,126 with just hello.c. So, let me go ahead now and run make hello, 1082 00:46:47,126 --> 00:46:50,476 Enter and notice even more stuff appeared on the screen 1083 00:46:50,476 --> 00:46:52,986 and this is because we've pre-configured the compliant 1084 00:46:53,396 --> 00:46:56,766 to know about all sorts of useful commands that, my God, 1085 00:46:56,826 --> 00:46:59,496 it would be a pain in the neck to type that whole line 1086 00:46:59,496 --> 00:47:02,246 of code every time you want to compile a program. 1087 00:47:02,546 --> 00:47:05,186 So, Make is gonna automate this for you and we'll tease apart 1088 00:47:05,186 --> 00:47:08,376 over time with these various flags or switches mean 1089 00:47:08,576 --> 00:47:10,316 but for now the compelling feature is 1090 00:47:10,316 --> 00:47:14,316 that we have a program called Hello, I can go ahead and run it 1091 00:47:14,506 --> 00:47:19,026 as such and now I have Oh high world executed much 1092 00:47:19,026 --> 00:47:19,696 more succinctly. 1093 00:47:19,776 --> 00:47:19,886 Yeah? 1094 00:47:20,216 --> 00:47:22,026 >> Really quickly, so programs 1095 00:47:22,026 --> 00:47:24,496 that are actually runable are in bold? 1096 00:47:24,686 --> 00:47:26,876 >> Programs that are actually runable or typically 1097 00:47:26,876 --> 00:47:29,466 in this program written in bold as our directories 1098 00:47:29,466 --> 00:47:31,316 and it's just a convention, it will differ 1099 00:47:31,316 --> 00:47:32,256 in different programs. 1100 00:47:33,066 --> 00:47:34,896 So, just to tease you with one other thing, 1101 00:47:34,896 --> 00:47:37,876 so this is again the CS50 appliance, 1102 00:47:37,876 --> 00:47:39,616 if I minimize we're back at our desktop 1103 00:47:39,616 --> 00:47:42,026 but realize this is a full fledged modern computer, 1104 00:47:42,026 --> 00:47:46,416 I can click the Firefox icon and I can go to google.com inside 1105 00:47:46,416 --> 00:47:49,246 of the appliance and actually now do everything I could 1106 00:47:49,246 --> 00:47:50,966 on the internet inside of this machine. 1107 00:47:51,236 --> 00:47:53,426 Moreover, what's nice about the appliance, irrespective 1108 00:47:53,426 --> 00:47:55,256 of the internet is that especially in the dorms 1109 00:47:55,256 --> 00:47:58,196 and houses if you have kind of flakey wireless, you don't need 1110 00:47:58,196 --> 00:47:59,886 to be consonantly connected to the internet, 1111 00:47:59,886 --> 00:48:02,326 the appliance boots independent of the internet 1112 00:48:02,326 --> 00:48:05,916 so you can now work anywhere, anytime including over breaks 1113 00:48:06,226 --> 00:48:09,596 if that's at all appealing, without actually needing 1114 00:48:09,596 --> 00:48:12,306 to be perpetually on line and it's all irrespective 1115 00:48:12,306 --> 00:48:15,436 of what your actual operating system is. 1116 00:48:16,506 --> 00:48:17,136 Any question? 1117 00:48:17,536 --> 00:48:21,036 All right so that's a lot to absorb all 1118 00:48:21,036 --> 00:48:22,596 at once why don't we-- oh, yes? 1119 00:48:22,596 --> 00:48:26,196 >> Whys is that Make Hello not Make Hello.c? 1120 00:48:26,836 --> 00:48:29,506 >> Good question, why is it Make Hello and not Make Hello.c? 1121 00:48:29,616 --> 00:48:32,906 Honestly, just because, like the programs authors decided 1122 00:48:33,236 --> 00:48:35,796 that if you type Make Hello, it will assume 1123 00:48:35,926 --> 00:48:39,606 that you want hello.c and it will look for those files. 1124 00:48:39,976 --> 00:48:42,956 We'll also see that it's more motivating in future weeks 1125 00:48:42,996 --> 00:48:46,536 because you can, you can create nicknames so that 1126 00:48:46,536 --> 00:48:47,996 when you say make something? 1127 00:48:48,186 --> 00:48:50,956 Something can be defined by you as a doing sequence of steps 1128 00:48:50,956 --> 00:48:52,016 that you wanted to automate. 1129 00:48:52,846 --> 00:48:56,756 >> What would happen if you had another file 1130 00:48:57,126 --> 00:49:01,016 like that tells hello [inaudible]? 1131 00:49:01,216 --> 00:49:03,586 >> If you had another program called Hello but you want it 1132 00:49:03,586 --> 00:49:05,406 to compile hello.c, would it get confused? 1133 00:49:05,676 --> 00:49:07,406 No, 'cause that's what we did a moment ago, 1134 00:49:07,406 --> 00:49:09,076 I still had the Hello program 1135 00:49:09,326 --> 00:49:11,116 but so I typed Make Hello and it said, um-um. 1136 00:49:11,116 --> 00:49:14,146 It's up to date because it had already been compiled 1137 00:49:14,146 --> 00:49:16,176 and it realized that it would create the same output. 1138 00:49:16,806 --> 00:49:18,456 So, in short no, yeah? 1139 00:49:19,076 --> 00:49:23,566 >> If you are to type Make Hello.c would it have done the 1140 00:49:23,566 --> 00:49:23,856 same thing? 1141 00:49:23,906 --> 00:49:24,466 >> Good question, 1142 00:49:24,466 --> 00:49:28,116 so and actually I can emphasize this quite explicitly, 1143 00:49:28,316 --> 00:49:29,476 when in doubt honestly? 1144 00:49:29,506 --> 00:49:31,416 When you have a computer, when you have a keyboard in front 1145 00:49:31,416 --> 00:49:35,146 of you, try it, the worst you can do is screw everything up 1146 00:49:35,216 --> 00:49:36,406 and download a new appliance. 1147 00:49:37,226 --> 00:49:40,486 So, Make Hello.c, enter, nothing to be done 1148 00:49:40,486 --> 00:49:43,586 for hello.c. Well the last time I saw that it related to this, 1149 00:49:43,586 --> 00:49:44,656 so let me get rid of this. 1150 00:49:45,096 --> 00:49:48,986 So, now let me do Make Hello.c, it doesn't want to compile it 1151 00:49:48,986 --> 00:49:51,886 because what it's now looking for, it's now realizing 1152 00:49:51,886 --> 00:49:54,006 that this is not a file that needs to be compiled 1153 00:49:54,526 --> 00:49:58,576 so in short, error message though it's not explicitly clear 1154 00:49:58,576 --> 00:50:00,896 that this is a problem, yeah? 1155 00:50:01,396 --> 00:50:03,986 [ Inaudible Remark ] 1156 00:50:04,486 --> 00:50:05,246 >> Really good question. 1157 00:50:05,246 --> 00:50:09,526 Do the files we create like hello.c exist in a file 1158 00:50:09,526 --> 00:50:10,416 on your own hard drive? 1159 00:50:10,416 --> 00:50:12,756 Actually no, if you poke around your own Mac 1160 00:50:12,756 --> 00:50:16,326 or Windows hard drive, you will just see one huge file, 1161 00:50:16,326 --> 00:50:19,536 it's called a VMDK file, Virtual something or other 1162 00:50:19,856 --> 00:50:22,326 and that means that all of the files you create inside 1163 00:50:22,326 --> 00:50:24,556 of the appliance are actually hidden inside 1164 00:50:24,556 --> 00:50:28,256 of one Gigabyte file and that gigabyte is chopped 1165 00:50:28,256 --> 00:50:30,836 up into the individual files but you'll see overtime 1166 00:50:30,836 --> 00:50:33,986 in the specifications for P-sets and in the online documentation. 1167 00:50:34,256 --> 00:50:36,136 You can interact with the appliance, 1168 00:50:36,216 --> 00:50:38,446 with your own computer, that home directory 1169 00:50:38,446 --> 00:50:40,016 that John Harvard's files are stored in? 1170 00:50:40,156 --> 00:50:42,666 You can actually mount that on your own computer, 1171 00:50:42,886 --> 00:50:45,756 you can connect to it via various internet programs 1172 00:50:45,976 --> 00:50:47,986 so in short you will see that we can interact with this 1173 00:50:47,986 --> 00:50:49,356 in all sorts of ways especially 1174 00:50:49,356 --> 00:50:52,206 if you find this environment just unappealing or confining, 1175 00:50:52,426 --> 00:50:55,566 you won't risk-- strictly need to use it. 1176 00:50:55,566 --> 00:50:58,086 There's many ways to make use of the appliance still. 1177 00:50:58,086 --> 00:51:00,616 So, this is a lot to absorb all at once, 1178 00:51:00,616 --> 00:51:03,756 let's take a two minute break to kind of give you a, 1179 00:51:03,936 --> 00:51:05,596 give you a moments rest bit and we'll resume 1180 00:51:05,826 --> 00:51:06,826 with something more fancy. 1181 00:51:07,516 --> 00:51:11,516 [ Inaudible Discussions ] 1182 00:51:12,016 --> 00:51:12,083 [ Background Noise ] 1183 00:51:12,083 --> 00:51:18,446 >> All right, so we are back, 1184 00:51:18,446 --> 00:51:22,636 if at any point honestly you are confused, have questions, 1185 00:51:22,686 --> 00:51:25,316 please catch my eye, raise your hand or I'll certainly stick 1186 00:51:25,316 --> 00:51:28,436 around afterward, more over moving forward in addition 1187 00:51:28,486 --> 00:51:31,066 to PDFs, of slides and source code being available online, 1188 00:51:31,296 --> 00:51:33,166 realize that all of the programs we write 1189 00:51:33,166 --> 00:51:35,936 in class will either be posted in advance on the website 1190 00:51:35,936 --> 00:51:38,066 or if we create it on the fly, we'll post it right 1191 00:51:38,236 --> 00:51:40,886 after lecture so that you can download it to your own Mac 1192 00:51:40,886 --> 00:51:43,646 or PC inside of the appliance and so even 1193 00:51:43,646 --> 00:51:46,236 if you want during class if you find it helpful to play along 1194 00:51:46,236 --> 00:51:47,706 and actually type what I'm typing, 1195 00:51:47,926 --> 00:51:49,556 get the same error messages I'm getting, 1196 00:51:49,556 --> 00:51:51,676 realize you can run the appliance in Sanders here 1197 00:51:51,946 --> 00:51:54,296 on your own machine, the wireless is pretty spotty 1198 00:51:54,296 --> 00:51:56,216 in Sanders right now, they're working on bolstering 1199 00:51:56,216 --> 00:51:57,556 that for later in the semester 1200 00:51:57,706 --> 00:51:59,796 but if you do download the appliance back home 1201 00:51:59,796 --> 00:52:02,166 or somewhere else on campus then next time bring to class, 1202 00:52:02,636 --> 00:52:05,456 realize it's a good way to more actively engage rather 1203 00:52:05,456 --> 00:52:07,696 than just sitting there listening passively. 1204 00:52:07,996 --> 00:52:10,096 So, a couple of more building blocks 1205 00:52:10,096 --> 00:52:11,856 with which we can do more interesting things. 1206 00:52:11,856 --> 00:52:15,836 So again a function is a chunk of code, a chunk of lines 1207 00:52:15,836 --> 00:52:19,276 of programming code that do something and what do they do? 1208 00:52:19,276 --> 00:52:22,116 It's really up to you, main is entirely up to you 1209 00:52:22,116 --> 00:52:24,426 because what you put in main just like in Scratch, 1210 00:52:24,426 --> 00:52:27,536 what you put in one green flag clicked is what happens 1211 00:52:27,536 --> 00:52:28,886 when you start running the program. 1212 00:52:29,106 --> 00:52:32,976 Now, printf, you can control its behavior only to some extent, 1213 00:52:33,316 --> 00:52:36,226 printf is another function whose purpose in life again is 1214 00:52:36,226 --> 00:52:37,776 to print something to the screen 1215 00:52:37,956 --> 00:52:40,696 but the F actually denotes something, it means formatted 1216 00:52:40,966 --> 00:52:43,576 because even though we've been using it for very simple things, 1217 00:52:43,576 --> 00:52:47,866 Oh hi world, you can actually print numbers and characters 1218 00:52:47,866 --> 00:52:50,326 and whole words and sentences and other things. 1219 00:52:50,556 --> 00:52:53,526 You can format numbers as integers, as real numbers 1220 00:52:53,526 --> 00:52:56,156 with decimal points and all sorts of other conventions. 1221 00:52:56,416 --> 00:52:59,136 And so printf takes what are called arguments, 1222 00:52:59,396 --> 00:53:01,416 so when we saw printf before, 1223 00:53:01,626 --> 00:53:04,936 recall that we saw these parenthesis inside of my program 1224 00:53:05,146 --> 00:53:07,976 and any time you see parenthesis after the name of a function, 1225 00:53:08,276 --> 00:53:10,466 that's your way of modifying its behavior. 1226 00:53:10,666 --> 00:53:13,036 If you think back on Scratch with all those puzzle pieces, 1227 00:53:13,266 --> 00:53:15,826 sometimes you could type a number into a little white box 1228 00:53:15,826 --> 00:53:18,796 or you could drag a puzzle piece on top of another and which sort 1229 00:53:18,796 --> 00:53:20,636 of magically grow and then contain it? 1230 00:53:20,986 --> 00:53:23,676 Well, same idea here, you can modify the behavior 1231 00:53:23,676 --> 00:53:27,596 of puzzle pieces and functions by passing them arguments. 1232 00:53:27,596 --> 00:53:29,976 It's just in C, you have to be a little more deliberate 1233 00:53:29,976 --> 00:53:32,766 with the keyboard and so anytime you see parenthesis right 1234 00:53:32,766 --> 00:53:34,556 outside, right after a function name 1235 00:53:34,836 --> 00:53:37,756 that means it's taking input generally called arguments 1236 00:53:37,856 --> 00:53:41,146 or parameters but these are for our purposes now synonymous. 1237 00:53:41,226 --> 00:53:43,086 It takes input, why is that useful? 1238 00:53:43,086 --> 00:53:44,746 Well, it'll be a pretty stupid function 1239 00:53:44,746 --> 00:53:47,976 if all printf could do is print, oh hi world, 1240 00:53:48,166 --> 00:53:50,706 it be nice if you could print anything and indeed it can, 1241 00:53:50,976 --> 00:53:53,656 I just have to choose as the programmer what to pass 1242 00:53:53,866 --> 00:53:55,716 in between double quotes. 1243 00:53:55,916 --> 00:53:58,456 Now, any guesses as to what this backslash N 1244 00:53:58,556 --> 00:53:59,936 at the end has been representing? 1245 00:53:59,936 --> 00:54:00,126 >> New line. 1246 00:54:01,266 --> 00:54:04,136 >> So, new line, so computers again are pretty dumb, 1247 00:54:04,136 --> 00:54:07,216 they only do what you tell them to do and if you don't tell them 1248 00:54:07,216 --> 00:54:08,766 to move the blinking cursor 1249 00:54:08,936 --> 00:54:11,076 to the next line, it's not gonna do it. 1250 00:54:11,246 --> 00:54:15,076 So, if I actually omit this, save my file and let me zoom in 1251 00:54:15,316 --> 00:54:20,226 and then re-run Make Hello, Enter and then run Hello, 1252 00:54:20,226 --> 00:54:22,636 notice what happens at the prompt, it's kind of a mess. 1253 00:54:22,906 --> 00:54:23,866 It says, oh hi world! 1254 00:54:23,946 --> 00:54:27,046 But then the prompt reappears and that's 1255 00:54:27,046 --> 00:54:28,596 because I've omitted the backslash N. 1256 00:54:28,596 --> 00:54:31,326 And we'll see there's other ones, there's backslash R 1257 00:54:31,326 --> 00:54:35,786 and backslash T but backslash N is by far the most commonly used 1258 00:54:35,786 --> 00:54:37,796 in C and in other languages. 1259 00:54:38,206 --> 00:54:40,456 So, what else do we want know about? 1260 00:54:40,456 --> 00:54:43,486 Well, in C, you have the notion of variables which we'll see 1261 00:54:43,486 --> 00:54:46,116 in a moment but these variables are specific type, 1262 00:54:46,346 --> 00:54:49,546 there's a char which represents a single character, 1263 00:54:49,586 --> 00:54:51,426 the act of touching one key on the keyboard, 1264 00:54:51,776 --> 00:54:54,056 there's an int which is an integer. 1265 00:54:54,346 --> 00:54:57,106 Now, an integer as an aside is 32 bits 1266 00:54:57,106 --> 00:54:59,876 and we only had eight bits on stage before, 1267 00:55:00,156 --> 00:55:02,056 with eight bits you can represent how many 1268 00:55:02,056 --> 00:55:02,876 different values? 1269 00:55:05,046 --> 00:55:07,326 It's actually 256, how do you get there? 1270 00:55:07,326 --> 00:55:09,556 Well, if you have eight bits here and each of these bits 1271 00:55:09,556 --> 00:55:11,506 or volunteers can be a zero or a one? 1272 00:55:11,746 --> 00:55:14,336 There's two opportunities here, two opportunities here, 1273 00:55:14,336 --> 00:55:16,236 two opportunities here, zero, one, zero, one, 1274 00:55:16,386 --> 00:55:18,246 so if you multiply all those together, two times two, 1275 00:55:18,246 --> 00:55:20,386 times two, times two, that's the same thing as two 1276 00:55:20,386 --> 00:55:22,536 to the eight and that's 256. 1277 00:55:22,776 --> 00:55:26,556 So, now if you have a 32-bit number not an 8-bit number 1278 00:55:26,556 --> 00:55:28,826 but a 32-bit number, that's two to the 32 1279 00:55:28,826 --> 00:55:30,116 which is roughly, anyone know? 1280 00:55:31,416 --> 00:55:33,116 It's actually 4 billion, give or take. 1281 00:55:33,116 --> 00:55:34,916 So, two to the 32 is four billion, 1282 00:55:35,086 --> 00:55:36,096 now what's the takeaway? 1283 00:55:36,096 --> 00:55:39,936 That's means an integer in a computer can store the number 1284 00:55:39,936 --> 00:55:42,696 from zero to four billion or more typically 1285 00:55:42,936 --> 00:55:46,596 from negative two billion to positive 2 billion, give or take 1286 00:55:46,916 --> 00:55:49,396 but notice the key takeaway here, it's finite, 1287 00:55:49,876 --> 00:55:52,036 there's only a fixed number of bits 1288 00:55:52,066 --> 00:55:54,656 which means there's only a fixed range of values which means 1289 00:55:54,656 --> 00:55:57,746 at some point if you try counting up to two billion 1290 00:55:57,936 --> 00:55:59,996 to billion one, two billion two, two billion three, 1291 00:56:00,286 --> 00:56:01,696 eventually what's gonna happen? 1292 00:56:02,956 --> 00:56:05,146 You're actually gonna end up being back at zero 1293 00:56:05,146 --> 00:56:07,536 or a negative number, some crazy thing's gonna happen 1294 00:56:07,536 --> 00:56:09,836 where you're counting is actually gonna wrap around 1295 00:56:09,886 --> 00:56:12,016 and bad things then happen as a result. 1296 00:56:12,196 --> 00:56:13,786 So, how do you get even bigger numbers? 1297 00:56:14,056 --> 00:56:17,406 Well, you use bigger integers, you use 64-bit integers. 1298 00:56:17,406 --> 00:56:20,926 So, if you've heard that your PC or Mac these days is 64-bit 1299 00:56:20,926 --> 00:56:22,926 that means that all of the numbers 1300 00:56:22,926 --> 00:56:25,616 with which it performs math are now 64-bits 1301 00:56:25,616 --> 00:56:27,986 and that generally is good for speed and performance 1302 00:56:28,306 --> 00:56:31,416 but it also means older programs that are 10 years old 1303 00:56:31,416 --> 00:56:34,116 or more often will break on that computer. 1304 00:56:34,166 --> 00:56:37,956 So, we are using as an aside of 32 bit virtual machine 1305 00:56:37,956 --> 00:56:40,286 so that it works on anyone's laptop even 1306 00:56:40,286 --> 00:56:42,836 if it's several years old but there's other data types. 1307 00:56:42,836 --> 00:56:48,506 Chars are 8 bits, ints are 32 bits, float is also 32 bits 1308 00:56:48,836 --> 00:56:50,756 but it's what's called a floating point value, 1309 00:56:50,756 --> 00:56:53,536 a real number where the decimal point can actually, 1310 00:56:53,586 --> 00:56:56,016 it's a real number with a decimal point. 1311 00:56:56,386 --> 00:56:59,166 Now, there too, if you think about it, real numbers, 1312 00:56:59,166 --> 00:57:01,746 we were taught in grade school can be infinitely precise, 1313 00:57:01,876 --> 00:57:05,886 you can have 0.333333 and you put a little line over it 1314 00:57:05,886 --> 00:57:07,796 which means infinitely many threes, 1315 00:57:08,086 --> 00:57:09,446 that's really darn precise. 1316 00:57:09,446 --> 00:57:12,686 It means one third exactly, computer, you're gonna have 1317 00:57:12,686 --> 00:57:14,536 to stop writing down threes at some point, 1318 00:57:14,536 --> 00:57:16,986 write just conceptually even if bits are completely new 1319 00:57:16,986 --> 00:57:19,996 to you it stands to reason that if you only have a fixed number 1320 00:57:19,996 --> 00:57:23,116 of them whether it's eight or 32 or 64, 1321 00:57:23,236 --> 00:57:25,586 at some point you're gonna have to decide, 1322 00:57:25,586 --> 00:57:31,786 "Do I want to represent 0.3333333 or 0.4444444? 1323 00:57:31,786 --> 00:57:34,056 In other words, there's only a finite number of permutations 1324 00:57:34,056 --> 00:57:36,696 of zeros and ones, only a finite number of permutations 1325 00:57:36,696 --> 00:57:39,336 of these eight humans on stage so you've got to pick 1326 00:57:39,586 --> 00:57:41,746 which of those real numbers do you want to represent? 1327 00:57:41,966 --> 00:57:44,626 So, in short computers are in inherently imprecise 1328 00:57:44,626 --> 00:57:47,476 and this can actually create some significant problems. 1329 00:57:47,726 --> 00:57:51,166 If you think back some 10 plus years, the Y2K problem 1330 00:57:51,166 --> 00:57:52,446 which is one of the more recent times 1331 00:57:52,446 --> 00:57:54,006 when everyone thought the world was gonna end? 1332 00:57:54,296 --> 00:57:56,416 Well, what was the Y2K problem, what was the source 1333 00:57:56,416 --> 00:58:00,306 of that issue and all the drama, yeah? 1334 00:58:00,306 --> 00:58:00,856 [ Inaudible Remark ] 1335 00:58:00,856 --> 00:58:04,696 >> Yeah, exactly so in a lot of computer programs, 1336 00:58:04,696 --> 00:58:09,696 the date accidentally went from 1999 back to 1900 1337 00:58:09,966 --> 00:58:12,496 because the programmers made the judgment call, 1338 00:58:12,496 --> 00:58:15,006 good or bad at the time, so you know, "ugh, there's-- 1339 00:58:15,006 --> 00:58:17,166 no one's gonna be using my software in the year 2000, 1340 00:58:17,166 --> 00:58:18,636 I'm just gonna use two digits 1341 00:58:18,886 --> 00:58:22,246 to represent the two number after the 19." 1342 00:58:22,546 --> 00:58:24,866 The problem though is if you're only using two digits 1343 00:58:24,866 --> 00:58:29,296 and you get to 1998, so the 98, 99 what do you get 1344 00:58:29,296 --> 00:58:30,536 when you wanna hit 2000? 1345 00:58:30,536 --> 00:58:31,786 You need the number 100 1346 00:58:31,886 --> 00:58:33,946 but if you're only using three decimal digits, 1347 00:58:33,946 --> 00:58:34,996 you're kinda out of luck. 1348 00:58:34,996 --> 00:58:36,656 So, what did these programs do in Y2K? 1349 00:58:37,266 --> 00:58:39,456 They wrapped around back to 00 so all 1350 00:58:39,456 --> 00:58:41,826 of a sudden people's dates were 1900 1351 00:58:41,826 --> 00:58:44,346 and just bad things happened, the world did not in fact end 1352 00:58:44,346 --> 00:58:45,546 and in fact a lot people made a lot 1353 00:58:45,546 --> 00:58:46,966 of money fixing all these problems 1354 00:58:47,366 --> 00:58:51,036 but using fairly arcane languages at that time 1355 00:58:51,336 --> 00:58:53,566 but the point was that that was just a design decision, 1356 00:58:53,566 --> 00:58:57,106 arguably a foolish design decision but if you can imagine 1357 00:58:57,106 --> 00:59:01,496 from the 10,000 pound computer, memory was expensive back 1358 00:59:01,496 --> 00:59:04,206 in the day and it wasn't all that large so you wanted to cut 1359 00:59:04,206 --> 00:59:06,826 as many corners as possible but it turns 1360 00:59:06,826 --> 00:59:10,156 out that people were still using software that's 20 years old, 1361 00:59:10,156 --> 00:59:12,516 30 years old and I know that on campus there's computers 1362 00:59:12,516 --> 00:59:14,306 that are still running software that old 1363 00:59:14,306 --> 00:59:16,856 and they have just been patched together over time. 1364 00:59:17,096 --> 00:59:20,406 So, what can you do when you need a bigger number than32 bits 1365 00:59:20,406 --> 00:59:22,056 for an int or a float? 1366 00:59:22,336 --> 00:59:26,756 Well, there's-- ironically you'd think it would be a long number 1367 00:59:26,756 --> 00:59:29,586 but it's in fact not, it's usually a long, long, 1368 00:59:29,586 --> 00:59:32,366 so we'll see that you call the data type, the type of number, 1369 00:59:32,366 --> 00:59:35,456 it's a long, long and that typically gives you 64 bits. 1370 00:59:35,686 --> 00:59:37,116 If you want even more precision 1371 00:59:37,116 --> 00:59:40,546 for that decimal point you can instead use a double 1372 00:59:40,546 --> 00:59:44,536 which is a 64 bit real number, it's still finite so you cannot 1373 00:59:44,536 --> 00:59:47,626 in fact represent all possible values despite what we learned 1374 00:59:47,626 --> 00:59:48,206 in grade school. 1375 00:59:48,206 --> 00:59:51,066 You have to choose a finite range of them so again 1376 00:59:51,066 --> 00:59:54,526 that means that computers are inherently imprecise. 1377 00:59:54,926 --> 00:59:56,426 So, how do we actually use these things? 1378 00:59:56,426 --> 00:59:58,636 Well, we've only seen printf as a function thus far 1379 00:59:58,896 --> 01:00:02,826 and so we've actually seen way more functions or puzzle pieces 1380 01:00:02,826 --> 01:00:04,976 in Scratch so let's round out a few more. 1381 01:00:05,326 --> 01:00:07,756 >> So, in C, it's actually not all that easy 1382 01:00:07,786 --> 01:00:09,886 to get user inputs, you kinda have to jump 1383 01:00:09,886 --> 01:00:12,476 through some hoops just to see what the user typed and not 1384 01:00:12,476 --> 01:00:13,986 to mention convert what they've typed 1385 01:00:13,986 --> 01:00:16,656 from ASCII characters to actually numbers. 1386 01:00:16,786 --> 01:00:20,286 For instance, when you type in 1.5 on a keyboard, 1387 01:00:20,506 --> 01:00:23,156 that's not a number, that's actually the character one, 1388 01:00:23,406 --> 01:00:25,816 the character period, the character five, 1389 01:00:26,126 --> 01:00:29,506 so you have to kind of convert that to a floating point value 1390 01:00:29,506 --> 01:00:32,266 and how we do that we'll ignore for now but it's suffice 1391 01:00:32,266 --> 01:00:35,006 to say some work has to go in to getting user input 1392 01:00:35,306 --> 01:00:38,496 so we have what's called the CS50 library which is a suite 1393 01:00:38,496 --> 01:00:42,006 of functions that you can use in your programs and indeed we do 1394 01:00:42,006 --> 01:00:44,716 for the first several weeks and the names imply what they do. 1395 01:00:44,996 --> 01:00:46,326 If you want to get a character 1396 01:00:46,326 --> 01:00:49,636 from the user we're gonna call Get char or get double 1397 01:00:49,636 --> 01:00:51,636 or get float or get in to get a long-long 1398 01:00:51,636 --> 01:00:53,956 or get string depending on the data type 1399 01:00:54,196 --> 01:00:56,586 and that's gonna allow me to write programs like this. 1400 01:00:56,586 --> 01:01:00,016 Let me go back to my code here, let me go ahead 1401 01:01:00,016 --> 01:01:01,816 and say not just, oh hi world now 1402 01:01:02,146 --> 01:01:03,386 but let me declare a variable 1403 01:01:03,386 --> 01:01:06,166 and then see you declare a variable like this, string S 1404 01:01:06,366 --> 01:01:10,096 and I'm gonna go ahead and say, "Get a string from the user 1405 01:01:10,546 --> 01:01:13,586 and get string just like printf is a function but what's neat 1406 01:01:13,586 --> 01:01:16,446 about get string is that it doesn't just do something 1407 01:01:16,446 --> 01:01:18,516 and leave it at that, it does something 1408 01:01:18,616 --> 01:01:20,906 and then it hands it back to me, all right? 1409 01:01:20,906 --> 01:01:24,576 So, it's as though this is doing my bidding, get string, 1410 01:01:24,606 --> 01:01:27,086 it's gonna deal with all the complexity of keyboard input, 1411 01:01:27,086 --> 01:01:29,376 it's gonna get that string of characters from the user 1412 01:01:29,566 --> 01:01:31,156 and it's gonna hand it to me in such a way 1413 01:01:31,156 --> 01:01:33,886 that I can store it inside a variable just like Scratch 1414 01:01:34,116 --> 01:01:35,926 and I'm gonna call S and the type 1415 01:01:35,926 --> 01:01:38,026 of that variable is what we'll call string. 1416 01:01:38,366 --> 01:01:40,686 If you're familiar with Java, it's not capital S, 1417 01:01:40,686 --> 01:01:43,846 it's lower case S string but it's just a variable and that's 1418 01:01:43,936 --> 01:01:45,436 because of the CS50 library. 1419 01:01:45,736 --> 01:01:48,066 Now again, I said that we don't always have to type, 1420 01:01:48,176 --> 01:01:52,646 oh hi world, we can pass in an argument whose value changes. 1421 01:01:52,846 --> 01:01:55,906 So, it turns out in C there is these place holders and if I do, 1422 01:01:55,906 --> 01:02:00,006 not just a hard coded string of characters, I do percent S, 1423 01:02:00,116 --> 01:02:01,736 that means put a string here. 1424 01:02:01,736 --> 01:02:03,666 Well, what string do you want to put there? 1425 01:02:04,046 --> 01:02:06,776 Well, let me go ahead and just move outside of the quotes, 1426 01:02:07,196 --> 01:02:10,476 comma S and what we'll see here is 1427 01:02:10,476 --> 01:02:14,126 that some functions can actually take not just zero, not just one 1428 01:02:14,406 --> 01:02:18,076 but even two arguments and the convention in programming is 1429 01:02:18,076 --> 01:02:20,296 to separate those arguments, those inputs, 1430 01:02:20,396 --> 01:02:22,906 those parameters again all synonyms by a comma, 1431 01:02:23,186 --> 01:02:25,646 a comma right, a comma separated list of arguments. 1432 01:02:25,936 --> 01:02:27,246 So, now what's gonna happen? 1433 01:02:27,496 --> 01:02:29,826 Well, whatever I typed is gonna get printed 1434 01:02:29,956 --> 01:02:33,816 and that is gonna be-- because the S gets substituted 1435 01:02:33,816 --> 01:02:34,846 for the percent S here. 1436 01:02:35,076 --> 01:02:36,406 But I need to do one more thing 1437 01:02:36,406 --> 01:02:39,486 and I can finally now explain what was going on here. 1438 01:02:39,806 --> 01:02:44,276 This includes standard io.h is what's called a header file. 1439 01:02:44,586 --> 01:02:47,406 It turns out that I can't just start using things like printf 1440 01:02:47,406 --> 01:02:49,166 and just assume that they'll work, 1441 01:02:49,256 --> 01:02:50,656 I have to tell the compiler, 1442 01:02:50,656 --> 01:02:54,356 "I wanna use a function called printf, written by someone, 1443 01:02:54,356 --> 01:02:58,766 some 20, 30 years ago and that function is declared, it's-- 1444 01:02:58,806 --> 01:03:03,636 it's written in a file called, standard io.h, now I don't know 1445 01:03:03,636 --> 01:03:05,526 where that is, it's somewhere on the hard drive 1446 01:03:05,796 --> 01:03:07,926 but the compiler know where to look by default. 1447 01:03:08,186 --> 01:03:10,576 So, that's why I was able to use printf, 1448 01:03:10,706 --> 01:03:12,746 if I had omitted the highlighted first line, 1449 01:03:12,956 --> 01:03:14,246 I would have gotten some kind of error. 1450 01:03:14,606 --> 01:03:16,146 Same thing with the CS50 library, 1451 01:03:16,146 --> 01:03:19,716 if I wanna use the CS50 library, if I wanna use the CS50 library, 1452 01:03:19,826 --> 01:03:22,066 I have to say, use CS50.h and I don't know where this file is, 1453 01:03:22,066 --> 01:03:23,966 it's somewhere in the appliance's hard drive, 1454 01:03:24,226 --> 01:03:27,146 GCC will find it for me but now I have the ability 1455 01:03:27,146 --> 01:03:29,756 to use the Get String function as well. 1456 01:03:29,886 --> 01:03:31,236 So, you didn't have to do this in Scratch, 1457 01:03:31,236 --> 01:03:34,026 Scratch makes everything available to you at once 1458 01:03:34,426 --> 01:03:36,696 but now I have to be a little more deliberate and that's okay, 1459 01:03:36,696 --> 01:03:39,596 it keeps my programs even more explicit as to what's going on. 1460 01:03:39,936 --> 01:03:42,236 So, let me zoom in again, let me type, 1461 01:03:42,306 --> 01:03:43,446 what do I type to compile this? 1462 01:03:43,526 --> 01:03:46,656 Yes, it's kinda, it's kinda there, 1463 01:03:46,656 --> 01:03:49,596 you can always cheat there, so make Hello, Enter, okay, 1464 01:03:49,596 --> 01:03:54,316 no errors so that's good, run Hello, nothing seems 1465 01:03:54,316 --> 01:03:56,116 to be happening but I do have a blinking prompt 1466 01:03:56,116 --> 01:03:59,026 so I can say something like, David, Enter and ump kind 1467 01:03:59,026 --> 01:04:01,736 of a bug, I don't really like that output. 1468 01:04:02,756 --> 01:04:04,726 What can I do to fix? 1469 01:04:04,726 --> 01:04:05,196 [ Inaudible Remark ] 1470 01:04:05,196 --> 01:04:06,456 >> Yeah, backslash N there 1471 01:04:06,456 --> 01:04:08,116 and I can make this a little more user friendly, 1472 01:04:08,116 --> 01:04:12,136 I can say something like, printf, name please, colon, 1473 01:04:12,136 --> 01:04:14,256 space and again a semicolon turns 1474 01:04:14,256 --> 01:04:16,956 out this is just a convention at the end of most any statement 1475 01:04:16,956 --> 01:04:19,086 in C you have to put a semicolon. 1476 01:04:19,306 --> 01:04:20,696 So, now I have a three line program. 1477 01:04:20,696 --> 01:04:27,526 Let me go back here and re-run it, David, didn't fix. 1478 01:04:27,666 --> 01:04:28,886 Okay, good, right, so just 1479 01:04:28,886 --> 01:04:31,476 because I changed the source code doesn't mean the program 1480 01:04:31,476 --> 01:04:32,936 itself is gonna start working 1481 01:04:33,146 --> 01:04:36,216 so let me actually re-run Make Hello, that looks good, 1482 01:04:36,216 --> 01:04:39,716 now let me re-run Hello, enter name please, 1483 01:04:39,716 --> 01:04:42,356 that looks prettier, enter, David. 1484 01:04:42,356 --> 01:04:44,926 Now, you can imagine making even more sentence structure there 1485 01:04:45,046 --> 01:04:47,936 but now we have the ability to get input and get output. 1486 01:04:48,446 --> 01:04:50,986 Let's take a look at just one other format string, 1487 01:04:51,046 --> 01:04:55,276 it turns out I'm gonna go ahead and get a float from the user 1488 01:04:55,276 --> 01:04:58,486 and I'm gonna have to change this now to floatf and the name 1489 01:04:58,486 --> 01:05:00,626 of my variable, I'm just keeping it simple, F for float, 1490 01:05:00,626 --> 01:05:01,626 I only have one variable, 1491 01:05:01,626 --> 01:05:02,946 there's no confusing with something else. 1492 01:05:02,946 --> 01:05:04,506 I'm gonna put percent F here 1493 01:05:04,506 --> 01:05:08,366 and F here 'cause now I wanna say just give me a number please 1494 01:05:08,956 --> 01:05:10,646 so let's go ahead and run this program. 1495 01:05:10,646 --> 01:05:13,086 So let's go ahead and run make Hello. 1496 01:05:13,626 --> 01:05:14,476 Run Hello. 1497 01:05:14,476 --> 01:05:15,476 Number please? 1498 01:05:15,476 --> 01:05:17,086 Let's do 1.5, enter. 1499 01:05:17,086 --> 01:05:19,246 Interesting, that looks pretty precise. 1500 01:05:19,246 --> 01:05:20,376 That's a lot of zeros. 1501 01:05:20,866 --> 01:05:24,536 But it turns out we can reveal to ourselves at least 1502 01:05:24,536 --> 01:05:26,376 for educational purposes here, 1503 01:05:26,586 --> 01:05:29,026 I actually wanna see what number is really being stored there. 1504 01:05:29,026 --> 01:05:32,876 Let me go ahead and show 10 digits after the decimal point 1505 01:05:33,166 --> 01:05:34,606 so I'm changing the format string. 1506 01:05:34,606 --> 01:05:37,346 Instead of just percent F, I'm doing percent 0.1F 1507 01:05:37,966 --> 01:05:39,986 but that's just so I'll see more on the screen. 1508 01:05:39,986 --> 01:05:41,786 So let me rerun this, make hello. 1509 01:05:42,026 --> 01:05:45,186 Let me rerun hello, enter 1.5, interesting. 1510 01:05:45,186 --> 01:05:47,666 So that's actually a pretty good number. 1511 01:05:47,666 --> 01:05:49,226 Let's try something else. 1512 01:05:49,226 --> 01:05:53,026 Let's run it with 0.1, Enter. 1513 01:05:53,926 --> 01:05:55,456 That is not what I typed. 1514 01:05:56,506 --> 01:05:57,946 So why did this just happen? 1515 01:05:57,986 --> 01:06:02,836 I'm pretty sure I did not type 0.10000015. 1516 01:06:02,836 --> 01:06:05,026 Why does the computer think that's what I indeed stored 1517 01:06:05,026 --> 01:06:05,636 in a variable? 1518 01:06:05,846 --> 01:06:06,056 Yeah? 1519 01:06:06,256 --> 01:06:09,876 >> It doesn't have that precision 1520 01:06:11,046 --> 01:06:14,106 to represent 0.1 exactly. 1521 01:06:14,106 --> 01:06:14,646 >> Exactly. 1522 01:06:14,646 --> 01:06:15,186 [ Inaudible Remark ] 1523 01:06:15,186 --> 01:06:17,036 >> It doesn't have enough precision 1524 01:06:17,036 --> 01:06:18,666 to represent that number 0.1. 1525 01:06:18,666 --> 01:06:20,376 Simple as that number is exactly 1526 01:06:20,536 --> 01:06:22,826 because if you only have 32 bits you got to pick and choose 1527 01:06:22,826 --> 01:06:25,946 which numbers you will be allowed to represent so rounded 1528 01:06:25,946 --> 01:06:27,516 to the closest possible much. 1529 01:06:27,726 --> 01:06:30,576 Now this might seem like a silly bug or issue 1530 01:06:30,816 --> 01:06:33,666 but they can actually lead to very serious problems. 1531 01:06:33,666 --> 01:06:35,726 And indeed to help visualize this, 1532 01:06:36,026 --> 01:06:39,546 there's some very famous examples in history of programs 1533 01:06:39,686 --> 01:06:43,276 and real world things that have been implemented in software 1534 01:06:43,276 --> 01:06:45,216 and that's software is flawed because humans 1535 01:06:45,216 --> 01:06:49,656 like us literally have made mistakes as simple or as trivial 1536 01:06:49,656 --> 01:06:51,296 or as innocent as that. 1537 01:06:51,686 --> 01:06:54,036 And you'll see from this video some of the things both 1538 01:06:54,326 --> 01:06:57,306 with real consequences or not that tend to happen. 1539 01:06:57,636 --> 01:06:58,816 So let me go ahead and pull this up. 1540 01:06:58,816 --> 01:07:02,106 It's just a few minutes long and let's see what indeed can happen 1541 01:07:02,236 --> 01:07:05,656 and just how severe, how important in understanding 1542 01:07:05,696 --> 01:07:07,356 of these low levels primitives are 1543 01:07:07,576 --> 01:07:09,986 when you're actually making decisions to buy, to write, 1544 01:07:10,246 --> 01:07:11,966 or to actually use software like this. 1545 01:07:11,966 --> 01:07:12,033 [ Background Music ] 1546 01:07:12,033 --> 01:07:17,876 >> We now return to Engineering Disasters on Modern Marvels. 1547 01:07:17,876 --> 01:07:19,646 Computers, we've all come 1548 01:07:19,646 --> 01:07:22,266 to accept the often frustrating problems that go with them, 1549 01:07:22,406 --> 01:07:27,056 bugs, viruses, and software glitches are small prices 1550 01:07:27,056 --> 01:07:28,246 to pay for the convenience. 1551 01:07:29,086 --> 01:07:31,256 But in high-tech and high-speed military 1552 01:07:31,256 --> 01:07:32,906 and space program applications, 1553 01:07:33,606 --> 01:07:37,086 the smallest problem can be magnified into disaster. 1554 01:07:38,766 --> 01:07:42,146 On June 4th, 1996 scientists prepare 1555 01:07:42,146 --> 01:07:44,406 to launch an unmanned Ariane 5 rocket, 1556 01:07:44,866 --> 01:07:47,206 it was carrying scientific satellites designed 1557 01:07:47,206 --> 01:07:50,556 to establish precisely how the Earth's magnetic field interacts 1558 01:07:50,556 --> 01:07:51,516 with solar winds. 1559 01:07:53,376 --> 01:07:55,806 The rocket was built for the European Space Agency 1560 01:07:55,806 --> 01:08:00,386 and lifted off from its facility on the coast of French Guiana. 1561 01:08:00,386 --> 01:08:02,526 >> At about 37 seconds into the flight, 1562 01:08:03,026 --> 01:08:04,906 they first noticed something was going wrong, 1563 01:08:04,986 --> 01:08:07,746 that the nozzles were swiveling in a way they really shouldn't. 1564 01:08:08,216 --> 01:08:09,716 Around 40 seconds into the flight, 1565 01:08:10,096 --> 01:08:12,156 clearly the vehicle was in trouble. 1566 01:08:12,506 --> 01:08:14,266 And that's when they made the decision to destroy it. 1567 01:08:14,776 --> 01:08:17,246 The range safety officer, with tremendous guts, 1568 01:08:17,686 --> 01:08:19,796 pressed the button, blew up the rocket before it, 1569 01:08:19,796 --> 01:08:22,666 it could become a hazard to public safety. 1570 01:08:22,666 --> 01:08:26,326 >> This was the maiden voyage of the Ariane 5, 1571 01:08:26,746 --> 01:08:30,346 and its destruction took place because of a flaw embedded 1572 01:08:30,346 --> 01:08:31,356 in the rocket's software. 1573 01:08:31,356 --> 01:08:34,086 >> The problem on the Ariane was that there was a number 1574 01:08:34,086 --> 01:08:36,996 that required 64 bits to express and they wanted 1575 01:08:36,996 --> 01:08:39,056 to convert it to a 16-bit number. 1576 01:08:39,536 --> 01:08:42,786 They assumed that the number was never gonna be very big. 1577 01:08:42,786 --> 01:08:45,646 That most of those digits in the 64-bit number were zeros. 1578 01:08:46,926 --> 01:08:47,546 They were wrong. 1579 01:08:47,796 --> 01:08:52,386 >> The inability of one software program to accept the kind 1580 01:08:52,386 --> 01:09:03,476 of number generated by another was at the root of the failure. 1581 01:09:03,656 --> 01:09:09,266 Software development had become a very costly part 1582 01:09:09,356 --> 01:09:11,076 of new technology. 1583 01:09:11,076 --> 01:09:15,066 The Ariane 4 rocket had been very successful so much 1584 01:09:15,066 --> 01:09:21,026 of the software created for it was also used in the Ariane 5. 1585 01:09:21,026 --> 01:09:27,456 >> The basic problem was that the Ariane 5 was faster, 1586 01:09:27,456 --> 01:09:33,266 accelerated faster, and, and the software hadn't accounted 1587 01:09:33,266 --> 01:09:33,936 for that. 1588 01:09:34,016 --> 01:09:37,486 >> The destruction of the rocket was a huge financial disaster, 1589 01:09:37,726 --> 01:09:39,626 all due to a minute software error. 1590 01:09:39,626 --> 01:09:43,356 But this wasn't the first time data conversion problems had 1591 01:09:43,476 --> 01:09:45,846 plagued modern rocket technology. 1592 01:09:45,846 --> 01:09:50,556 >> In 1991, with the start of the first Gulf War, 1593 01:09:51,266 --> 01:09:53,636 the Patriot missile experienced a similar kind 1594 01:09:53,666 --> 01:09:55,346 of number-conversion problem, and as a result, 28 people, 1595 01:09:55,376 --> 01:09:56,336 28 American soldiers were killed 1596 01:09:56,366 --> 01:09:57,716 and about a hundred others wounded when the Patriot 1597 01:09:57,746 --> 01:09:58,496 which was supposed to protect 1598 01:09:58,526 --> 01:09:59,726 against incoming Scuds failed to fire a missile. 1599 01:09:59,756 --> 01:10:01,316 >> When Iraq invaded Kuwait and America launched Desert Storm 1600 01:10:01,346 --> 01:10:03,146 in early 1991, Patriot missile batteries were deployed 1601 01:10:03,176 --> 01:10:04,136 to protect Saudi Arabia and Israel 1602 01:10:04,166 --> 01:10:04,976 from Iraqi Scud missile attacks. 1603 01:10:05,166 --> 01:10:07,826 >> The Patriot is a U.S. medium-range surface-to-air 1604 01:10:07,826 --> 01:10:10,796 system manufactured by the Raytheon Company. 1605 01:10:11,696 --> 01:10:15,666 >> The size of the Patriot interceptor itself is, 1606 01:10:15,666 --> 01:10:19,636 it's about roughly 20-feet long, and it weighs about 2,000 pounds 1607 01:10:19,636 --> 01:10:22,856 and it carries a warhead of about, 1608 01:10:23,326 --> 01:10:25,236 I think it's roughly 150 pounds. 1609 01:10:25,236 --> 01:10:28,896 And the warhead itself is high explosive 1610 01:10:29,606 --> 01:10:33,246 which has fragments around them. 1611 01:10:33,246 --> 01:10:37,106 The casing of the warhead is designed to act like buckshot. 1612 01:10:37,546 --> 01:10:39,496 >> The missiles are carried four per container, 1613 01:10:39,906 --> 01:10:42,066 and are transported by a semitrailer. 1614 01:10:42,956 --> 01:10:47,416 >> The Patriot antimissile system goes back 1615 01:10:47,416 --> 01:10:50,156 at least 20 years now. 1616 01:10:50,866 --> 01:10:54,246 It was originally designed as an air defense missile 1617 01:10:54,356 --> 01:10:56,146 to shoot down enemy airplanes. 1618 01:10:56,636 --> 01:11:01,916 In the First Gulf War, when that war came along, the army wanted 1619 01:11:01,916 --> 01:11:05,106 to use it to shoot down Scuds, not airplanes. 1620 01:11:05,706 --> 01:11:08,996 The Iraqi Air Force was not so much of a problem 1621 01:11:09,536 --> 01:11:11,796 but the army was worried about Scuds. 1622 01:11:12,586 --> 01:11:15,386 And so they tried to upgrade the Patriot. 1623 01:11:15,856 --> 01:11:19,066 >> Intercepting an enemy missile traveling at Mach 5 was going 1624 01:11:19,066 --> 01:11:19,956 to be challenging enough. 1625 01:11:20,326 --> 01:11:23,416 But when the Patriot was rushed into service, 1626 01:11:24,346 --> 01:11:26,976 the army was not aware of an Iraqi modification. 1627 01:11:26,976 --> 01:11:33,296 That made their Scuds nearly impossible to hit. 1628 01:11:33,826 --> 01:11:34,806 >> What happened is the Scuds 1629 01:11:35,096 --> 01:11:36,636 that were coming in were unstable. 1630 01:11:36,636 --> 01:11:37,546 They were wobbling. 1631 01:11:37,766 --> 01:11:39,826 The reason for this was the Iraqis, 1632 01:11:40,086 --> 01:11:43,086 in order to get 600 kilometers 1633 01:11:43,086 --> 01:11:46,456 out of the 300-kilometer range missile took weight 1634 01:11:46,456 --> 01:11:48,586 out of the front warhead, they made the warhead lighter. 1635 01:11:49,326 --> 01:11:53,936 So now the Patriot is trying to come at the Scud and most 1636 01:11:53,936 --> 01:11:56,196 of the time, the overwhelming majority of the time, 1637 01:11:56,196 --> 01:11:57,996 it will just fly by the Scud. 1638 01:11:57,996 --> 01:12:01,606 >> Once the Patriot system operators realize the Patriot 1639 01:12:01,606 --> 01:12:02,356 missed its target. 1640 01:12:02,826 --> 01:12:04,856 They detonated the Patriot's warhead 1641 01:12:04,856 --> 01:12:08,066 to avoid possible casualties if it was allowed 1642 01:12:08,066 --> 01:12:09,026 to fall to the ground. 1643 01:12:10,416 --> 01:12:13,486 >> That was what most people saw, as big fire balls 1644 01:12:13,486 --> 01:12:19,916 in the sky, and misunderstood as intercepts of Scud warheads. 1645 01:12:19,916 --> 01:12:19,983 [ Background Noise ] 1646 01:12:19,983 --> 01:12:22,566 >> Although in the night sky, Patriots appeared 1647 01:12:22,566 --> 01:12:24,886 to be successfully destroying Scuds, 1648 01:12:25,176 --> 01:12:28,276 at Dhahran there could be no mistake about its performance. 1649 01:12:28,436 --> 01:12:31,396 There, the Patriot's radar system lost track 1650 01:12:31,396 --> 01:12:36,396 of an incoming Scud, and never launched due to a software flaw. 1651 01:12:40,046 --> 01:12:41,806 It was the Israeli's who first discovered 1652 01:12:41,806 --> 01:12:44,436 that the longer the system was on, 1653 01:12:44,746 --> 01:12:48,626 the greater the time discrepancy became due to a clock embedded 1654 01:12:48,626 --> 01:12:49,576 in the system's computer. 1655 01:12:50,646 --> 01:12:53,806 >> About two weeks before the tragedy in Dhahran, 1656 01:12:54,166 --> 01:12:56,296 the Israeli's reported to the Defense Department 1657 01:12:56,696 --> 01:12:58,516 that the system was losing time. 1658 01:12:58,516 --> 01:13:00,366 After about eight hours of running, they noticed 1659 01:13:00,366 --> 01:13:03,276 that the system is becoming noticeably less accurate. 1660 01:13:03,676 --> 01:13:06,266 The Defense Department responded by telling all 1661 01:13:06,266 --> 01:13:07,426 of the Patriot batteries 1662 01:13:07,846 --> 01:13:10,146 to not leave the systems on for a long time. 1663 01:13:10,786 --> 01:13:12,246 They never said what a long time was. 1664 01:13:12,936 --> 01:13:17,276 Eight hours, ten hours, a thousand hours, nobody knew. 1665 01:13:17,276 --> 01:13:20,406 >> The Patriot battery stationed at the barracks at Dhahran, 1666 01:13:20,406 --> 01:13:24,276 and its flawed internal clock, had been on over 100 hours 1667 01:13:24,276 --> 01:13:25,686 on the night of February 25th. 1668 01:13:25,686 --> 01:13:29,736 >> It tracked time, to an accuracy 1669 01:13:29,736 --> 01:13:30,796 of about a tenth of a second. 1670 01:13:30,796 --> 01:13:33,956 Now, a tenth of a second is an interesting number 1671 01:13:33,956 --> 01:13:36,966 because it can't be expressed in binary exactly 1672 01:13:36,966 --> 01:13:39,536 which means it can't be expressed exactly 1673 01:13:39,536 --> 01:13:42,706 in any modern digital computer. 1674 01:13:42,706 --> 01:13:47,156 It's hard to believe, but use this as an example. 1675 01:13:47,156 --> 01:13:48,346 Let's take the number one-third. 1676 01:13:48,346 --> 01:13:52,696 One-third cannot be expressed in decimal exactly. 1677 01:13:53,226 --> 01:13:58,086 One-third is 0.333 going on for infinity. 1678 01:13:58,086 --> 01:14:02,066 There's no way to do that with absolute accuracy in decimal. 1679 01:14:02,406 --> 01:14:05,006 That's exactly the kind of problem that happened 1680 01:14:05,006 --> 01:14:06,856 in the Patriot, the longer the system ran, 1681 01:14:07,316 --> 01:14:09,246 the worse the time error became. 1682 01:14:09,546 --> 01:14:12,976 >> After one hundred hours of operation the error 1683 01:14:12,976 --> 01:14:16,936 in time was only about one-third of a second, but in terms 1684 01:14:16,936 --> 01:14:18,876 of targeting a missile traveling at Mach 5, 1685 01:14:20,136 --> 01:14:23,766 it resulted in a tracking error of over 600 meters. 1686 01:14:24,536 --> 01:14:27,456 It would be a fatal error for the soldiers at Dhahran. 1687 01:14:27,876 --> 01:14:33,186 >> What happened is a Scud launch was detected 1688 01:14:33,266 --> 01:14:35,576 by early warning satellites, and they knew 1689 01:14:35,576 --> 01:14:38,686 that the Scud was coming in their general direction. 1690 01:14:38,686 --> 01:14:40,066 They didn't know where it was coming. 1691 01:14:41,136 --> 01:14:42,896 >> It was now up to the radar component 1692 01:14:42,896 --> 01:14:46,906 of the Patriot system defending Dhahran to locate and keep track 1693 01:14:46,906 --> 01:14:48,306 of the incoming enemy missile. 1694 01:14:49,106 --> 01:14:50,346 >> The radar was very smart. 1695 01:14:50,696 --> 01:14:52,406 It would actually track the position of the Scud, 1696 01:14:52,406 --> 01:14:55,596 and then predict where it probably would be the next time 1697 01:14:55,596 --> 01:14:56,876 the radar sent a pulse out. 1698 01:14:57,336 --> 01:14:58,566 That was called a range gate. 1699 01:14:59,016 --> 01:15:03,896 >> Then once the Patriot decides enough time has passed 1700 01:15:03,896 --> 01:15:06,486 to go back and check the next location, 1701 01:15:07,006 --> 01:15:09,076 for this detected object, it goes back. 1702 01:15:09,546 --> 01:15:11,096 So when it went back to the wrong place, 1703 01:15:11,096 --> 01:15:15,226 it then sees no object and it decides 1704 01:15:15,226 --> 01:15:16,346 that there was no object, 1705 01:15:16,346 --> 01:15:19,026 it was a false detection, and drops the track. 1706 01:15:19,026 --> 01:15:22,986 >> The incoming Scud disappeared from the radar screen, 1707 01:15:22,986 --> 01:15:25,406 and seconds later, it slammed into the barracks. 1708 01:15:26,146 --> 01:15:30,416 The Scud killed 28, and was the last one fired during the First 1709 01:15:30,466 --> 01:15:31,036 Gulf War. 1710 01:15:32,126 --> 01:15:34,836 Tragically, the updated software arrived 1711 01:15:34,996 --> 01:15:36,526 at Dhahran the following day. 1712 01:15:37,256 --> 01:15:41,456 The software flaw had been fixed, closing one chapter 1713 01:15:41,456 --> 01:15:46,246 in the troubled history of the Patriot missile. 1714 01:15:46,816 --> 01:15:48,756 The Patriot is actually an acronym 1715 01:15:49,006 --> 01:15:51,996 for Phased Array Tracking Radar to Intercept of Target. 1716 01:15:52,076 --> 01:15:54,056 >> So it suffices to say there are all sorts 1717 01:15:54,056 --> 01:15:56,336 of non-militaristic applications of this stuff 1718 01:15:56,336 --> 01:15:59,196 but it's frightening just what the implications are. 1719 01:15:59,196 --> 01:16:00,616 And so, over the next few weeks, 1720 01:16:00,616 --> 01:16:03,236 what we will do is focus not only on doing 1721 01:16:03,236 --> 01:16:05,976 but understanding exactly how all of this stuff works 1722 01:16:06,256 --> 01:16:07,766 so that you yourselves are empowered 1723 01:16:07,766 --> 01:16:09,936 to build almost anything you would like by terms end. 1724 01:16:09,936 --> 01:16:14,666 We will see you on Friday. 1725 01:16:14,666 --> 01:16:15,016 [ Noise ] 1726 01:16:15,016 --> 01:16:18,576 [ Silence ]