- All right.
so, let's go ahead now and make a transition in code.
- So much like our transition from scratch to C
and ultimately C to JavaScript.
So with C to Python, I decided to take the approach of trying
to map one language to another.
Give students a representative example of a construct in C,
whether it's a function, or a loop, or condition, or a variable.
And then show them the equivalent Python.
So much like in Scratch, they're reassured that the idea is the same,
but now you have a colon and you have fewer parentheses and no semi-colon
and you really have to indent.
But it's not a big deal, is the point at least, of that.
And what I found hopefully was helpful too in explaining this,
or at least as helpful for the way my mind works,
is to actually pull up some representative examples.
Not just of lines of code, but whole programs,
and import them from C to Python.
So that one, students ideally already know how the C version works.
So there's no cognitive barrier there.
Now it's really just a syntactic translation of one to the other.
- So it's certainly nice then to have that corpus of demos ready at hand.
all of our lecturers come with a zip of all of the source
files that you show and lecture.
And so we can just take those and immediately transform them into Python.
- And it's a very safe way, I think, of exploring a new language.
Even for me it was enlightening to just take the C example and then figure out,
all right here's the solution literally on the left, how do we now on the right
re-implement this in Python.
And it's an opportunity to read up on a language,
figure out how I can do things a little more elegantly,
maybe Python really can tighten some of those things up.
Because you can you have some nice constructs like for...in for instance.
And so that was helpful exercise I thought.
- And super impactful is the ability in CS50 IDE
to actually have a split window to show it literally side by side,
as opposed to jumping back and forth between them
or showing them on a PowerPoint slide, which is what we've done before.
- I agree.
And hopefully students found this helpful too for pset 6.
Since beyond the sentiment analysis and the ML part of that problem
set did we have students reimplement Mario and/or Caesar or Visionaire
or Crack, and so forth.
And there too, I feel like that's a very comfortable space
to be in because, hey, you already have your solution,
whether it's yours or ours that we made available.
All you have to do is figure out now how to map this to a new language
and you have the entirety of Google and the web at your disposal,
as well as the lessons learned from class.
So hopefully that's a nice way of sort of bootstrapping oneself
to enough comfort to then bite off something like sentiment analysis.
- Now Python, as a language, has much better I/O capabilities than C,
at least out of the box.
So what motivated, nonetheless, we saw a little bit
earlier porting the library to Python.
- Yeah.
It was a good question and it was kind of a toss up because Python
has a nice input function that will just get you
user input, much like getString.
But I wanted to actually return a specific data type, much
like we did with C. And I also wanted there to be really a one to one
mapping for those early conversions, those warm up exercises where
you don't have to figure out how getString and getInt and getFloat
and so forth work.
We actually want to just port those, literally, over to the equivalence.
Plus for some of our teachers online, especially
in CS50 AP who might be using Python even more,
it's just nice to be able to hand students
a library with which they can even do earlier portions of the course,
but in Python.
So just having that in our toolkit felt compelling,
even though we very quickly abandoned it deliberately
for later in that same piece set.
- I suppose even on its own it it allows us to introduce the equivalent of pound
include with Python's import.
- Indeed.
There's a nice mapping to that as well.