YouTube2Text

Lec 1 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008 — Transcript

by MIT OpenCourseWare · 9,783 words · 1,271 segments · language en · Watch on YouTube

Full transcript

  1. 0:00The following content is provided under a Creative
  2. 0:02Commons license.
  3. 0:03Your support will help MIT OpenCourseware continue to
  4. 0:06offer high-quality educational resources for free.
  5. 0:10To make a donation, or view additional materials from
  6. 0:13hundreds of MIT courses, visit MIT OpenCourseware, at
  7. 0:17ocw.mit.edu .
  8. 0:17PROFESSOR: Good morning.
  9. 0:18Try it again.
  10. 0:19Good morning.
  11. 0:22STUDENTS: Good morning.
  12. 0:25PROFESSOR: Thank you.
  13. 0:27This is 6.00, also known as Introduction to Computer
  14. 0:31Science and Programming.
  15. 0:32My name is Eric Grimson, I have together Professor John
  16. 0:35Guttag over here, we're going to be lecturing
  17. 0:37the course this term.
  18. 0:39I want to give you a heads up; you're getting some serious
  19. 0:41firepower this term.
  20. 0:43John was department head for ten years, felt like a
  21. 0:47century, and in course six, I'm the current department
  22. 0:50head in course six.
  23. 0:51John's been lecturing for thirty years, roughly.
  24. 0:55All right, I'm the young guy, I've only been lecturing for
  25. 0:58twenty-five years.
  26. 0:59You can tell, I have less grey hair than he does.
  27. 1:03What I'm trying to say to you is, we take this
  28. 1:05course really seriously.
  29. 1:07We hope you do as well.
  30. 1:08But we think it's really important for the department
  31. 1:10to help everybody learn about computation, and that's what
  32. 1:14this course is about.
  33. 1:16What I want to do today is three things: I'm going to
  34. 1:19start-- actually, I shouldn't say start, I'm going to do a
  35. 1:22little bit of administrivia, the kinds of things you need
  36. 1:24to know about how we're going to run the course.
  37. 1:26I want to talk about the goal of the course, what it is
  38. 1:30you'll be able to do at the end of this course when you
  39. 1:32get through it, and then I want to begin talking about
  40. 1:35the concepts and tools of computational thinking, which
  41. 1:39is what we're primarily going to focus on here.
  42. 1:41We're going to try and help you learn how to think like a
  43. 1:43computer scientist, and we're going to begin talking about
  44. 1:45that towards the end of this lecture and of course
  45. 1:47throughout the rest of the lectures that carry on.
  46. 1:50Right, let's start with the goals.
  47. 1:52I'm going to give you goals in two levels.
  48. 1:55The strategic goals are the following: we want to help
  49. 1:58prepare freshmen and sophomores who are interested
  50. 2:02in majoring in course six to get an easy entry into the
  51. 2:05department, especially for those students who don't have
  52. 2:07a lot of prior programming experience.
  53. 2:09If you're in that category, don't panic, you're
  54. 2:11going to get it.
  55. 2:12We're going to help you ramp in and you'll certainly be
  56. 2:14able to start the course six curriculum and do just fine
  57. 2:17and still finish on target.
  58. 2:20We don't expect everybody to be a course six major,
  59. 2:22contrary to popular opinion, so for those are you not in
  60. 2:25that category, the second thing we want to do is we want
  61. 2:27to help students who don't plan to major in course six to
  62. 2:30feel justifiably confident in their ability to write and
  63. 2:34read small pieces of code.
  64. 2:37For all students, what we want to do is we want to give you
  65. 2:40an understanding of the role computation can and cannot
  66. 2:43play in tackling technical problems. So that you will
  67. 2:47come away with a sense of what you can do, what you can't do,
  68. 2:50and what kinds of things you should use to tackle complex
  69. 2:53problems.
  70. 2:54And finally, we want to position all students so that
  71. 2:56you can easily, if you like, compete for things like your
  72. 3:00office and summer jobs.
  73. 3:02Because you'll have an appropriate level of
  74. 3:04confidence and competence in your ability to do
  75. 3:06computational problem solving.
  76. 3:08Those are the strategic goals.
  77. 3:10Now, this course is primarily aimed at students who have
  78. 3:15little or no prior programming experience.
  79. 3:19As a consequence, we believe that no student here is
  80. 3:21under-qualified for this course: you're all MIT
  81. 3:24students, you're all qualified to be here.
  82. 3:26But we also hope that there aren't any students here who
  83. 3:29are over-qualified for this course.
  84. 3:31And what do I mean by that?
  85. 3:32If you've done a lot prior programming, this is probably
  86. 3:37not the best course for you, and if you're in that
  87. 3:39category, I would please encourage you to talk to John
  88. 3:42or I after class about what your goals are, what kind of
  89. 3:45experience you have, and how we might find you a course
  90. 3:48that better meets your goals.
  91. 3:51Second reason we don't want over-qualified students in the
  92. 3:54class, it sounds a little nasty, but the second reason
  93. 3:56is, an over-qualified student, somebody who's, I don't know,
  94. 3:59programmed for Google for the last five years, is going to
  95. 4:03have an easy time in this course, but we don't want such
  96. 4:05a student accidentally intimidating the rest of you.
  97. 4:08We don't want you to feel inadequate when you're simply
  98. 4:12inexperienced.
  99. 4:13And so, it really is a course aimed at students with little
  100. 4:16or no prior programming experience.
  101. 4:18And again, if you're not in that category, talk to John or
  102. 4:20I after class, and we'll help you figure out where you might
  103. 4:22want to go.
  104. 4:24OK.
  105. 4:24Those are the top-level goals of the course.
  106. 4:26Let's talk sort of at a more tactical level, about what do
  107. 4:29we want you to know in this course.
  108. 4:31What we want you to be able to do by the time
  109. 4:33you leave this course?
  110. 4:34So here are the skills that we would like you to acquire.
  111. 4:41Right, the first skill we want you to acquire, is we want you
  112. 4:44to be able to use the basic tools of computational
  113. 4:46thinking to write small scale programs. I'm going to keep
  114. 4:50coming back to that idea, but I'm going to call it
  115. 4:52computational thinking.
  116. 4:57And that's so you can write small pieces of code.
  117. 5:00And small is not derogatory here, by the way, it just says
  118. 5:02the size of things you're going to be able to do.
  119. 5:05Second skill we want you to have at the end of this course
  120. 5:08is the ability to use a vocabulary of computational
  121. 5:10tools in order to be able to understand
  122. 5:13programs written by others.
  123. 5:15So you're going to be able to write, you're going
  124. 5:16to be able to read.
  125. 5:19This latter skill, by the way, is incredibly valuable.
  126. 5:24Because you won't want to do everything from scratch
  127. 5:26yourself, you want to be able to look at what is being
  128. 5:28created by somebody else and understand what is inside of
  129. 5:31there, whether it works correctly and how you can
  130. 5:33build on it.
  131. 5:34This is one of the few places where
  132. 5:35plagiarism is an OK thing.
  133. 5:37It's not bad to, if you like, learn from the skills of
  134. 5:40others in order to create something you want to write.
  135. 5:42Although we'll come back to plagiarism as a
  136. 5:44bad thing later on.
  137. 5:46Third thing we want you to do, is to understand the
  138. 5:48fundamental both capabilities and limitations of
  139. 5:52computations, and the costs associated with them.
  140. 5:55And that latter statement sounds funny, you don't think
  141. 5:57of computations having limits, but they do.
  142. 5:59There're some things that cannot be computed.
  143. 6:01We want you to understand where those limits are.
  144. 6:03So you're going to be able to understand
  145. 6:05abilities and limits.
  146. 6:15And then, finally, the last tactical skill that you're
  147. 6:18going to get out of this course is you're going to have
  148. 6:19the ability to map scientific problems into a
  149. 6:22computational frame.
  150. 6:24So you're going to be able to take a description of a
  151. 6:26problem and map it into something computational.
  152. 6:37Now if you think about it, boy, it sounds
  153. 6:39like grammar school.
  154. 6:41We're going to teach you to read, we're going to teach you
  155. 6:43to write, we're going to teach you to understand what you can
  156. 6:46and cannot do, and most importantly, we're going to
  157. 6:49try and give you the start of an ability to take a
  158. 6:52description of a problem from some other domain, and figure
  159. 6:55out how to map it into that domain of computation so you
  160. 6:57can do the reading and writing that you want to do.
  161. 7:01OK, in a few minutes we're going to start talking then
  162. 7:03about what is computation, how are we going to start building
  163. 7:05those tools, but that's what you should take away, that's
  164. 7:07what you're going to gain out of this course by the time
  165. 7:09you're done.
  166. 7:11Now, let me take a sidebar for about five minutes to talk
  167. 7:14about course administration, the administrivia, things that
  168. 7:17we're going to do in the course, just so you know what
  169. 7:19the rules are.
  170. 7:20Right, so, class is two hours of lecture a week.
  171. 7:24You obviously know where and you know when,
  172. 7:26because you're here.
  173. 7:27Tuesdays and Thursdays at 11:00.
  174. 7:29One hour of recitation a week, on Fridays, and we'll come
  175. 7:32back in a second to how you're going to get set up for that.
  176. 7:34And nine hours a week of outside-the-class work.
  177. 7:38Those nine hours are going to be primarily working on
  178. 7:40problem sets, and all the problems sets are going to
  179. 7:42involve programming in Python, which is the language we're
  180. 7:45going to be using this term.
  181. 7:48Now, one of the things you're going to see is the first
  182. 7:50problem sets are pretty easy.
  183. 7:51Actually, that's probably wrong, John, right?
  184. 7:52They're very easy.
  185. 7:54And we're going to ramp up.
  186. 7:55By the time you get to the end of the term, you're going to
  187. 7:57be dealing with some fairly complex things, so one of the
  188. 7:59things you're going to see is, we're going to make heavy use
  189. 8:01of libraries, or code written by others.
  190. 8:04It'll allow you to tackle interesting problems I'll have
  191. 8:06you to write from scratch, but it does mean that this skill
  192. 8:11here is going to be really valuable.
  193. 8:13You need to be able to read that code and understand it,
  194. 8:15as well as write your own.
  195. 8:18OK.
  196. 8:19Two quizzes.
  197. 8:20During the term, the dates have already been scheduled.
  198. 8:23John, I forgot to look them up, I think it's October 2nd
  199. 8:25and November 4th, it'll be on the course website.
  200. 8:29My point is, go check the course website, which by the
  201. 8:31way is right there.
  202. 8:34If you have, if you know you have a conflict with one of
  203. 8:37those quiz dates now, please see John or I right away.
  204. 8:40We'll arrange something ahead of time.
  205. 8:42But if you--
  206. 8:44The reason I'm saying that is, you know, you know that you're
  207. 8:45getting married that day for example, we will excuse you
  208. 8:47from the quiz to get married.
  209. 8:49We'll expect you come right back to do the quiz by the
  210. 8:51way, but the--
  211. 8:53Boy, tough crowd.
  212. 8:54All right.
  213. 8:57If you have a conflict, please let us know.
  214. 8:59Second thing is, if you have an MIT documented special need
  215. 9:03for taking quizzes, please see John or I well in advance.
  216. 9:07At least two weeks before the quiz.
  217. 9:08Again, we'll arrange for this, but you need to give us enough
  218. 9:10warning so that we can deal with that.
  219. 9:13OK, the quizzes are open book.
  220. 9:16This course is not about memory.
  221. 9:20It's not how well you can memorize facts: in fact, I
  222. 9:22think both John and I are a little sensitive to memory
  223. 9:24tests, given our age, right John?
  224. 9:26This is not about how you memorize things, it's about
  225. 9:28how you think.
  226. 9:29So they're open note, open book.
  227. 9:30It's really going to test your ability to think.
  228. 9:34The grades for the course will be assigned roughly, and I use
  229. 9:38the word roughly because we reserve the right to move
  230. 9:40these numbers around a little bit, but basically in the
  231. 9:42following percentages: 55% of your grade comes from the
  232. 9:44problem sets, the other 45% come from the quizzes.
  233. 9:48And I should've said there's two quizzes and a final exam.
  234. 9:50I forgot, that final exam during final period.
  235. 9:52So the quiz percentages are 10%, 15%, and 20%.
  236. 9:55Which makes up the other 45%.
  237. 9:59OK.
  238. 10:00Other administrivia.
  239. 10:02Let me just look through my list here.
  240. 10:05First problem set, problem set zero, has already been posted.
  241. 10:07This is a really easy one.
  242. 10:09We intend it to be a really easy problem set.
  243. 10:11It's basically to get you to load up Python on your machine
  244. 10:14and make sure you understand how to interact with it.
  245. 10:17The first problem set will be posted shortly, it's also
  246. 10:19pretty boring-- somewhat like my lectures but not John's--
  247. 10:23and that means, you know, we want you just to
  248. 10:25get going on things.
  249. 10:26Don't worry, we're going to make them more interesting as
  250. 10:27you go along.
  251. 10:28Nonetheless, I want to stress that none of these problems
  252. 10:31sets are intended to be lethal.
  253. 10:33We're not using them to weed you out, we're using them to
  254. 10:36help you learn.
  255. 10:36So if you run into a problem set that just, you
  256. 10:39don't get, all right?
  257. 10:41Seek help.
  258. 10:43Could be psychiatric help, could be a TA.
  259. 10:46I recommend the TA.
  260. 10:47My point being, please come and talk to somebody.
  261. 10:50The problems are set up so that, if you start down the
  262. 10:53right path, it should be pretty straight-forward to
  263. 10:55work it through.
  264. 10:56If you start down a plausible but incorrect path, you can
  265. 11:00sometimes find yourself stuck in the weeds somewhere, and we
  266. 11:02want to bring you back in.
  267. 11:03So part of the goal here is, this should not be a grueling,
  268. 11:08exhausting kind of task, it's really something that should
  269. 11:10be helping you learn the material.
  270. 11:12If you need help, ask John, myself, or the TAs.
  271. 11:15That's what we're here for.
  272. 11:17OK.
  273. 11:18We're going to run primarily a paperless subject, that's why
  274. 11:22the website is there.
  275. 11:23Please check it, that's where everything's going to be
  276. 11:24posted in terms of things you need to know.
  277. 11:27In particular, please go to it today, you will find a form
  278. 11:30there that you need to fill out to register for, or sign
  279. 11:33up for rather, a recitation.
  280. 11:35Recitations are on Friday.
  281. 11:37Right now, we have them scheduled at 9:00, 10:00,
  282. 11:3911:00, 12:00, 1:00, and 2:00.
  283. 11:41We may drop one of the recitations, just depending on
  284. 11:45course size, all right?
  285. 11:46So we reserve the right, unfortunately, to have to move
  286. 11:48you around.
  287. 11:49My guess is that 9:00 is not going to be a tremendously
  288. 11:52popular time, but maybe you'll surprise me.
  289. 11:54Nonetheless, please go in and sign up.
  290. 11:56We will let you sign up for whichever recitation makes
  291. 11:58sense for you.
  292. 11:59Again, we reserve the right to move people around if we have
  293. 12:02to, just to balance load, but we want you to find something
  294. 12:04that fits your schedule rather than ours.
  295. 12:08OK.
  296. 12:09Other things.
  297. 12:10There is no required text.
  298. 12:12If you feel exposed without a text book, you really have to
  299. 12:17have a textbook, you'll find one recommended-- actually I'm
  300. 12:20going to reuse that word, John, at least suggest it, on
  301. 12:23the course website.
  302. 12:24I don't think either of us are thrilled with the text, it's
  303. 12:26the best we've probably found for Python, it's OK.
  304. 12:28If you need it, it's there.
  305. 12:29But we're going to basically not rely on any specific text.
  306. 12:33Right.
  307. 12:34Related to that: attendance here is
  308. 12:36obviously not mandatory.
  309. 12:38You ain't in high school anymore.
  310. 12:40I think both of us would love to see your smiling faces, or
  311. 12:42at least your faces, even if you're not
  312. 12:44smiling at us every day.
  313. 12:46Point I want to make about this, though, is that we are
  314. 12:49going to cover a lot of material that is not in the
  315. 12:52assigned readings, and we do have assigned readings
  316. 12:53associated with each one of these lectures.
  317. 12:57If you choose not to show up today-- or sorry, you did
  318. 13:00choose to show up today, if you choose not to show up in
  319. 13:03future days-- we'll understand, but please also
  320. 13:05understand that the TAs won't have a lot of patience with
  321. 13:08you if you're asking a question about something that
  322. 13:10was either covered in the readings, or covered in the
  323. 13:12lecture and is pretty straight forward.
  324. 13:14All right?
  325. 13:14We expect you to behave responsibly
  326. 13:16and we will as well.
  327. 13:18All right.
  328. 13:20I think the last thing I want to say is, we will not be
  329. 13:22handing out class notes.
  330. 13:26Now this sounds like a draconian measure;
  331. 13:27let me tell you why.
  332. 13:29Every study I know of, and I suspect every one John knows,
  333. 13:31about learning, stresses that students learn best when they
  334. 13:35take notes.
  335. 13:36Ironically, even if they never look at them.
  336. 13:40OK.
  337. 13:40The process of writing is exercising both halves of your
  338. 13:44brain, and it's actually helping you learn, and so
  339. 13:46taking notes is really valuable thing.
  340. 13:48Therefore we're not going to distribute notes.
  341. 13:50What we will distribute for most lectures is a handout
  342. 13:53that's mostly code examples that we're going to do.
  343. 13:55I don't happen to have one today because we're not going
  344. 13:57to do a lot of code.
  345. 13:58We will in future.
  346. 13:59Those notes are going to make no sense, I'm guessing,
  347. 14:02outside of the lecture, all right?
  348. 14:04So it's not just, you can swing by 11:04 and grab a copy
  349. 14:08and go off and catch some more sleep.
  350. 14:10What we recommend is you use those notes to take your own
  351. 14:13annotations to help you understand what's going on,
  352. 14:15but we're not going to provide class notes.
  353. 14:17We want you to take your own notes to help you, if you
  354. 14:20like, spur your own learning process.
  355. 14:23All right.
  356. 14:24And then finally, I want to stress that John, myself, all
  357. 14:28of the staff, our job is to help you learn.
  358. 14:32That's what we're here for.
  359. 14:32It's what we get excited about.
  360. 14:35If you're stuck, if you're struggling, if you're not
  361. 14:38certain about something, please ask.
  362. 14:40We're not mind readers, we can't tell when you're
  363. 14:42struggling, other than sort of seeing the expression on your
  364. 14:44face, we need your help in identifying that.
  365. 14:48But all of the TAs, many of whom are sitting down in the
  366. 14:50front row over here, are here to help, so come and ask.
  367. 14:53At the same time, remember that they're students too.
  368. 14:56And if you come and ask a question that you could have
  369. 14:59easily answered by doing the reading, coming to lecture, or
  370. 15:02using Google, they're going to have less patience.
  371. 15:05But helping you understand things that really are a
  372. 15:07conceptual difficulty is what they're here for and what
  373. 15:10we're here for, so please come and talk to us.
  374. 15:14OK.
  375. 15:15That takes care of the administrivia preamble.
  376. 15:17John, things we add?
  377. 15:18PROFESSOR GUTTAG: Two more quick things.
  378. 15:34This semester, your class is being videotaped for
  379. 15:35OpenCourseware.
  380. 15:35If any of you don't want your image recorded and posted on
  381. 15:36the web, you're supposed to sit in the back three rows.
  382. 15:38PROFESSOR GRIMSON: Ah, thank you.
  383. 15:39I forgot.
  384. 15:39PROFESSOR GUTTAG: --Because the camera may pan.
  385. 15:40I think you're all very good-looking and give MIT a
  386. 15:40good image, so please, feel free to be filmed.
  387. 15:40PROFESSOR GRIMSON: I'll turn around, so if you want to, you
  388. 15:45know, move to the back, I won't see who moves.
  389. 15:48Right.
  390. 15:48Great.
  391. 15:48Thank you, John.
  392. 15:49PROFESSOR GUTTAG: So that, the other thing I want to mention
  393. 15:57is, recitations are also very important.
  394. 16:00We will be covering material in recitations that're not in
  395. 16:00the lectures, not in the reading, and we do expect you
  396. 16:03to attend recitations.
  397. 16:03PROFESSOR GRIMSON: Great.
  398. 16:04Thanks, John.
  399. 16:06Any questions about the administrivia?
  400. 16:08I know it's boring, but we need to do it so you know what
  401. 16:10the ground rules are.
  402. 16:12Good.
  403. 16:13OK.
  404. 16:14Let's talk about computation.
  405. 16:16As I said, our strategic goal, our tactical goals, are to
  406. 16:19help you think like a computer scientist. Another way of
  407. 16:23saying it is, we want to give you the skill so that you can
  408. 16:25make the computer do what you want it to do.
  409. 16:28And we hope that at the end of the class, every time you're
  410. 16:30confronted with some technical problem, one of your first
  411. 16:32instincts is going to be, "How do I write the piece of code
  412. 16:35that's going to help me solve that?"
  413. 16:37So we want to help you think like a computer
  414. 16:39scientist. All right.
  415. 16:41And that, is an interesting statement.
  416. 16:45What does it mean, to think like a computer scientist?
  417. 16:55Well, let's see.
  418. 16:59The primary knowledge you're going to take away from this
  419. 17:00course is this notion of computational problem solving,
  420. 17:02this ability to think in
  421. 17:04computational modes of thought.
  422. 17:07And unlike in a lot of introductory courses, as a
  423. 17:10consequence, having the ability to memorize is not
  424. 17:12going to help you.
  425. 17:13It's really learning those notions of the tools that you
  426. 17:16want to use.
  427. 17:18What in the world does it mean to say
  428. 17:19computational mode of thought?
  429. 17:20It sounds like a hifalutin phrase you use when you're
  430. 17:22trying to persuade a VC to fund you.
  431. 17:24Right.
  432. 17:25So to answer this, we really have to ask a different
  433. 17:27question, a related question; so, what's computation?
  434. 17:31It's like a strange statement, right?
  435. 17:32What is computation?
  436. 17:35And part of the reason for putting it up is that I want
  437. 17:38to, as much as possible, answer that question by
  438. 17:41separating out the mechanism, which is the computer, from
  439. 17:45computational thinking.
  440. 17:47Right.
  441. 17:47The artifact should not be what's driving this.
  442. 17:49It should be the notion of, "What does it mean to do
  443. 17:51computation?"
  444. 17:53Now, to answer that, I'm going to back up one more level.
  445. 17:56And I'm going to pose what sounds like a philosophy
  446. 17:57question, which is, "What is knowledge?" And you'll see in
  447. 18:01about two minutes why I'm going to do this.
  448. 18:02But I'm going to suggest that I can divide knowledge into at
  449. 18:04least two categories.
  450. 18:07OK, and what is knowledge?
  451. 18:08And the two categories I'm going to divide them into are
  452. 18:12declarative and imperative knowledge.
  453. 18:19Right.
  454. 18:20What in the world is declarative knowledge?
  455. 18:22Think of it as statements of fact.
  456. 18:25It's assertions of truth.
  457. 18:27Boy, in this political season, that's a really dangerous
  458. 18:29phrase to use, right?
  459. 18:30But it's a statement of fact.
  460. 18:32I'll stay away from the political comments.
  461. 18:34Let me give you an example of this.
  462. 18:35Right.
  463. 18:36Here's a declarative statement.
  464. 18:37The square root of x is that y such that y squared equals x,
  465. 18:46y's positive.
  466. 18:48You all know that.
  467. 18:50But what I want you to see here, is that's a
  468. 18:52statement of fact.
  469. 18:54It's a definition.
  470. 18:55It's an axiom.
  471. 18:55It doesn't help you find square roots.
  472. 19:00If I say x is 2, I want to know, what's the square root
  473. 19:02of 2, well if you're enough of a geek, you'll say 1.41529 or
  474. 19:06whatever the heck it is, but in general, this doesn't help
  475. 19:10you find the square root.
  476. 19:12The closest it does is it would let you test. You know,
  477. 19:15if you're wandering through Harvard Square and you see an
  478. 19:17out-of-work Harvard grad, they're handing out examples
  479. 19:19of square roots, they'll give you an example and you can
  480. 19:21test it to see, is the square root of
  481. 19:232, 1.41529 or whatever.
  482. 19:26I don't even get laughs at Harvard jokes, John, I'm going
  483. 19:29to stop in a second here, all right?
  484. 19:31All right, so what am I trying to say here?
  485. 19:33It doesn't -- yeah, exactly.
  486. 19:36We're staying away from that, really quickly, especially
  487. 19:38with the cameras rolling.
  488. 19:39All right.
  489. 19:40What am I trying to say?
  490. 19:41It tells you how you might test something but it doesn't
  491. 19:44tell you how to.
  492. 19:46And that's what imperative knowledge is.
  493. 19:48Imperative knowledge is a description of
  494. 19:51how to deduce something.
  495. 19:52So let me give you an example of a piece
  496. 19:54of imperative knowledge.
  497. 19:56All right, this is actually a very old piece of imperative
  498. 19:58knowledge for computing square roots, it's attributed to
  499. 20:00Heron of Alexandria, although I believe that the Babylonians
  500. 20:04are suspected of knowing it beforehand.
  501. 20:07But here is a piece of imperative knowledge.
  502. 20:09All right?
  503. 20:10I'm going to start with a guess, I'm going to call it g.
  504. 20:17And then I'm going to say, if g squared is close to x, stop.
  505. 20:26And return g.
  506. 20:28It's a good enough answer.
  507. 20:30Otherwise, I'm going to get a new guess by taking g, x over
  508. 20:38g, adding them, and dividing by two.
  509. 20:42Then you take the average of g and x over g.
  510. 20:44Don't worry about how came about, Heron found this out.
  511. 20:47But that gives me a new guess, and I'm going to repeat.
  512. 20:56That's a recipe.
  513. 20:58That's a description of a set of steps.
  514. 21:01Notice what it has, it has a bunch of nice things that we
  515. 21:04want to use, right?
  516. 21:05It's a sequence of specific instructions
  517. 21:08that I do in order.
  518. 21:10Along the way I have some tests, and depending on the
  519. 21:13value of that test, I may change where I am in that
  520. 21:17sequence of instructions.
  521. 21:18And it has an end test, something that tells me when
  522. 21:20I'm done and what the answer is.
  523. 21:22This tells you how to find square roots.
  524. 21:24it's how-to knowledge.
  525. 21:25It's imperative knowledge.
  526. 21:27All right.
  527. 21:27That's what computation basically is about.
  528. 21:31We want to have ways of capturing this process.
  529. 21:35OK, and that leads now to an interesting question, which
  530. 21:37would be, "How do I build a mechanical process to capture
  531. 21:43that set of computations?" So I'm going to suggest that
  532. 21:46there's an easy way to do it--
  533. 21:50I realized I did the boards in the wrong order here-- one of
  534. 21:53the ways I could do it is, you could imagine building a
  535. 21:55little circuit to do this.
  536. 21:57If I had a couple of elements of stored values in it, I had
  537. 22:00some wires to move things around, I had a little thing
  538. 22:02to do addition, little thing to do division, and a
  539. 22:05something to do the testing, I could build a little circuit
  540. 22:07that would actually do this computation.
  541. 22:09OK.
  542. 22:11That, strange as it sounds, is actually an example of the
  543. 22:15earliest computers, because the earliest computers were
  544. 22:18what we call fixed-program computers, meaning that they
  545. 22:31had a piece of circuitry designed to do a specific
  546. 22:34computation.
  547. 22:35And that's what they would do: they would do that specific
  548. 22:38computation.
  549. 22:40You've seen these a lot, right?
  550. 22:41A good example of this: calculator.
  551. 22:47It's basically an example of a fixed-program computer.
  552. 22:51It does arithmetic.
  553. 22:53If you want play video games on it, good luck.
  554. 22:55If you want to do word processing on it, good luck.
  555. 22:58It's designed to do a specific thing.
  556. 23:00It's a fixed-program computer.
  557. 23:03In fact, a lot of the other really interesting early ones
  558. 23:05similarly have this flavor, to give an example: I never know
  559. 23:09how to pronounce this, Atanasoff, 1941.
  560. 23:14One of the earliest computational things was a
  561. 23:16thing designed by a guy named Atanasoff, and it basically
  562. 23:18solved linear equations.
  563. 23:22Handy thing to do if you're doing 1801, all right, or
  564. 23:261806, or whatever you want to do those things in.
  565. 23:29All it could do, though, was solve those equations.
  566. 23:31One of my favorite examples of an early computer was done by
  567. 23:36Alan Turing, one of the great computer scientists of all
  568. 23:39time, called the bombe, which was designed to break codes.
  569. 23:43It was actually used during WWII to break
  570. 23:45German Enigma codes.
  571. 23:46And what it was designed to do, was to solve
  572. 23:48that specific problem.
  573. 23:49The point I'm trying to make is, fixed-program computers is
  574. 23:53where we started, but it doesn't really get us to where
  575. 23:55we'd like to be.
  576. 23:55We want to capture this idea of problem solving.
  577. 23:58So let's see how we'd get there.
  578. 24:01So even within this framework of, given a description of a
  579. 24:05computation as a set of steps, in the idea that I could build
  580. 24:08a circuit to do it, let me suggest for you what would be
  581. 24:10a wonderful circuit to build.
  582. 24:13Suppose you could build a circuit with the following
  583. 24:15property: the input to this circuit would be any other
  584. 24:18circuit diagram.
  585. 24:20Give it a circuit diagram for some computation, you give it
  586. 24:22to the circuit, and that circuit would wonderfully
  587. 24:26reconfigure itself to act like the circuits diagram.
  588. 24:30Which would mean, it could act like a calculator.
  589. 24:33Or, it could act like Turing's bombe.
  590. 24:35Or, it could act like a square root machine.
  591. 24:38So what would that circuit look like?
  592. 24:39You can imagine these tiny little robots wandering
  593. 24:42around, right?
  594. 24:42Pulling wires and pulling out components and
  595. 24:44stacking them together.
  596. 24:45How would you build a circuit that could take a circuit
  597. 24:47diagram in and make a machine act like that circuit?
  598. 24:53Sounds like a neat challenge.
  599. 24:55Let me change the game slightly.
  600. 24:59Suppose instead, I want a machine that can take a
  601. 25:02recipe, the description of a sequence of steps, take that
  602. 25:07as its input, and then that machine will now act like what
  603. 25:12is described in that recipe.
  604. 25:15Reconfigure itself, emulate it, however you want to use
  605. 25:17the words, it's going to change how it does the
  606. 25:19computation.
  607. 25:21That would be cool.
  608. 25:23And that exists.
  609. 25:24It's called an interpreter.
  610. 25:26It is the basic heart of every computer.
  611. 25:29What it is doing, is saying, change the game.
  612. 25:33This is now an example of a stored-program computer.
  613. 25:40What that means, in a stored-program computer, is
  614. 25:48that I can provide to the computer a sequence of
  615. 25:51instructions describing the process I want it to execute.
  616. 25:55And inside of the machine, and things we'll talk about, there
  617. 25:58is a process that will allow that sequence to be executed
  618. 26:02as described in that recipe, so it can behave like any
  619. 26:06thing that I can describe in one of those recipes.
  620. 26:09All right.
  621. 26:10That actually seems like a really nice thing to have, and
  622. 26:14so let me show you what that would basically look like.
  623. 26:19Inside of a stored-program computer, we would have the
  624. 26:22following: we have a memory, it's connected to two things;
  625. 26:31control unit, in what's called an ALU, an arithmetic logic
  626. 26:37unit, and this can take in input, and spit out output,
  627. 26:46and inside this stored-program computer, excuse me, you have
  628. 26:50the following: you have a sequence of instructions.
  629. 26:55And these all get stored in there.
  630. 27:03Notice the difference.
  631. 27:05The recipe, the sequence of instructions, is actually
  632. 27:07getting read in, and it's treated just like data.
  633. 27:10It's inside the memory of the machine, which means we have
  634. 27:12access to it, we can change it, we can use it to build new
  635. 27:15pieces of code, as well as we can interpret it.
  636. 27:19One other piece that goes into this computer--
  637. 27:21I never remember where to put the PC, John, control?
  638. 27:23ALU?
  639. 27:25Separate?
  640. 27:26I'll put it separate-- you have a thing
  641. 27:29called a program counter.
  642. 27:31And here's the basis of the computation.
  643. 27:34That program counter points to some location in memory,
  644. 27:38typically to the first instruction in the sequence.
  645. 27:43And those instructions, by the way, are very simple: they're
  646. 27:45things like, take the value out of two places in memory,
  647. 27:48and run them through the multiplier in here, a little
  648. 27:51piece of circuitry, and stick them back into
  649. 27:53someplace in memory.
  650. 27:54Or take this value out of memory, run it through some
  651. 27:57other simple operation, stick it back in memory.
  652. 28:00Having executed this instruction, that counter goes
  653. 28:03up by one and we move to the next one.
  654. 28:05We execute that instruction, we move to the next one.
  655. 28:08Oh yeah, it looks a whole lot like that.
  656. 28:13Some of those instructions will involve tests: they'll
  657. 28:16say, is something true?
  658. 28:18And if the test is true, it will change the value of this
  659. 28:22program counter to point to some other place in the
  660. 28:25memory, some other point in that sequence of instructions,
  661. 28:28and you'll keep processing.
  662. 28:30Eventually you'll hopefully stop, and a value gets spit
  663. 28:32out, and you're done.
  664. 28:34That's the heart of a computer.
  665. 28:35Now that's a slight misstatement.
  666. 28:37The process to control it is intriguing and interesting,
  667. 28:39but the heart of the computer is simply this notion that we
  668. 28:42build our descriptions, our recipes, on a sequence of
  669. 28:46primitive instructions.
  670. 28:47And then we have a flow of control.
  671. 28:50And that flow of control is what I just described.
  672. 28:51It's moving through a sequence of instructions, occasionally
  673. 28:53changing where we are as we move around.
  674. 28:57OK.
  675. 28:58The thing I want you to take away from this, then, is to
  676. 29:02think of this as, this is, if you like, a recipe.
  677. 29:06And that's really what a program is.
  678. 29:19It's a sequence of instructions.
  679. 29:21Now, one of things I left hanging is, I said, OK, you
  680. 29:23build it out of primitives.
  681. 29:24So one of the questions is, well, what are the right
  682. 29:25primitives to use?
  683. 29:28And one of the things that was useful here is, that we
  684. 29:31actually know that the set of primitives that you want to
  685. 29:33use is very straight-forward.
  686. 29:37OK, but before I do that, let me drive home this idea of why
  687. 29:39this is a recipe.
  688. 29:42Assuming I have a set of primitive instructions that I
  689. 29:44can describe everything on, I want to know what can I build.
  690. 29:47Well, I'm going to do the same analogy to a real recipe.
  691. 29:49So, real recipe.
  692. 29:51I don't know.
  693. 29:51Separate six eggs.
  694. 29:54Do something.
  695. 29:55Beat until the-- sorry, beat the whites
  696. 29:57until they're stiff.
  697. 29:59Do something until an end test is true.
  698. 30:02Take the yolks and mix them in with the sugar and water--
  699. 30:04No.
  700. 30:05Sugar and flour I guess is probably what I want, sugar
  701. 30:06and water is not going to do anything interesting for me
  702. 30:08here-- mix them into something else.
  703. 30:11Do a sequence of things.
  704. 30:13A traditional recipe actually is based on a small set of
  705. 30:17primitives, and a good chef with, or good cook, I should
  706. 30:21say, with that set of primitives, can create an
  707. 30:23unbounded number of great dishes.
  708. 30:26Same thing holds true in programming.
  709. 30:28Right.
  710. 30:29Given a fixed set of primitives, all right, a good
  711. 30:37programmer can program anything.
  712. 30:43And by that, I mean anything that can be described in one
  713. 30:45of these process, you can capture in that set of
  714. 30:47primitives.
  715. 30:49All right, the question is, as I started to say, is, "What
  716. 30:51are the right primitives?" So there's a little bit of, a
  717. 30:54little piece of history here, if you like.
  718. 30:55In 1936, that same guy, Alan Turing, showed that with six
  719. 31:01simple primitives, anything that could be described in a
  720. 31:05mechanical process, it's actually algorithmically,
  721. 31:08could be programmed just using those six primitives.
  722. 31:12Think about that for a second.
  723. 31:14That's an incredible statement.
  724. 31:16It says, with six primitives, I can rule the world.
  725. 31:20With six primitives, I can program anything.
  726. 31:23A couple of really interesting consequences of that, by the
  727. 31:25way, one of them is, it says, anything you can do in one
  728. 31:29programming language, you can do in
  729. 31:31another programming language.
  730. 31:33And there is no programming language that is better-- well
  731. 31:36actually, that's not quite true, there are some better at
  732. 31:37doing certain kinds of things-- but there's nothing
  733. 31:39that you can do in C that you can't do in Fortran.
  734. 31:43It's called Turing compatibility.
  735. 31:45Anything you can do with one, you can do with another, it's
  736. 31:46based on that fundamental result.
  737. 31:49OK.
  738. 31:50Now, fortunately we're not going to start with Turing's
  739. 31:53six primitives, this would be really painful programming,
  740. 31:56because they're down at the level of, "take this value and
  741. 31:59write it onto this tape." First of all, we don't have
  742. 32:01tapes anymore in computers, and even if we did, you don't
  743. 32:04want to be programming at that level.
  744. 32:05What we're going to see with programming language is that
  745. 32:07we're going to use higher-level abstracts.
  746. 32:09A broader set of primitives, but nonetheless the same
  747. 32:12fundamental thing holds.
  748. 32:13With those six primitives, you can do it.
  749. 32:16OK.
  750. 32:18So where are we here?
  751. 32:19What we're saying is, in order to do computation, we want to
  752. 32:22describe recipes, we want to describe this sequence of
  753. 32:24steps built on some primitives, and we want to
  754. 32:28describe the flow of control that goes through those
  755. 32:30sequence of steps as we carry on.
  756. 32:33So the last thing we need before we can start talking
  757. 32:35about real programming is, we need to
  758. 32:36describe those recipes.
  759. 32:39All right, And to describe the recipes, we're
  760. 32:41going to want a language.
  761. 32:54We need to know not only what are the primitives, but how do
  762. 32:57we make things meaningful in that language.
  763. 33:01Language.
  764. 33:03There we go.
  765. 33:05All right.
  766. 33:07Now, it turns out there are--
  767. 33:08I don't know, John, hundreds?
  768. 33:09Thousands?
  769. 33:10Of programming languages?
  770. 33:11At least hundreds-- of programming languages around.
  771. 33:13PROFESSOR JOHN GUTTAG: [UNINTELLIGIBLE]
  772. 33:16PROFESSOR ERIC GRIMSON: True.
  773. 33:16Thank you.
  774. 33:18You know, they all have, you know,
  775. 33:20their pluses and minuses.
  776. 33:21I have to admit, in my career here, I think I've taught in
  777. 33:23at least three languages, I suspect you've taught more,
  778. 33:26five or six, John?
  779. 33:27Both of us have probably programmed in more than those
  780. 33:29number of languages, at least programmed that many, since we
  781. 33:31taught in those languages.
  782. 33:33One of the things you want to realize is,
  783. 33:35there is no best language.
  784. 33:36At least I would argue that, I think John would agree.
  785. 33:38We might both agree we have our own nominees for worst
  786. 33:40language, there are some of those.
  787. 33:43There is no best language.
  788. 33:44All right?
  789. 33:44They all are describing different things.
  790. 33:46Having said that, some of them are better suited for some
  791. 33:48things than others.
  792. 33:51Anybody here heard of MATLAB Maybe programmed in MATLAB?
  793. 33:55It's great for doing things with vectors and matrices and
  794. 33:58things that are easily captured in that framework.
  795. 34:01But there's some things that are a real
  796. 34:02pain to do in MATLAB.
  797. 34:03So MATLAB's great for that kind of thing.
  798. 34:05C is a great language for programming things that
  799. 34:07control data networks, for example.
  800. 34:10I happen to be, and John teases me about this
  801. 34:12regularly, I'm an old-time Lisp programmer, and that's
  802. 34:14how I was trained.
  803. 34:16And I happen to like Lisp and Scheme, it's a great language
  804. 34:19when you're trying to deal with problems where you have
  805. 34:20arbitrarily structured data sets.
  806. 34:23It's particularly good at that.
  807. 34:25So the point I want to make here is that there's no
  808. 34:27particularly best language.
  809. 34:30What we're going to do is simply use a language that
  810. 34:32helps us understand.
  811. 34:33So in this course, the language we're
  812. 34:34going to use is Python.
  813. 34:38Which is a pretty new language, it's growing in
  814. 34:39popularity, it has a lot of the elements of some other
  815. 34:42languages because it's more recent, it inherits things
  816. 34:44from it's pregenitors, if you like.
  817. 34:48But one of the things I want to stress is, this course is
  818. 34:50not about Python.
  819. 34:54Strange statement.
  820. 34:55You do need to know how to use it, but it's not about the
  821. 34:58details of, where do the semi-colons go in Python.
  822. 35:00All right?
  823. 35:02It's about using it to think.
  824. 35:04And what you should take away from this course is having
  825. 35:06learned how to design recipes, how to structure recipes, how
  826. 35:10to do things in modes in Python.
  827. 35:13Those same tools easily transfer
  828. 35:15to any other language.
  829. 35:16You can pick up another language in a week, couple of
  830. 35:18weeks at most, once you know how to do Python.
  831. 35:22OK.
  832. 35:23In order to talk about Python and languages, I want to do
  833. 35:25one last thing to set the stage for what we're going to
  834. 35:28do here, and that's to talk about the different dimensions
  835. 35:30of a language.
  836. 35:31And there're three I want to deal with.
  837. 35:33The first one is, whether this is a high-level
  838. 35:35or low-level language.
  839. 35:41That basically says, how close are you
  840. 35:42the guts of the machine?
  841. 35:43A low-level language, we used to call this assembly
  842. 35:45programming, you're down at the level of, your primitives
  843. 35:48are literally moving pieces of data from one location of
  844. 35:51memory to another, through a very simple operation.
  845. 35:54A high-level language, the designer has created a much
  846. 35:57richer set of primitive things.
  847. 35:59In a high-level language, square root might simply be a
  848. 36:02primitive that you can use, rather than you having to go
  849. 36:04over and code it.
  850. 36:06And there're trade-offs between both.
  851. 36:08Second dimension is, whether this is a general versus a
  852. 36:12targeted language.
  853. 36:15And by that I mean, do the set of primitives support a broad
  854. 36:18range of applications, or is it really aimed at a very
  855. 36:22specific set of applications?
  856. 36:23I'd argue that MATLAB is basically a targeted language,
  857. 36:25it's targeted at matrices and vectors and things like that.
  858. 36:29And the third one I want to point out is, whether this is
  859. 36:31an interpreted versus a compiled language.
  860. 36:41What that basically says is the following: in an
  861. 36:44interpreted language, you take what's called the source code,
  862. 36:46the thing you write, it may go through a simple checker but
  863. 36:49it basically goes to the interpreter, that thing inside
  864. 36:52the machine that's going to control the flow of going
  865. 36:54through each one of the instructions,
  866. 36:55and give you an output.
  867. 36:57So the interpreter is simply operating directly on your
  868. 37:00code at run time.
  869. 37:02In a compiled language, you have an intermediate step, in
  870. 37:05which you take the source code, it runs through what's
  871. 37:07called a checker or a compiler or both, and it creates what's
  872. 37:10called object code.
  873. 37:11And that does two things: one, it helps catch bugs in your
  874. 37:16code, and secondly it often converts it into a more
  875. 37:19efficient sequence of instructions before you
  876. 37:21actually go off and run it.
  877. 37:24All right?
  878. 37:24And there's trade-offs between both.
  879. 37:25I mean, an interpreted language is often easier to
  880. 37:27debug, because you can still see your raw code there, but
  881. 37:30it's not always as fast. A compiled language is usually
  882. 37:32much faster in terms of its execution.
  883. 37:34And it's one of the things you may want to trade off.
  884. 37:37Right.
  885. 37:38In the case of Python, it's a high-level language.
  886. 37:43I would argue, I think John would agree with me, it's
  887. 37:45basically a general-purpose language.
  888. 37:47It happens to be better suited for manipulating strings than
  889. 37:50numbers, for example, but it's really a
  890. 37:51general-purpose language.
  891. 37:53And it's primarily--
  892. 37:55I shouldn't say primarily, it is an interpreted language.
  893. 37:58OK?
  894. 37:59As a consequence, it's not as good as helping debug, but it
  895. 38:03does let you-- sorry, that's the wrong way of saying-- it's
  896. 38:04not as good at catching some things before you run them, it
  897. 38:07is easier at some times in debugging as you go
  898. 38:09along on the fly.
  899. 38:11OK.
  900. 38:11So what does Python look like?
  901. 38:13In order to talk about Python-- actually, I'm going
  902. 38:15to do it this way-- we need to talk about how to
  903. 38:22write things in Python.
  904. 38:22Again, you have to let me back up slightly and set the stage.
  905. 38:26Our goal is to build recipes.
  906. 38:28You're all going to be great chefs by the
  907. 38:29time you're done here.
  908. 38:30All right?
  909. 38:32Our goal is to take problems and break them down into these
  910. 38:35computational steps, these sequence of instructions
  911. 38:37that'll allow us to capture that process.
  912. 38:40To do that, we need to describe: not only, what are
  913. 38:42the primitives, but how do we capture things legally in that
  914. 38:45language, and interact with the computer?
  915. 38:47And so for that, we need a language.
  916. 38:49We're about to start talking about the elements of the
  917. 38:51language, but to do that, we also need to separate out one
  918. 38:54last piece of distinction.
  919. 38:58Just like with a natural language, we're going to
  920. 38:59separate out syntax versus semantics.
  921. 39:02So what's syntax?
  922. 39:03Syntax basically says, what are the legal expressions in
  923. 39:09this language?
  924. 39:16Boy, my handwriting is atrocious, isn't it?
  925. 39:22There's a English sequence of words.
  926. 39:25It's not since syntactically correct, right?
  927. 39:27It's not a sentence.
  928. 39:28There's no verb in there anywhere, it's just
  929. 39:30a sequence of nouns.
  930. 39:31Same thing in our languages.
  931. 39:32We have to describe how do you put together legally formed
  932. 39:36expressions.
  933. 39:38OK?
  934. 39:39And as we add constructs to the language, we're going to
  935. 39:41talk about.
  936. 39:42Second thing we want to talk about very briefly as we go
  937. 39:45along is the semantics of the language.
  938. 39:48And here we're going to break out two pieces; static
  939. 39:50semantics and full semantics.
  940. 39:53Static semantics basically says which programs are
  941. 40:01meaningful.
  942. 40:05Which expressions make sense.
  943. 40:09Here's an English sentence.
  944. 40:17It's syntactically correct.
  945. 40:20Right?
  946. 40:20Noun phrase, verb, noun phrase.
  947. 40:23I'm not certain it's meaningful, unless you are in
  948. 40:25the habit of giving your furniture personal names.
  949. 40:29What's the point?
  950. 40:30Again, you can have things that are syntactically legal
  951. 40:32but not semantically meaningful, and static
  952. 40:35semantics is going to be a way of helping us decide what
  953. 40:38expressions, what pieces of code, actually have real
  954. 40:41meaning to it.
  955. 40:41All right?
  956. 40:43The last piece of it is, in addition to having static
  957. 40:47semantics, we have sort of full semantics.
  958. 40:53Which is, what does the program mean?
  959. 40:58Or, said a different way, what's going to
  960. 40:59happen when I run it?
  961. 41:08That's the meaning of the expression.
  962. 41:09That's what you want.
  963. 41:10All right?
  964. 41:10You want to know, what's the meaning of this piece of code?
  965. 41:13When I run it, what's going to happen?
  966. 41:14That's what I want to build.
  967. 41:16The reason for pulling this out is, what you're going to
  968. 41:18see is, that in most languages, and certainly in
  969. 41:21Python-- we got lots of help here-- all right, Python comes
  970. 41:29built-in with something that will check your static, sorry,
  971. 41:31your syntax for you.
  972. 41:33And in fact, as a sidebar, if you turn in a problem set that
  973. 41:37is not syntactically correct, there's a simple button that
  974. 41:40you push that will check your syntax.
  975. 41:42If you've turned in a program that's not syntactically
  976. 41:44correct, the TAs give you a zero.
  977. 41:46Because it said you didn't even take the time to make
  978. 41:48sure the syntax is correct.
  979. 41:49The system will help you find it.
  980. 41:50In Python, it'll find it, I think one bug at
  981. 41:53a time, right John?
  982. 41:53It finds one syntax error at a time, so you have to be a
  983. 41:55little patient to do it, but you can check that
  984. 41:57the syntax is right.
  985. 41:59You're going to see that we get some help here on the
  986. 42:06static semantics, and I'm going to do an example in a
  987. 42:08second, meaning that the system, some languages are
  988. 42:11better than others on it, but it will try and help you catch
  989. 42:15some things that are not semantically correct
  990. 42:20statically.
  991. 42:21In the case of Python, it does that I think all at run time.
  992. 42:23I'm looking to you again, John, I think there's no
  993. 42:26pre-time checks.
  994. 42:27Its-- sorry?
  995. 42:27PROFESSOR JOHN GUTTAG: [UNINTELLIGIBLE]
  996. 42:28PROFESSOR ERIC GRIMSON: There is some.
  997. 42:31OK.
  998. 42:32Most of them, I think though, are primarily caught at run
  999. 42:35time, and that's a little bit of a pain because you don't
  1000. 42:36see it until you go and run the code, and there are some,
  1001. 42:38actually we're going to see an example I think in a second
  1002. 42:40where you find it, but you do get some help there.
  1003. 42:43The problem is, things that you catch here are actually
  1004. 42:47the least worrisome bugs.
  1005. 42:49They're easy to spot, you can't run the program with
  1006. 42:52them there, so you're not going to get weird answers.
  1007. 42:55Not everything is going to get caught in
  1008. 42:58static semantics checking.
  1009. 42:59Some things are going to slide through, and
  1010. 43:00that's actually a bother.
  1011. 43:03It's a problem.
  1012. 43:04Because it says, your program will still give you a value,
  1013. 43:07but it may not be what you intended, and you can't always
  1014. 43:10tell, and that may propagate it's way down through a whole
  1015. 43:12bunch of other computations before it causes some
  1016. 43:14catastrophic failure.
  1017. 43:16So actually, the problem with static semantics is you'd like
  1018. 43:19it to catch everything, you don't always get it.
  1019. 43:21Sadly we don't get much help here.
  1020. 43:23Which is where we'd like it.
  1021. 43:25But that's part of your job.
  1022. 43:27OK.
  1023. 43:27What happens if you actually have something that's both
  1024. 43:30syntactically correct, and appears to have correct static
  1025. 43:32semantics, and you run it?
  1026. 43:33It could run and give you the right answer, it could crash,
  1027. 43:37it could loop forever, it could run and apparently give
  1028. 43:43you the right answer.
  1029. 43:45And you're not always going to be able to tell.
  1030. 43:47Well, you'll know when it crashes, that doesn't help you
  1031. 43:49very much, but you can't always tell whether
  1032. 43:51something's stuck in an infinite loop or whether it's
  1033. 43:52simply taking a long time to compute.
  1034. 43:54You'd love to have a system that spots that for you, but
  1035. 43:57it's not possible.
  1036. 43:58And so to deal with this last one, you
  1037. 44:00need to develop style.
  1038. 44:02All right?
  1039. 44:06Meaning, we're going to try to help you with how to develop
  1040. 44:09good programming style, but you need to write in a way in
  1041. 44:12which it is going to be easy for you to spot the places
  1042. 44:15that cause those semantic bugs to occur.
  1043. 44:19All right.
  1044. 44:20If that sounds like a really long preamble, it is.
  1045. 44:23Let's start with Python.
  1046. 44:24But again, my goal here is to let you see what computation's
  1047. 44:28about, why we need to do it, I'm going to remind you one
  1048. 44:30last time, our goal is to be able to have a set of
  1049. 44:32primitives that we combine into complex expressions,
  1050. 44:35which we can then abstract to treat as primitives, and we
  1051. 44:38want to use that sequence of instructions in this flow of
  1052. 44:43control computing, in order to deduce new information.
  1053. 44:47That imperative knowledge that we talked about right there.
  1054. 44:50So I'm going to start today, we have about five or ten
  1055. 44:52minutes left, I think, in order-- sorry, five minutes
  1056. 44:54left-- in order to do this with some beginnings of
  1057. 44:56Python, and we're going to pick this up obviously, next
  1058. 44:58time, so; simple parts of Python.
  1059. 45:02In order to create any kinds of expressions, we're going to
  1060. 45:04need values.
  1061. 45:06Primitive data elements.
  1062. 45:07And in Python, we have two to start with; we have numbers,
  1063. 45:13and we have strings.
  1064. 45:16Numbers is what you'd expect.
  1065. 45:18There's a number.
  1066. 45:21There's another number.
  1067. 45:21All right?
  1068. 45:24Strings are captured in Python with an open quote and some
  1069. 45:28sequence of characters followed by a closed quote.
  1070. 45:33Associated with every data type in Python is a type,
  1071. 45:37which identifies the kind of thing it is.
  1072. 45:40Some of these are obvious.
  1073. 45:41Strings are just a type on their own.
  1074. 45:44But for numbers, for example, we can have
  1075. 45:46a variety of types.
  1076. 45:47So this is something that we would call an
  1077. 45:49integer, or an INT.
  1078. 45:50And this is something we would call a
  1079. 45:54floating point, or a float.
  1080. 45:57Or if you want to think of it as a real number.
  1081. 45:59And there's some others that we can see.
  1082. 46:01We're going to build up this taxonomy if you like, but the
  1083. 46:04reason it's relevant is, associated with each one of
  1084. 46:07those types is a set of operators that expect certain
  1085. 46:11types of input in order to do their job.
  1086. 46:13And given those types of input, will get back output.
  1087. 46:16All right.
  1088. 46:17In order to deal with this, let me show you an example,
  1089. 46:19and I hope that comes up, great.
  1090. 46:21What I have here is a Python shell, and I'm going to just
  1091. 46:25show you some simple examples of how we start building
  1092. 46:27expressions.
  1093. 46:28And this'll lead into what you're going to see next time
  1094. 46:30as well as what you're going to do tomorrow.
  1095. 46:32So.
  1096. 46:33Starting with the shell, I can type in expressions.
  1097. 46:37Actually, let me back up and do this in video.
  1098. 46:38I can type in a number, I get back a number, I can type in a
  1099. 46:42string, I get back the string.
  1100. 46:46Strings, by the way, can have spaces in them, they can have
  1101. 46:49other characters, it's simply a sequence of things, and
  1102. 46:52notice, by the way, that the string five-- sorry, the
  1103. 46:59string's digit five digit two is different
  1104. 47:02than the number 52.
  1105. 47:03The quotes are around them to make that distinction.
  1106. 47:05We're going to see why in a second.
  1107. 47:07What I'm doing, by the way, here is I'm simply typing in
  1108. 47:09expressions to that interpreter.
  1109. 47:11It's using its set of rules to deduce the value and print
  1110. 47:13them back out.
  1111. 47:15Things I might like to do in here is, I might like to do
  1112. 47:17combinations of things with these.
  1113. 47:19So we have associated with simple things, a set of
  1114. 47:23operations.
  1115. 47:27So for numbers, we have the things you'd expect, the
  1116. 47:32arithmetics.
  1117. 47:33And let me show you some examples of that.
  1118. 47:35And actually, I'm going to do one other distinction here.
  1119. 47:38What I typed in, things like-- well, let me start this way--
  1120. 47:42there's an expression.
  1121. 47:44And in Python the expression is, operand, operator,
  1122. 47:48operand, when we're doing simple expressions like this,
  1123. 47:51and if I give it to the interpreter, it gives me back
  1124. 47:53exactly what you'd expect, which is that value.
  1125. 47:56OK?
  1126. 47:57The distinction I'm going to make is, that's an expression.
  1127. 47:59The interpreter is going to get a value for it.
  1128. 48:01When we start building up code, we're
  1129. 48:03going to use commands.
  1130. 48:04Or statements.
  1131. 48:05Which are actually things that take in a value and ask the
  1132. 48:08computer to do something with it.
  1133. 48:09So I can similarly do this, which is going to look strange
  1134. 48:13because it's going to give me the same value back out, but
  1135. 48:16it actually did a slightly different thing.
  1136. 48:17And notice, by the way, when I typed it how print showed up
  1137. 48:19in a different color?
  1138. 48:21That's the Python saying, that is a command, that is a
  1139. 48:24specific command to get the value of the expression and
  1140. 48:26print it back out.
  1141. 48:27When we start writing code, you're going to see that
  1142. 48:29difference, but for now, don't worry about it, I just want to
  1143. 48:31plant that idea.
  1144. 48:33OK.
  1145. 48:33Once we've got that, we can certainly, though,
  1146. 48:35do things like this.
  1147. 48:39Notice the quotes around it.
  1148. 48:42And it treats it as a string, it's simply getting me back
  1149. 48:44the value of that string, 52 times 7, rather than
  1150. 48:47the value of it.
  1151. 48:49Now, once we've got that, we can start doing things.
  1152. 48:52And I'm going to use print here-- if I could type, in
  1153. 48:53order to just to get into that, I can't type, here we
  1154. 48:55go-- in order to get into the habit.
  1155. 48:57I can print out a string.
  1156. 49:00I can print out--
  1157. 49:07Ah!--
  1158. 49:09Here's a first example of something that
  1159. 49:10caught one of my things.
  1160. 49:11This is a static semantic error.
  1161. 49:15So what went on here?
  1162. 49:16I gave it an expression that had an operand in there.
  1163. 49:18It expected arithmetic types.
  1164. 49:21But I gave two strings.
  1165. 49:23And so it's complaining at me, saying, you can't do this.
  1166. 49:26I don't know how to take two strings and
  1167. 49:27multiply them together.
  1168. 49:30Unfortunately-- now John you may disagree with me on this
  1169. 49:32one-- unfortunately in Python you can, however,
  1170. 49:34do things like this.
  1171. 49:37What do you figure that's going to do?
  1172. 49:39Look legal?
  1173. 49:41The string three times the number three?
  1174. 49:45Well it happens to give me three threes in a row.
  1175. 49:49I hate this.
  1176. 49:50I'm sorry, John, I hate this.
  1177. 49:51Because this is overloading that multiplication operator
  1178. 49:55with two different tasks.
  1179. 49:56It's saying, if you give me two numbers, I'll
  1180. 49:57do the right thing.
  1181. 49:58If you give me a number and a string, I'm going to
  1182. 50:00concatenate them together, it's really different
  1183. 50:02operations, but nonetheless, it's what it's going to do.
  1184. 50:05STUDENT: [UNINTELLIGIBLE]
  1185. 50:11PROFESSOR ERIC GRIMSON: There you go.
  1186. 50:12You know, there will be a rebuttal phase a little later
  1187. 50:14on, just like with the political debates, and he
  1188. 50:16likes it as a feature, I don't like it, you can tell he's not
  1189. 50:18a Lisp programmer and I am.
  1190. 50:20All right.
  1191. 50:21I want to do just a couple more quick examples.
  1192. 50:22Here's another one.
  1193. 50:23Ah-ha!
  1194. 50:24Give you an example of a syntax error.
  1195. 50:28Because 52A doesn't make sense.
  1196. 50:31And you might say, wait a minute, isn't that a string,
  1197. 50:32and the answer's no, I didn't say it's a string by putting
  1198. 50:34quotes around it.
  1199. 50:35And notice how the machine responds differently to it.
  1200. 50:38In this case it says, this is a syntax error, and it's
  1201. 50:41actually highlighting where it came from so I can go
  1202. 50:43back and fix it.
  1203. 50:44All right.
  1204. 50:45Let's do a couple of other simple examples.
  1205. 50:48All right?
  1206. 50:49I can do multiplication.
  1207. 50:50I've already seen that.
  1208. 50:51I can do addition.
  1209. 50:52Three plus five.
  1210. 50:54I can take something to a power, double star, just take
  1211. 50:58three to the fifth power.
  1212. 50:59I can do division, right?
  1213. 51:03Whoa.
  1214. 51:04Right?
  1215. 51:05Three divided by five is zero?
  1216. 51:08Maybe in Bush econom-- no, I'm not going to do any political
  1217. 51:10comments today, I will not say that, all right?
  1218. 51:12What happened?
  1219. 51:14Well, this is one of the places where
  1220. 51:15you have to be careful.
  1221. 51:16It's doing integer division.
  1222. 51:19So, three divided by five is zero, with a
  1223. 51:22remainder of three.
  1224. 51:23So this is the correct answer.
  1225. 51:24If I wanted to get full, real division, I should make one of
  1226. 51:28them a float.
  1227. 51:30And yes, you can look at that and say, well is that right?
  1228. 51:32Well, up to some level of accuracy, yeah, that's .6 is
  1229. 51:35what I'd like to get out.
  1230. 51:36All right.
  1231. 51:38I can do other things.
  1232. 51:40In a particular, I have similar operations on strings.
  1233. 51:46OK, I can certainly print out strings, but I can actually
  1234. 51:48add strings together, and just as you saw, I can multiply
  1235. 51:51strings, you can kind of guess what this is going to do.
  1236. 51:53It is going to merge them together into one thing.
  1237. 51:58I want--
  1238. 51:59I know I'm running you slightly over, I want to do
  1239. 52:00one last example, it's, I also want to be able to do, have
  1240. 52:03variables to store things.
  1241. 52:05And to do that, in this it says, if I have a value, I
  1242. 52:11want to keep it around, to do that, I can
  1243. 52:12do things like this.
  1244. 52:20What does that statement do?
  1245. 52:21It says, create a name for a variable-- which I just did
  1246. 52:24there, in fact, let me type it in-- mystring, with an equal
  1247. 52:28sign, which is saying, assign or bind to that name the value
  1248. 52:32of the following expression.
  1249. 52:35As a consequence, I can now refer to
  1250. 52:37that just by its name.
  1251. 52:39If I get the value of mystring, there it is, or if I
  1252. 52:43say, take mystring and add to it the string, mylastname, and
  1253. 52:49print it back out.
  1254. 52:51So this is the first start of this.
  1255. 52:53What have we done?
  1256. 52:54We've got values, numbers and strings.
  1257. 52:57We have operations to associate with them.
  1258. 52:59I just threw a couple up here.
  1259. 53:00You're going to get a chance to explore them, and you'll
  1260. 53:02see not only are there the standard numerics for strings,
  1261. 53:04there are things like length or plus or other things you
  1262. 53:06can do with them.
  1263. 53:08And once I have values, I want to get a hold of them so I can
  1264. 53:10give them names.
  1265. 53:11And that's what I just did when I bound that.
  1266. 53:12I said, use the name mystring to be bound to or have the
  1267. 53:16value of Eric, so I can refer to it anywhere else that I
  1268. 53:19want to use it.
  1269. 53:20And I apologize for taking you over, we'll come back to this
  1270. 53:23next time, please go to the website to sign up for
  1271. 53:25recitation for tomorrow.

About this transcript

This page contains the full transcript of Lec 1 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008 by MIT OpenCourseWare, generated from the public captions YouTube serves with the video. The transcript has 9,783 words across 1,271 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.