1 00:00:00,000 --> 00:00:00,600 2 00:00:00,600 --> 00:00:01,450 - All right. 3 00:00:01,450 --> 00:00:05,290 so, let's go ahead now and make a transition in code. 4 00:00:05,290 --> 00:00:09,880 - So much like our transition from scratch to C 5 00:00:09,880 --> 00:00:11,950 and ultimately C to JavaScript. 6 00:00:11,950 --> 00:00:15,310 So with C to Python, I decided to take the approach of trying 7 00:00:15,310 --> 00:00:17,500 to map one language to another. 8 00:00:17,500 --> 00:00:20,170 Give students a representative example of a construct in C, 9 00:00:20,170 --> 00:00:23,322 whether it's a function, or a loop, or condition, or a variable. 10 00:00:23,322 --> 00:00:25,030 And then show them the equivalent Python. 11 00:00:25,030 --> 00:00:29,290 So much like in Scratch, they're reassured that the idea is the same, 12 00:00:29,290 --> 00:00:32,439 but now you have a colon and you have fewer parentheses and no semi-colon 13 00:00:32,439 --> 00:00:34,040 and you really have to indent. 14 00:00:34,040 --> 00:00:36,810 But it's not a big deal, is the point at least, of that. 15 00:00:36,810 --> 00:00:40,389 And what I found hopefully was helpful too in explaining this, 16 00:00:40,389 --> 00:00:42,430 or at least as helpful for the way my mind works, 17 00:00:42,430 --> 00:00:44,596 is to actually pull up some representative examples. 18 00:00:44,596 --> 00:00:46,720 Not just of lines of code, but whole programs, 19 00:00:46,720 --> 00:00:48,749 and import them from C to Python. 20 00:00:48,749 --> 00:00:51,540 So that one, students ideally already know how the C version works. 21 00:00:51,540 --> 00:00:54,340 So there's no cognitive barrier there. 22 00:00:54,340 --> 00:00:57,960 Now it's really just a syntactic translation of one to the other. 23 00:00:57,960 --> 00:01:03,370 - So it's certainly nice then to have that corpus of demos ready at hand. 24 00:01:03,370 --> 00:01:06,087 all of our lecturers come with a zip of all of the source 25 00:01:06,087 --> 00:01:07,420 files that you show and lecture. 26 00:01:07,420 --> 00:01:10,630 And so we can just take those and immediately transform them into Python. 27 00:01:10,630 --> 00:01:12,670 - And it's a very safe way, I think, of exploring a new language. 28 00:01:12,670 --> 00:01:15,580 Even for me it was enlightening to just take the C example and then figure out, 29 00:01:15,580 --> 00:01:19,130 all right here's the solution literally on the left, how do we now on the right 30 00:01:19,130 --> 00:01:20,470 re-implement this in Python. 31 00:01:20,470 --> 00:01:22,330 And it's an opportunity to read up on a language, 32 00:01:22,330 --> 00:01:24,550 figure out how I can do things a little more elegantly, 33 00:01:24,550 --> 00:01:26,883 maybe Python really can tighten some of those things up. 34 00:01:26,883 --> 00:01:30,940 Because you can you have some nice constructs like for...in for instance. 35 00:01:30,940 --> 00:01:32,750 And so that was helpful exercise I thought. 36 00:01:32,750 --> 00:01:35,320 - And super impactful is the ability in CS50 IDE 37 00:01:35,320 --> 00:01:38,319 to actually have a split window to show it literally side by side, 38 00:01:38,319 --> 00:01:40,360 as opposed to jumping back and forth between them 39 00:01:40,360 --> 00:01:43,810 or showing them on a PowerPoint slide, which is what we've done before. 40 00:01:43,810 --> 00:01:44,590 - I agree. 41 00:01:44,590 --> 00:01:46,540 And hopefully students found this helpful too for pset 6. 42 00:01:46,540 --> 00:01:49,331 Since beyond the sentiment analysis and the ML part of that problem 43 00:01:49,331 --> 00:01:53,600 set did we have students reimplement Mario and/or Caesar or Visionaire 44 00:01:53,600 --> 00:01:54,910 or Crack, and so forth. 45 00:01:54,910 --> 00:01:57,340 And there too, I feel like that's a very comfortable space 46 00:01:57,340 --> 00:01:59,589 to be in because, hey, you already have your solution, 47 00:01:59,589 --> 00:02:01,714 whether it's yours or ours that we made available. 48 00:02:01,714 --> 00:02:04,630 All you have to do is figure out now how to map this to a new language 49 00:02:04,630 --> 00:02:07,630 and you have the entirety of Google and the web at your disposal, 50 00:02:07,630 --> 00:02:09,500 as well as the lessons learned from class. 51 00:02:09,500 --> 00:02:12,125 So hopefully that's a nice way of sort of bootstrapping oneself 52 00:02:12,125 --> 00:02:16,030 to enough comfort to then bite off something like sentiment analysis. 53 00:02:16,030 --> 00:02:20,311 - Now Python, as a language, has much better I/O capabilities than C, 54 00:02:20,311 --> 00:02:21,310 at least out of the box. 55 00:02:21,310 --> 00:02:24,160 So what motivated, nonetheless, we saw a little bit 56 00:02:24,160 --> 00:02:26,871 earlier porting the library to Python. 57 00:02:26,871 --> 00:02:27,370 - Yeah. 58 00:02:27,370 --> 00:02:30,119 It was a good question and it was kind of a toss up because Python 59 00:02:30,119 --> 00:02:32,890 has a nice input function that will just get you 60 00:02:32,890 --> 00:02:34,780 user input, much like getString. 61 00:02:34,780 --> 00:02:37,570 But I wanted to actually return a specific data type, much 62 00:02:37,570 --> 00:02:43,270 like we did with C. And I also wanted there to be really a one to one 63 00:02:43,270 --> 00:02:46,840 mapping for those early conversions, those warm up exercises where 64 00:02:46,840 --> 00:02:50,240 you don't have to figure out how getString and getInt and getFloat 65 00:02:50,240 --> 00:02:51,130 and so forth work. 66 00:02:51,130 --> 00:02:55,540 We actually want to just port those, literally, over to the equivalence. 67 00:02:55,540 --> 00:02:58,030 Plus for some of our teachers online, especially 68 00:02:58,030 --> 00:03:00,280 in CS50 AP who might be using Python even more, 69 00:03:00,280 --> 00:03:02,505 it's just nice to be able to hand students 70 00:03:02,505 --> 00:03:05,380 a library with which they can even do earlier portions of the course, 71 00:03:05,380 --> 00:03:06,100 but in Python. 72 00:03:06,100 --> 00:03:08,620 So just having that in our toolkit felt compelling, 73 00:03:08,620 --> 00:03:11,710 even though we very quickly abandoned it deliberately 74 00:03:11,710 --> 00:03:13,780 for later in that same piece set. 75 00:03:13,780 --> 00:03:18,060 - I suppose even on its own it it allows us to introduce the equivalent of pound 76 00:03:18,060 --> 00:03:19,510 include with Python's import. 77 00:03:19,510 --> 00:03:20,020 - Indeed. 78 00:03:20,020 --> 00:03:22,952 There's a nice mapping to that as well. 79 00:03:22,952 --> 00:03:23,452