Latest / Talk Python To Me / #22: CPython Internals and Learning Python with pythontutor.com
Transcript
- 0:00It's time to look deep within the machine and understand what really happens when your Python code executes.
- 0:06We're code walking through the CPython code base and visualizing it at pythontutor.com.
- 0:11This is episode number 22 with Philip Guau, recorded Monday, August 3rd, 2015.
- 0:17Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the
- 0:47ecosystem, and the personalities.
- 0:49This is your host, Michael Kennedy.
- 0:51Follow me on Twitter where I'm @mkennedy, and keep up with the show and listen to past
- 0:56episodes at talkpython.fm.
- 0:58Be sure to follow the show on Twitter where it's at talkpython.
- 1:02This episode is brought to you by Hired and CodeChip.
- 1:06Thank them both for supporting the show on Twitter via at HiredHQ and at CodeChip.
- 1:11Now let me introduce Philip.
- 1:14Philip Guau is an assistant professor of computer science at the University of Rochester in New York.
- 1:19He researches human-computer interactions with a focus on user interfaces for online learning.
- 1:24He's especially interested in studying how to better train software engineers and data scientists.
- 1:30He created a free web-based visualization tool for learning programming called Online Python Tutor
- 1:35at pythontutor.com, which has been used by over 1.2 million people in over 165 countries to visualize over 11 million pieces of code.
- 1:45Philip, welcome to the show.
- 1:46My pleasure.
- 1:48Yeah, it's really exciting to have you here.
- 1:50We're going to talk a lot about many things.
- 1:53We're going to talk about CPython and a really cool project that you put on your website and on YouTube called CPython, a 10-hour code walk.
- 2:02And so we'll be digging into CPython.
- 2:04And we're also going to talk about this thing called Python Tutor at pythontutor.com that you are working to help people understand the internals of Python better.
- 2:12So that's going to be great stuff.
- 2:14Cool.
- 2:14I'm looking forward to it.
- 2:16Yeah.
- 2:16Before we get into the details, though, you know, everyone likes to know how people got into programming and how they got started in Python.
- 2:22What's your story?
- 2:23So my story was I was always interested in computers as a kid, like many people who got into computer science.
- 2:29But I never really had a strong programming background until I went to college.
- 2:34So I tried to learn QBasic by myself when I was 10.
- 2:39And that, you know, I had a book and then I failed after a few weeks because I had no one teaching me.
- 2:43I took an AP computer science course in high school.
- 2:46That was in C++.
- 2:46And that was really fun.
- 2:48And that was kind of my first introduction to really doing programming.
- 2:52And in college, I decided to major in electrical engineering and computer science.
- 2:57And that's when I started just learning programming formally.
- 3:01But really, the Python relevance is I didn't actually start hacking for fun until my about my senior year of college.
- 3:09And the first language that I learned for programming for fun and not just because I had to do it for class was actually Python.
- 3:15So the first kinds of programs I wrote were scripts to manage my photos and, you know, kind of manipulate and manage my own personal photo gallery and, you know, put it up on a simple website.
- 3:28So that was where I got started getting hooked on Python.
- 3:30That was, you know, it was about 10 years ago.
- 3:32That was around 2005.
- 3:33That was like Python 2.4 or something like that.
- 3:36Yeah, that's a great way to get started.
- 3:38I think a lot of people have interesting stories like that, you know, just they have some small problem they're trying to solve.
- 3:44And, you know, it leads you down this path.
- 3:47And all of a sudden, you discover this world where, hey, there's this great thing, you know, programming or Python or whatever.
- 3:52Yep, that's exactly right.
- 3:54So I see you're calling in from Seattle, right?
- 3:57What are you doing up there?
- 3:58So I am currently an assistant professor of computer science at the University of Rochester in upstate New York.
- 4:05So that's nowhere near Seattle.
- 4:06That's what I was going to say.
- 4:07You're not – it's not at all in Seattle.
- 4:08So I get to – one of the real benefits of being a professor is that your summers are free to do research or to travel or to do other sorts of scholarly work.
- 4:19So most professors in most terms, they stay on campus in the summers and they do research full time for three months.
- 4:27What I decided to do this summer since I had some colleagues at Microsoft was to spend most of my summer at Microsoft Research doing research and both in software engineering and in online education at the lab in Seattle.
- 4:41And I came here because I actually was an intern here a long time ago when I was back in grad school.
- 4:47So I'm actually back interning in the same group.
- 4:49So it's sort of a homecoming of sorts.
- 4:51Back to the future.
- 4:52That's excellent.
- 4:53Yeah, I've done some work with some of the guys up at Microsoft.
- 4:55It's a cool place up there.
- 4:57So excellent.
- 4:57Is this related to PythonTutor.com?
- 5:00No, not really.
- 5:01I mean, this is just a completely separate sort of research project.
- 5:04So there's nothing Python related in the work here, unfortunately.
- 5:08All right.
- 5:09Cool.
- 5:10All right.
- 5:11So let's talk about your CPython internals class.
- 5:16This was a class you did at University of Rochester, right?
- 5:192014, I think.
- 5:21At least the recorded version was 2014.
- 5:23Yep.
- 5:24So this was a class I taught in fall 2014.
- 5:27And the name of the course was Dynamic Languages and Software Development.
- 5:32So I actually inherited this course from another professor who was taking a leave and teaching another class that term.
- 5:41And that class was originally in Ruby.
- 5:43So it was sort of a graduate level programming languages class about these sorts of dynamically type languages.
- 5:48And originally he did it in Ruby.
- 5:50But since I knew Python a lot better, I revamped the class to be in Python and basically turned it into what the videos are online.
- 5:59So I'd be happy to talk about that in detail.
- 6:02Just for everyone listening, the videos are online.
- 6:05And I actually spent like the last week going through your class.
- 6:08So I feel like I've had like some super intense summer course or something, you know, doing like 10 lectures.
- 6:14And people can find those on your website at pgbovine.net slash cpython dash internals dot htm.
- 6:21And I actually went through, unrelated to this conversation or maybe preceding this whole having you on the show, I just saw your videos and thought they were awesome.
- 6:30And I put them into a YouTube playlist at bit.ly slash cpython walk.
- 6:34So both of those work well.
- 6:35What was the main goal of the class?
- 6:38Sort of get people to understand what happens when you actually run dynamic code like Python?
- 6:43Yeah, I think that was basically that was basically a philosophy.
- 6:48So a lot of programming languages classes are taught from more of a theoretical perspective.
- 6:54Right.
- 6:54So it's usually kind of some formal syntax and semantics and maybe doing some proofs.
- 7:01And it's very, you know, kind of a formalism heavy.
- 7:04And I thought it would be interesting to do a very different sort of class for graduate students from the opposite side, which is something extremely applied to saying, you know, here is a here is a piece of Python code.
- 7:15Let's start with hello world or a simple for loop or a simple function call.
- 7:20And what actually happens throughout all the steps between that code being parsed and then the output appearing on your screen, let's say.
- 7:29So I wanted to dive into the interpreter and show students how everything worked under the hood and how there's really, you know, by deconstructing, you can show that there's really no magic here.
- 7:39There's just a lot of C code behind the scenes that keeps track of a lot of stuff.
- 7:43And eventually your program runs.
- 7:45So we don't do the parsing stage because I think parsing is fairly standard.
- 7:50And that's covered by most kind of introductory compilers classes.
- 7:54You write a grammar and parser generator and some code gives you a like an AST.
- 8:00And then that gets walked to turn into some kind of bytecode.
- 8:04So the class actually starts with assuming you have a bunch of Python bytecode.
- 8:07How does the bytecode actually get interpreted step by step by the by the interpreter runtime system to do your your programs operations?
- 8:16Yeah, that's really cool.
- 8:17And I think, you know, if I think about how like C code runs and then my intuition about how that C code actually executes, if you understand a little bit about registers and memory addresses and pointers, your intuition more or less will carry the day.
- 8:32I think with interpreted languages, all bets are off.
- 8:36Right.
- 8:37I mean, you have some concept of the programming language doing things, but then the way that happens, you really have to look inside.
- 8:44Right.
- 8:45Yeah, exactly.
- 8:47Because the these interpret languages are often not implemented like you would conceptually think of it.
- 8:53Right.
- 8:53You think of something as you have frames and variables and pointers to each other.
- 8:57But really, these bytecodes are this sort of the Python one is sort of this stack based kind of virtual machine.
- 9:04I think Java, the Java virtual machine is that way, too, but I forgot the exact semantics.
- 9:08But it's not something you would think about normally, but they do it that way.
- 9:11One, because it's really compact and it's kind of leads to really compact code and sort of easy to understand code for the implementer.
- 9:18But yeah, but that's very different than the conceptual model in your head at the very high level, how a program ought to work.
- 9:24And we can talk about that later when we talk about the Python tutor as well, because that kind of leads into that other tool.
- 9:30So we can keep talking about the CPython stuff first.
- 9:32Sure. So one of the things I thought was interesting was in your very first session, you did you have kind of a cool whiteboarding thing you're doing with a Microsoft Surface and like a pen where you can kind of draw on the code.
- 9:43And that's cool.
- 9:44You do a cool little sketch about what actually happens when you type Python space some file that py.
- 9:50And I mean, on one level, I knew it.
- 9:54On the other, it was a little surprising to me to say.
- 9:56And the first step is compilation.
- 9:58Can you maybe like talk just briefly about like what happens when I run my Python code before we get into the interpreter itself?
- 10:05Yeah.
- 10:06So many people are surprised when there's a compilation step in Python or in these sorts of dynamic or what people call scripting languages, because usually you think of running Python space, whatever, or Perl space, whatever, Ruby space, whatever.
- 10:20And it just runs, right?
- 10:21Right.
- 10:22I just thought, here we go with the interpreter.
- 10:24And now it's interpreting, right?
- 10:26Right.
- 10:27So with Java or C or C#, you have a compilation step and then you run a compiled binary.
- 10:33And there's two separate steps.
- 10:34But with Python, as with many other languages, the compilation happens before the execution.
- 10:40So what happens is as a standard kind of a front end to a compiler, it takes the source code.
- 10:46It does the lexical analysis.
- 10:48It does the parsing.
- 10:49It creates a AST or abstract syntax tree from that.
- 10:52And then it walks that tree and creates a bunch of bytecode.
- 10:56So the Python bytecode language, you can read in the documentation, it has, I don't know, a few dozen operations like add, load, store, and also some operations that are a little bit more Python specific, like build a list, build a dictionary, build a tuple, function call, those sorts of things.
- 11:16So the compilation step really takes your source code, which is in human readable, somewhat human readable form, and turns it into a linear stream of instructions.
- 11:26Very much like assembly language, except you can think of bytecode as an assembly language for a Python virtual computer.
- 11:35Right. That was kind of the impression I got as well, like a much, much richer assembly language where you have operations like build class and call method, push and pop stuff off stacks and so on.
- 11:46Yep, exactly.
- 11:47If we want to go work with this, right, we can go to python.org and download the code and decompress it or untar it or whatever.
- 11:56And it's just, it literally is a bunch of C code, right?
- 11:59The C in CPython is, here's your C implementation of this interpreter, right?
- 12:03That's right.
- 12:04So if you go to, this is what I do on the first day of class.
- 12:07We have everybody download the C interpreter source code from, sorry, the CPython source code from python.org and unzip it and do configure and make.
- 12:19Now, part of the class, I didn't require students to actually run the interpreter if they didn't want,
- 12:26because most of the class was actually reading through the code and walking through it.
- 12:29Now, the students who were a bit more adventurous, they could try to compile the interpreter themselves.
- 12:34And then try to, you know, put in debug statements or print statements to see how it works behind the scenes.
- 12:40But actually, compile interpreter itself might not be easy if you're on, say, especially, say, on a Windows machine, which doesn't have a lot of development tools, compilers.
- 12:49So I'm usually on Linux and Mac machines.
- 12:51If you install the standard developer tool chain with GCC and make and configure and all that stuff.
- 12:58In theory, right, building is always hard.
- 13:01But in theory, if you do dot slash configure and then and you type make all your your you'll actually call the C compiler on your machine.
- 13:10And it will compile all the C files and the C and the H files in the CPython slash directory.
- 13:18And in the end, it will produce a binary executable file called Python.
- 13:22And that Python you can just run.
- 13:24And that is the Python interpreter that you just compiled from C source code.
- 13:29So most of the class, what we do is we go over what a lot of those C files actually do and see.
- 13:34Maybe you could give us like a 10,000 foot view of what are the interesting parts of that source code and what is just noise and details.
- 13:44So there's like objects and then there's include there's see eval dot C.
- 13:49There's there's like a few really common parts that you come back to over and over and over.
- 13:53And then there's a bunch of details.
- 13:54Yeah.
- 13:55So on the Web site with all the videos, I actually show the files that they reference.
- 14:00But really, the core file that I keep on going back to what you're saying is in Python slash C eval dot C.
- 14:08And what that is that that file at its core is the main interpreter loop.
- 14:12So conceptually, how you execute how Python executes code is a byte code is just a bunch of them.
- 14:20It's just a list of instructions.
- 14:22Each one is add or subtract or build list or function call or so forth.
- 14:28And all the interpreter does is just go through one instruction at a time, take it off the list of instructions, do something and then move to the next instruction, do something, move the instruction and then do something else.
- 14:41And it might jump around the stream of instructions if you have, say, a function call or a loop.
- 14:46But really, the main interpreter loop in C eval dot C, all it does is it's just a big, wild, true, infinite loop that just.
- 14:54Yeah, there's like a huge switch statement.
- 14:56And it is huge, right?
- 14:57That's right.
- 14:58Yeah, there's like a 3000 or whatever line switch statement.
- 15:02There's a fun fact in there.
- 15:03If you actually I don't know if it's in all the versions, but at least in some of the versions I saw, there's some kind of comment in there saying that they needed to like break up the switch statement in some weird way.
- 15:15Because some C compilers just can't take switch statements that are that big.
- 15:21So they had to actually break up the code into pieces because, you know, it wouldn't compile on some kind of computers because that code was just too giant.
- 15:28Yeah, that's pretty funny.
- 15:30It's like a 3000 line switch statement.
- 15:31It's pretty cool.
- 15:32But those are more or less the steps that have all the opcodes.
- 15:37And so if I look at Python, it's not necessarily mapping one to one the Python code I write to these opcodes, which is a good thing for Python programmers, right?
- 15:50That means you're working in a high level language.
- 15:52You're not working like down in the detail, right?
- 15:54But it also means it's hard for me to understand if I write, you know, create a class and I say, you know, T equals new test class.
- 16:01What does that actually mean?
- 16:03Like, how do I line that up?
- 16:04And so you had a cool way to disassemble that, right?
- 16:07And look at it.
- 16:37Currently, candidates receive five or more offers in just the first week and there are no obligations ever.
- 16:42Sounds pretty awesome, doesn't it?
- 16:45Well, did I mention there's a signing bonus?
- 16:47Everyone who accepts a job from Hired gets a $2,000 signing bonus.
- 16:51And as Talk Python listeners, it gets way sweeter.
- 16:55Use the link Hired.com slash Talk Python To Me and Hired will double the signing bonus to $4,000.
- 17:04Opportunity's knocking.
- 17:04Visit Hired.com slash Talk Python To Me and answer the call.
- 17:18Right, right.
- 17:19So the disassembler actually comes in the standard Python library.
- 17:25So if you do, right, so if you do Python space dash M space DIS, which runs the disk module space, the Python file name, name of Python file, I'll actually run the main function in the DIS module.
- 17:41And what that will do is I'll actually print out a somewhat human readable representation of the bytecode.
- 17:46And the cool thing about that is that it shows the line number of which line of your Python source code compiles into which bytecode.
- 17:55And as you mentioned, it's not a one-to-one mapping.
- 17:57So one line usually compiles to several bytecodes because the bytecode is at a lower level.
- 18:03So you can run that DIS command.
- 18:05And the DIS module, you can just search for, if you search on your favorite search engine for Python space DIS, you should see the documentation for this disassembler module.
- 18:16And that is in the standard library, and that gives you all of the stuff.
- 18:20So now that said, though, that only prints out the instructions.
- 18:24There was somebody who made a library called byteplay, which is B-Y-T-E-P-L-A-Y.
- 18:31And that library actually is an enhanced version of the disassembler that lets you get the disassembled bytecode into objects.
- 18:39You can actually play with it yourself.
- 18:41You can manipulate it.
- 18:42You can, you know, take it apart.
- 18:44You can analyze it.
- 18:45So this byteplay library, I haven't used it myself personally, but I know people who really like playing with it.
- 18:51Yeah, that's cool.
- 18:52A little more powerful.
- 18:53One thing about the DIS module is it's super easy to look at just sort of flat code in Python files.
- 19:02But if I want to look at the functions or I've got nested functions and classes, it's a little more work to do that, right?
- 19:07Yeah.
- 19:09So the default with the DIS module is it just disassembles the top level of your program.
- 19:15So all the top level says is that if you define a function, it'll just say function definition.
- 19:20And then what you have to do is you actually have to go inside that function and disassemble that function itself.
- 19:27So it is a little bit more hairy.
- 19:29And I don't know if byteplay handles all that out of the box, but it might.
- 19:34But the idea is that the DIS module, if you just run it by default, it will just disassemble the top level program.
- 19:39And any functions will not be disassembled automatically.
- 19:42You have to actually grab the code of those functions and go in there and call dis on that.
- 19:47So it is a little bit more tricky to do that.
- 19:50Sure.
- 19:51The other thing I thought was interesting is if I've got a function, let's say foo, in Python, I could say, what is it?
- 19:59Foo.func underscore bytecode.
- 20:03How do I – the bytecode is actually there on the function.
- 20:06And you can look at it in its encoded form, which is kind of some binary string type thing.
- 20:12And then you can also disassemble that as well, right?
- 20:15That's right.
- 20:16And that's what I think we're just leading into that.
- 20:18So the idea is that DIS itself, if you just run it, it disassembles the bytecode of the, I guess, of the top level file.
- 20:26But each function itself has its own code.
- 20:29And like you said, I think it's – it's actually different in Python 2 and 3, the name of it.
- 20:34But I think in one version it's like the function object dot func underscore code.
- 20:39The other one is just like just dot code or something like that.
- 20:43But the idea is that the code of the function just appears inside of it as a binary string of data.
- 20:50So if you actually print it out, it just looks like some garbled string.
- 20:53But if you run it through some – you can run it through some pretty printing function or through DIS.
- 20:58And it actually shows you the bytecode of the function.
- 21:01Because all a function object is that it's some context plus an actual string of bytecode that represents what the instructions are that the function is supposed to execute when you run it.
- 21:14Yeah, the other thing I thought was pretty cool is – or interesting to understand is that sort of compile step that you talk about, right?
- 21:22When I run Python My Python file, I get first like a compile step to bytecode and then the dynamic interpreted execution.
- 21:30But all those functions and stuff, that bytecode is there and ready to roll.
- 21:34It's just not kind of wired together until it gets to the interpreter, right?
- 21:39That's right.
- 21:40So you can actually compile – I think it's just the Python interpreter does the compiling and running all at the same time.
- 21:48But I think there's actually a mode in Python that you can just compile to – you can just compile the bytecode and not actually run it yet.
- 21:57I'm not sure exactly which flags are that one.
- 21:59But sometimes people actually ship pre-compiled Python bytecode instead of the source code.
- 22:06So there's – I don't know what reason people do this because you can just run the source code.
- 22:12And some people like to obfuscate their bytecode maybe, but I don't know how well that actually works because you can kind of reverse engineer it.
- 22:20But yeah, so the compile step is completely separate from the running step.
- 22:25And like you said, once you compile, it's just a bunch of – instead of a text file, a .py file, it's called, I think, a .pyo file or something.
- 22:33It's just a bunch of garbled stuff.
- 22:35And then that garbled stuff, you can just run through the interpreter and it'll do your – it'll run with your program.
- 22:40Yeah, it's really interesting to see how it's all coming together.
- 22:45What do you think some of the main reasons for studying Python at this level are?
- 22:49Like how does it make you a better programmer, do you think?
- 22:51That's a great question.
- 22:54I think that studying Python at this level of the implementation level, it kind of makes you – I feel like it makes you a better programmer in that you kind of, one, build a really good mental model of what goes on behind the scenes.
- 23:09And you see that these languages are just tools made by people.
- 23:14I think there's something really powerful in that.
- 23:15I feel this is a very kind of systems perspective of programming.
- 23:20So one analogy is that why do people study, say, operating systems or study compilers?
- 23:26That's a good example.
- 23:27Like the kind of classic thing in college is that a lot of people have to take an operating systems course where they build a very simple sort of OS kernel in C and maybe some assembly.
- 23:39And their kernel kind of runs and it does a simple hello world.
- 23:42Or you do a compilers course where you build a compiler using some basic building blocks.
- 23:49And the idea there is that it's not that you're going to ever build an operating system or a compiler in real life or a new programming language.
- 23:56You're not – most people are not going to implement a new kind of programming language.
- 23:59But by studying the principles behind how it works, I feel like – I think it makes you a better programmer in that you kind of understand how large complex code bases are organized and logically broken down.
- 24:12So I view this class like you've seen with these videos as more of like a code reading or literature exercise in a way.
- 24:18Because we're actually reading through dozens of – actually not that many.
- 24:23Maybe a dozen really core complex files and seeing how they – the pieces fit together.
- 24:30So it's sort of like dissecting, you know, kind of a large piece of code.
- 24:35I think that's really interesting in its own right.
- 24:38Yeah.
- 24:39A lot of people when they're in school at least studying this stuff, it's all very – I don't know, like you said, abstract or maybe not – it's not quite what I'm looking for.
- 24:48But like it doesn't have the nitty-gritty details of the real world applied to it.
- 24:54So all the error conditions that are so bizarre and all the optimizations, you don't necessarily have to deal with that.
- 24:58And so when you do finally get to a real world complex code base, it's super hard to feel comfortable.
- 25:05And I think, you know, you kind of helped your students do that a lot in there.
- 25:08So that was cool.
- 25:08Yeah.
- 25:10I think that's – and like you mentioned, there's always a tradeoff, right?
- 25:13So even in my choice of what to cover in this class, if you notice, I only cover maybe a dozen or so files.
- 25:19I mean, the Python code base has hundreds or thousands of source code files.
- 25:24And obviously, I don't have – one, I don't have time to cover all that.
- 25:27And two, I feel like this dozen is really the conceptual core of the interpreter.
- 25:31A lot of the files are just modules, right?
- 25:33A lot of the files are just like here's how strings are implemented.
- 25:37Here's how, you know, the socket class is implemented.
- 25:41Here's how, you know, memory mapped iOS is implemented.
- 25:43Those are all, I feel, auxiliary things.
- 25:45But whereas the core thing is, you know, what is an object?
- 25:48What is, you know, a class?
- 25:50What is a function?
- 25:51What is the interpreter?
- 25:52So – and even as you notice from watching the videos, I don't go over every single line in excruciating detail.
- 25:58I basically gloss over things and say, look, this block happens if there's some kind of error.
- 26:02You run out of memory.
- 26:03So, you know, look at that in spare time.
- 26:05Exactly.
- 26:05But here's like conceptually what happens.
- 26:07So, it is a balance of, you know, exposing students to the nitty-gritty, like you said, but also not too nitty-gritty because there's so much complexity in the code that isn't core to the lessons in the class.
- 26:20So, it's a balance.
- 26:21Yeah.
- 26:22A lot of times as programmers, we are – to be effective, we have to kind of zoom in, look at the tree, zoom out, look at the forest, zoom back in on another tree, zoom back in.
- 26:31And that skill of like in and out is pretty awesome.
- 26:34We talked about the opcodes.
- 26:36That's one – and that eval C – cEval.c function or class where it has the main eval loop running around and around.
- 26:44That's one of the main architectural pieces of CPython.
- 26:48Another one was – that struck me was everything is this type of C object called pi object.
- 26:55Yep.
- 26:56Everything is a pi object, right?
- 26:58Pretty much.
- 27:00So, numbers, strings, custom classes, those all kind of make sense.
- 27:06But even the class definition itself, functions, methods.
- 27:11So, that was really interesting to me.
- 27:14And then we have derivatives of those, like things that have pi object kind of as their base class, like pi int object for int, pi list object for lists, and so on.
- 27:24But C is not an object-oriented language.
- 27:28So, how does that work?
- 27:29Right.
- 27:30So, like you mentioned, the pi object structure, I guess, in C is the base of how everything is implemented.
- 27:39All the objects are implemented in Python.
- 27:41And what that contains is – that contains actually really few sorts of basic data.
- 27:47And I think the most basic, I'm trying to remember off the top of my head, is one is a reference count of how many pointers are pointing to this object at once.
- 27:55And it's because Python implements garbage collection by doing reference counting.
- 28:00So, if you have nobody pointing to you, then you get garbage collected and your memory gets reclaimed.
- 28:04So, everything is conceptually a subclass of pi objects.
- 28:10So, if you want to make an integer object, it's a pi in object.
- 28:13Or if you want to make a string, it's a pi string object.
- 28:15If you want to make a function object, it's a pi function object.
- 28:18And like you mentioned, C is not object-oriented language.
- 28:21So, there's no inheritance in the language.
- 28:23But really, you can fake it by basically doing what's called structural inheritance or structural subtyping.
- 28:31What that really does is it's a hack where you basically create a struct that is – where the first few elements of the struct are exactly the same as the base class.
- 28:42So, basically, the pi in object – I don't have the code in front of me.
- 28:45But the pi in object, the first whatever –
- 28:48What is it?
- 28:49Type?
- 28:50Like the class, the original type, and then the ref count like you're saying, right?
- 28:53That's right.
- 28:54So, those are the – yeah, those are the two things in pi object.
- 28:58That's right.
- 28:58So, there's a pointer to the – a tag saying what type it is.
- 29:01And then there's the number of references.
- 29:04So, every struct that represents some kind of a Python class – all the names are getting mixed up – starts with those two things.
- 29:16And the cool thing there is because if you have C code that expects a pi object star, a pi object pointer, and operates on it, it knows that the first thing it accesses in memory is the type.
- 29:29And the second thing, I think, is the reference count.
- 29:31So, all of your code will work perfectly fine if it's an in object or a long object or a string object if the function you're passing it into expects just a base class of pi objects.
- 29:42So, basically, conceptually, it's just subclassing or subtyping.
- 29:46But that's how it ends up being implemented in C.
- 29:49And, actually, how C++ does subtyping, I think, in its most basic form, is basically that.
- 29:56Because C++ is meant to be compiled to be somewhat backwards compatible with C.
- 30:01So, this idea of piling another class on top of another one structurally with the fields in the same places is a pretty classic technique.
- 30:09Yeah.
- 30:10You kind of – yeah, absolutely.
- 30:12You kind of have to really understand C pointers pretty well to get it.
- 30:16But once you do, it's pretty straightforward, right?
- 30:18Because when you say pointer and you dereference that pointer and you say a name, that really just maps to, like, an offset from the base address.
- 30:25And long as they all have the same shape up to that point in terms of in memory, you basically have inheritance, right?
- 30:31That's cool.
- 30:46This episode is brought to you by CodeShip.
- 30:48CodeShip has launched organizations, create teams, set permissions for specific team members, and improve collaboration in your continuous delivery workflow.
- 30:57Maintain centralized control over your organization's projects and teams with CodeShip's new organizations plan.
- 31:03And as Talk Python listeners, you can save 20% off any premium plan for the next three months.
- 31:09Just use the code TALKPython, all caps, no spaces.
- 31:12Check them out at CodeShip.com and tell them thanks for supporting the show on Twitter where they're at CodeShip.
- 31:18Yep, exactly.
- 31:24And that's another kind of a side effect of studying this sort of – studying implementation.
- 31:29Because most implementations are usually in C.
- 31:32So you get to kind of see these interesting C tricks and see how other languages are built on top of that, like object-in-order programming.
- 31:40Yeah, it's cool.
- 31:41I definitely have a better appreciation for macros after spending 10 hours looking through that idea.
- 31:48Because I did a lot of C++, but not a lot of pure C.
- 31:51So, you know, some of the tricks you might do differently in C++, you know, almost, you know, have really nice macro solutions.
- 31:59So that's cool.
- 31:59Your other project, Python Tutor at PythonTutor.com, what's the relationship to this?
- 32:08I mean, certainly PythonTutor.com helps you understand that sort of in-memory what's happening inside your Python code.
- 32:16So I kind of see these things as somewhat related, these two projects that you had.
- 32:20Maybe you could just introduce Python Tutor for everyone and then we could talk a bit about it.
- 32:24Sure.
- 32:25So Python Tutor at PythonTutor.com is a – it's a web-based tool where you can write Python code.
- 32:32And actually now you can write code in a lot of other languages.
- 32:34So you can write code.
- 32:35It supports Python, Java, JavaScript, TypeScript, which is a Microsoft version of JavaScript with types, which works really well.
- 32:43And also Ruby now.
- 32:45What you do is you write code in your browser and then you run it.
- 32:48And it actually goes – it sends your code to a server to run in a sandbox.
- 32:52So it actually runs a real version of the language and not some kind of JavaScript-y simulation of it.
- 32:59So it runs the code.
- 33:01It sends back the execution trace, which is everything that happened when your code ran.
- 33:06You know, what it did at every step, when it printed out, what variables there are, what data structures there are.
- 33:12And then it produces a visualization for you that you can step through.
- 33:15So it produces a visualization of every step of the code execution.
- 33:20And then you can use a slider to go through it and see that, you know, the variables being created, the function stack frames being created, the pointers that are pointing to each other.
- 33:29And what that lets you do is that lets beginners especially build up a mental model of what is kind of going on inside their program.
- 33:38Because even for code – for experienced programmers, we actually build up this model ourselves.
- 33:43We look at a piece of Python code and we think in our heads, oh, there's a variable here that's pointing something else here and that's pointing this other thing here.
- 33:50And then we call a function and that function points to the same thing we do.
- 33:53But those structures are really hard for beginners to build up in their heads.
- 33:57And this tool has just been really helpful for a lot of people to build up that model.
- 34:02And the relationship between that and the CPython stuff is actually really interesting because the CPython stuff is really for advanced learners who want to learn how things really work behind the scenes.
- 34:12And like we mentioned earlier, the Python tutors, for most people, I think, it's more useful because it's really what happens.
- 34:18It draws the pictures of what happens at the conceptual level, right?
- 34:22That you're actually – conceptually, all you want to think about is you run every line of code and something happens.
- 34:27You don't need to know about the bytecode or the stack or the main interpreter loop or PyObjects or everything.
- 34:34So I think those two are really complementary.
- 34:36One is for advanced kind of programmers who want to study internals, whereas the Python tutor is for beginners who are just learning the language.
- 34:45Yeah, that's for sure.
- 34:47I kind of saw it the same way.
- 34:49I feel like there's sort of this understanding of the thing that is CPython.
- 34:55And Python tutor is this great way to help beginners kind of form good mental models.
- 35:00And your CPython walk is really good at actually showing a super deep understanding.
- 35:05But they kind of give like two perspectives of the same thing.
- 35:07So even though I've been doing Python for a long time and I know C really well or C++ anyway, I still thought that just looking at the stuff that was going on in Python tutor,
- 35:15like it has some really great visualizations for showing basically like scope, variable scope and things like that, because that can be kind of hard to understand for beginners.
- 35:26Those kinds of things, right?
- 35:28Like because it's not just, well, it's in the curly braces.
- 35:30And so when it leaves the curly braces, this variable is gone, right?
- 35:33There's a whole different mechanism for finding what's defined where and so on.
- 35:37Right.
- 35:37That's right.
- 35:38And also with the, with nested scopes and closures in Python, that gets even more tricky.
- 35:44So the Python tutor has a way of visualizing kind of your parent frame.
- 35:48So if you, for example, the classic case, if you define a function within a function, that inner function has access to the outer functions variables as well as the global variables.
- 35:59And it gets even trickier when, you know, you have a function foo and inside of foo, you define bar and bar access is something within foo.
- 36:06But then foo returns bar to its color and foo is the stack of foo is gone.
- 36:12But when you call bar again, you can actually still get back to the variables that foo had, even though foo has finished executing.
- 36:19And the Python tutor and these sorts of tools visualize that for you.
- 36:23And it's been used by quite a few classes, especially I teach these things like nested functions and closures, which are not as obvious, you know, and they're, they're more advanced concepts.
- 36:33Yeah.
- 36:34I, I do professional like training for Python and other, other technologies as well.
- 36:39And I was thinking I'd probably pull that up when it gets to the scope stuff for students, just, you know, because, you know, I'm teaching a lot of guys who have done C++ or .NET or something like that.
- 36:48And just their mental model is not appropriate.
- 36:50Right.
- 36:51And just like seeing it is a lot easier than spending five minutes talking about it, writing some demos.
- 36:56So I think that's really cool.
- 36:57I think it can help, help a lot in those areas as well.
- 37:00Yeah, definitely.
- 37:01Please, please use it.
- 37:03And, and, and let me know if you have issues.
- 37:05I mean, it's pretty, it's pretty robust at this point.
- 37:08I mean, the thing is, it does require an expert such as yourself to guide people through.
- 37:12I mean, it's helpful for people by themselves.
- 37:14But if you just, what people do as instructors, like yourself, is you just pull up a browser and start writing code and start running it and start explaining the code to the students one step at a time.
- 37:25And that's a lot more useful, I think, than starting a terminal.
- 37:28Right.
- 37:28Because the alternative now is you start a terminal, write a, write a function or a nested function or whatever, and then put a bunch of print statements inside.
- 37:35And then you just run the terminal and just print a bunch of stuff.
- 37:37And you're like, okay, I got to explain why it's printing this.
- 37:40But whereas in the Python tutor, it's printing it to the web terminal.
- 37:43But then also every step you see, oh, it's printing this because X is now pointing to this.
- 37:48And now X points to something else and it's printing that.
- 37:50It's extremely clear.
- 37:51Yeah, it is very clear.
- 37:53And it's like, you know, if you were to do your terminal example and then go over to the whiteboard and sketch out what's really happening as you try to describe it, like Python tutor just does that drawing for you, right?
- 38:02Exactly.
- 38:04So the exact use case is what you said.
- 38:06It really replaces a combination of a terminal.
- 38:11It really replaces a text editor, you know, interpreted a terminal scene, like a REPL, and a separate whiteboard all in one.
- 38:21And I thought it was really interesting you mentioned the .NET kind of the C slash .NET developers switching the mental model of Python.
- 38:28A funny story about this is recently I wanted to learn Ruby.
- 38:31I've always wanted to learn Ruby for a while.
- 38:33I've never done it before.
- 38:34And I felt a good way for me to learn Ruby is to actually write my own Ruby backend for the Python tutor.
- 38:42So the Python tutor is actually, it's a very platform, it's a language independent interface.
- 38:47If you notice the visualizations, nothing about the visualizations has Python.
- 38:50They're just variables and stack frames and functions and lists and objects with attributes and stuff.
- 38:57And you can imagine squinting and that makes sense in another language like JavaScript or Java or Ruby.
- 39:03So what the backend does is that you actually write a backend, say in Ruby, by hooking into the Ruby debugger and printing out what happens at every step, you can actually generate visualizations for Ruby.
- 39:13So I actually spent about two weeks really deep diving into the Ruby language implementation and debugger and how it works.
- 39:20And I actually created the backend for Ruby, which is live on the site.
- 39:24And that actually gave me some really interesting revelations about how scoping especially works in Ruby.
- 39:30Have you done Ruby before?
- 39:31I started to learn Ruby on Rails a little bit, played around with it, never really got very far with it.
- 39:37Yeah, it's, it's, we could do a whole other podcast on that.
- 39:40I think people who've done Python for a long time, when, when we learn Ruby, it just seems crazy and weird.
- 39:45And I'm sure Ruby people say the same thing with Python.
- 39:47The scoping is really weird.
- 39:48So I have an example of Ruby scoping example is like something that really looks basic in Python.
- 39:54Like, oh, this ought to work.
- 39:55So I'll give you a, a classic example is if you have a, what looks like a global variable, like, you know, X equals five.
- 40:03And then you define a function in Ruby inside that function, you cannot access the global variable.
- 40:08Okay.
- 40:09It's like insane.
- 40:10And it's because it actually, when you define a global variable, it's actually not a global variable.
- 40:16It's a local variable in that scope.
- 40:18And when you define a function, I can like what it looks like a function.
- 40:22That's actually a method on the default object, which is outside of the scope of your normal thing.
- 40:27So it can't actually access what you think is a global.
- 40:30So if you actually think of things in a Python way and you're doing Ruby, it gets super confusing in terms of scope.
- 40:37So, but the Python tutor actually illustrates that all for you.
- 40:40And it's like, oh, wow, I can see why I can't access that variable.
- 40:42Even though I thought by looking at the code, I could.
- 40:44Yeah.
- 40:45And that way I think Python tutor is really interesting for experienced developers because we have these really strong mental models, but they're not always, they're not portable necessarily.
- 40:54Right.
- 40:54You can't just plug them into different situations.
- 40:56And so seeing the differences might just quickly, you know, connect that, those two together.
- 41:01Exactly.
- 41:02And I think that's why I've been extending it to other languages because it's, I want this tool to be useful not only for someone who's an absolute beginner, who's never learned anything, but also for experienced programmers.
- 41:13And one of the future pieces of work I love to get into, if I have time, is to kind of make the bridge between different languages.
- 41:21Now that imagine Python tutor is this nice visualization that is pretty much language agnostic.
- 41:26I want to see, like, one awesome thing would be, like, if I'm a Python programmer, I want to learn Ruby.
- 41:31I want to write some Python examples and then see some equivalent or similar Ruby examples and step through their code and see, oh, this is how you do this, you know, do lambdas or do nested functions in Ruby.
- 41:42It looks kind of like Python.
- 41:44So I think that with this tool, because it's on the web, people can build up interactive examples showing how different languages differ from each other.
- 41:52Yeah, I think that's actually really valuable.
- 41:54Although you might need a 301 redirect to a language tutor or something like that, right?
- 42:00Yeah, the name is funny.
- 42:01Yeah, the name kind of stuck because it started with Python.
- 42:05I debated a change of name for a while, and the domain is really good, and, you know, it's pretty highly ranked, and everybody, a lot of people know it.
- 42:12So I think it might just be an inside joke.
- 42:15I might just have to stick with Python for now, even though it supports these languages.
- 42:18Yeah, yeah, of course.
- 42:19It's cool.
- 42:19So that's all really well and good for helping.
- 42:23Before we move on, I guess, let me go back to one thing.
- 42:26One other thing that I think is really helpful, even in this mode that we've already spoken about, we'll get to the other modes that we have available in Python tutor as well.
- 42:34But one I thought was really cool is forwards and backwards execution.
- 42:38Like, so I'm a huge fan of PyCharm, and PyCharm has really nice interactive debugging.
- 42:43And, you know, speaking of Microsoft, you're around, you know, somewhere physically in here, the Visual Studio guys, and they have Python tools for Visual Studio, which have nice interactive debuggers.
- 42:53But going back in a debugger is not the same thing as actually forward and reversing time.
- 42:59And I think that's one of the things that's cool about Python tutor is I can run forwards.
- 43:03Oh, wait, I didn't understand what happened.
- 43:05Let me go back three steps, forward two steps.
- 43:06You know, that's a really cool feature.
- 43:09Yeah, and I think that's one of the key features.
- 43:11And, you know, people have been trying to do reverse kind of debuggers in production for a while.
- 43:16There are actually some teams, you know, doing stuff for various languages.
- 43:21I mean, in production, it's really hard to do.
- 43:23But actually, in this educational case, the forward and backward is sort of a trick because what happens is the whole program has already executed by the time you see it in the browser.
- 43:33So when I'm scrubbing forward and backwards, I'm just looking at different pieces of the log that the program has already done.
- 43:39So that's really nice because it allows you to go forward and backwards arbitrarily.
- 43:42It's not like I have to re-execute it all.
- 43:44The whole program is done.
- 43:45I'm just seeing what did it do with step one and what did it do with step two and such.
- 43:49That's awesome.
- 43:50Yeah, there's not like an edit, continue, or drag execution pointer to skip this if check or something like that, right?
- 43:56That would be cool.
- 43:57But, yeah, yeah.
- 43:58That would be cool.
- 43:58But, yeah, it's a read-only view.
- 44:00It's just it's done.
- 44:01Yeah, this is the program you wrote.
- 44:02Let's just see what happens at every step.
- 44:03Yeah, I think that's amazing.
- 44:05So the other thing that you can do that you seem to be building out more and more is to bring other perspectives into this.
- 44:13So if I go around pythontutor.com and I go click some stuff, it's like an automated system showing me stuff.
- 44:18But if I wanted to sit over the shoulder of somebody and help them understand it or if I was teaching a class and a bunch of people doing it, you've got tools for that as well, right?
- 44:27Yeah.
- 44:28So the immediate tool, it's all on the site right now.
- 44:31If you look at if you go to the Python Tutor site, there's a start shared session button on the upper left.
- 44:37And what that does is that it actually creates a unique URL that you can send to your friend or to a tutor or to a TA.
- 44:44And when they join that URL, they actually get into your session.
- 44:49So it's like you're both virtually in the same session that are sharing it.
- 44:53So what you can do is you can write code together just like you're in Google Docs.
- 44:57And then you can actually run when you run the code, your visualizations are synced up.
- 45:02So you can actually when you step backward, the other person's screen also steps.
- 45:05And then there's a chat box so you can talk to each other.
- 45:08And you can also see each other's mouse cursor.
- 45:11So that simulates the experience of, say, a tutor and a learner getting together and sitting side by side and trying to work out a piece of code together.
- 45:20Except you can do this anywhere and remotely.
- 45:23So we've deployed this for about a year now.
- 45:26And a bunch of people, like hundreds of people, have just used the service to do both tutoring, like remotely, just saying, you know, I sent a link to my tutor and they can tutor me and I don't have to be in the same room with them.
- 45:38And also people use it for collaborative learning, which is really neat.
- 45:41So this chat room supports arbitrary numbers of users.
- 45:45In reality, after you get to more than four or five, it gets confusing because so many people are trying to write code together and chat.
- 45:51And it's just it's a storm of little mouse cursors.
- 45:54Exactly.
- 45:55So because you see everyone's cursor.
- 45:57So I've seen people with three, four, maybe five people kind of talking about stuff.
- 46:01So that's sort of the tool that simulates a a kind of personal interaction with the visualization.
- 46:10Then you have another form that is sort of almost a dashboard of many learners, right?
- 46:17Right.
- 46:18So then there's another tool that I've been building that isn't exactly live on the site yet because it's it's really a beta for tutors only.
- 46:26And what that is, is that that solves the problem of there not being enough tutors.
- 46:30So imagine if you're in a large, you know, in a real class, you know, in a college class, you might have 50 students in a computer lab and one tutor or TA there.
- 46:40And what the TA has to do is run around the computer lab helping everybody.
- 46:43And, you know, people are raising their hands or going around helping one person.
- 46:47Then someone else raises their hand and go around helping another person in, say, an online course, you know, a MOOC or these massive online courses.
- 46:54There may be a thousand students for every TA on the course.
- 46:56And there's no way they can help everybody at once, obviously.
- 47:00So what I've done is I built a dashboard that shows a tutor or a teacher in real time what a lot of students are doing at the same time on a website like the Python tutor.
- 47:11So this dashboard can show up to dozens of people and each person's actions are just in a little tile.
- 47:18So it's like you have a you have dozens of little rectangular tiles and a big dashboard on your monitor.
- 47:23And each one is updating in real time as the student is editing code or running code or seeing compiler errors.
- 47:30So then as a teacher, you can glance and it's sort of like you're looking over the shoulders of, say, 20 or 30 students at once and seeing at a glance what they're doing.
- 47:40And most of the time, students are just coding along or they're paused or they're thinking.
- 47:45But then sometimes you see a student always keep getting the same compiler error or you see a student changing their code back and forth and seeming confused.
- 47:53And in that case, you can start a chat with those students in directly in the tile.
- 47:58So you can you can chat with any number of students you want.
- 48:02And each chat shows up directly in their in their coding session.
- 48:06And as a tutor, because you have this dashboard, you can simultaneously chat with many students at once.
- 48:12And the reason this works really well in practice is because a lot of students are just paused or thinking so that you could jump in to help, say, three or four or five students at once.
- 48:21And it's not like you're chatting all the time.
- 48:23You're chatting, giving them a suggestion, giving them pointers or something.
- 48:26And then they go off and do some work and you go help someone else.
- 48:29And you can do all that from the comfort of your own of your own home without having to run around a giant computer lab.
- 48:35Or if you're in an online course, you can't.
- 48:37You don't know where the students are.
- 48:38They're all over the world.
- 48:39But you can just sit there in one central location and help up to dozens of people at once.
- 48:43Yeah, that's really awesome.
- 48:44So you've got all that in a blog post that's coming up pretty soon, right?
- 48:48Do you know when that's coming out?
- 48:50Yeah, so I'm writing up a blog post.
- 48:52I don't exactly know what's coming out.
- 48:53Hopefully, it'll be in the middle of the month.
- 48:56I'm still kind of shopping around to different folks and seeing where I can get it published.
- 49:02And the research papers on these projects are coming out soon on my website as well.
- 49:08So all of these are kind of along the lines of my research projects, which all revolve around the theme of how do you build better interactive tools for teaching programming?
- 49:18Yeah, awesome.
- 49:19Speaking of interactive tools, we had Brad Miller on from Interactive Python.
- 49:24And you guys are doing some work together as well, right?
- 49:28They're doing something with pythontutor.com to integrate that?
- 49:32Yeah, so Brad, Professor Brad Miller, he was one of the first users of the Python tutor back in the day.
- 49:39So I started this project about five years ago as a graduate student.
- 49:42And that had zero users.
- 49:44And it was just something I did.
- 49:46You know, like many hobby projects, like many of these open source projects, it just scratched my own itch.
- 49:50I was teaching a bit of Python.
- 49:52I wanted to create some visualizations that helped myself out.
- 49:54And it was a fun thing to do.
- 49:56I put this project online for about a year or two.
- 49:59And no one really used it.
- 50:01You know, I showed some friends and colleagues.
- 50:03And I thought, oh, this is a kind of cool hobby project.
- 50:05But then around 20, I think around 2011, oh, it was four years ago.
- 50:09Around 2011, Brad was starting to build some digital textbook resources.
- 50:15He had been an author.
- 50:16He's been a professor for probably over a dozen years.
- 50:19And he had written some Python textbooks.
- 50:22And he was trying to experiment back then in 2011 with putting Python educational materials online in a digital format.
- 50:32And, you know, because he's really innovative, what he wanted to do is he was thinking, I don't want to just put some text and code online.
- 50:40Because then it's just like it's no better than reading a book except you're just on the computer.
- 50:43I mean, it's better in the sense only in the sense that it's free, which is cool.
- 50:48I mean, that's already great.
- 50:49I mean, having a free digital textbook that's open source is great because many more people can read it.
- 50:54But he's saying, you know, if we're all already on the computer, can't we do something more interactive?
- 50:59So he found my Python Tutor project and actually challenged me to try to make it so that you can embed it within other web pages.
- 51:08And theoretically, it was possible because it's just a web-based interface.
- 51:11But, you know, I had to write a bunch of code to get it so that it can embed within other web pages.
- 51:16And we did that.
- 51:17This was four years ago.
- 51:19And I've been working with him ever since on and off to embed the Python Tutor in his page.
- 51:24So if you actually look at his interactivepython.org digital textbooks, throughout the textbook, you'll see little widgets here and there that show a piece of Python code with a slider through it.
- 51:35And then you can just slide, and then the visualizations actually appear.
- 51:38And then if you hit edit, you can actually edit the code in the Python Tutor and see the visualizations.
- 51:43I think that's been tremendously helpful for students because they can not only read the code, they can actually see what's going on.
- 51:49And the cool thing is that that all happens within the context of their normal interactive textbook.
- 51:55So, yeah, so Brad is an early power user and longtime power user of the system.
- 51:59So I'm glad you had him on the show.
- 52:01Yeah, that's awesome.
- 52:02And the students can even kind of, like, customize the code samples and save them and stuff, right?
- 52:07So that's really neat.
- 52:08Yeah, exactly.
- 52:09And that's the cool thing about being online, that you can not only, say, with the Python 2, with the visualizations, you know, you can imagine someone making a visualization, right?
- 52:19Like an instructor using PowerPoint to very carefully draw out pointers and lists and data structures.
- 52:26And that's all good.
- 52:27But then what if, as a student, you're like, wait, I want to change this code to make it go backwards or something?
- 52:33And the cool thing about having a real tool is that you can just change your own code and see the new visualization instead of just seeing what the teacher imagined.
- 52:40Yeah, that's wonderful.
- 52:41Because that playing, that playful exploration is sort of key to becoming a good programmer, I think.
- 52:47Exactly.
- 52:48And that's something that's, you know, on a more philosophical level, that sort of tinkering mindset, like you said, is key.
- 52:55I mean, on one hand, it's very important to understand fundamental principles like variables and scoping and function and stuff.
- 53:00But a lot of this, you know, as you know, and I'm sure a lot of people have talked to, you know, software is really a craft, right?
- 53:06You can't.
- 53:07It's just like woodworking or, you know, being a carpenter or something.
- 53:12Like you have to learn some of the basic physics and material science behind it.
- 53:17But really, you can't just become an expert, you know, woodworker by just reading a bunch of books.
- 53:22You have to start tinkering and making mistakes and, you know, bruising your hands.
- 53:26And it's very similar.
- 53:27You have to write a lot of code, play around, see a bunch of errors, and just build up this intuition about how things work behind the scenes.
- 53:34And hopefully the visualizations help scaffold that learning.
- 53:37Yeah, I think absolutely they do.
- 53:40So very cool project.
- 53:42I think, Philip, that might be a good place to kind of wrap it up.
- 53:45Before I let you go, let me ask you two final questions I always ask the guests.
- 53:48Great.
- 53:49First of all, what's your favorite editor?
- 53:52Oh, starting religious wars here.
- 53:55I've used Vim.
- 53:56Hey, there's no judgments passed.
- 53:58No judgments passed.
- 53:59No judgments passed.
- 54:00So I started as an Emacs user in college for about a year or two.
- 54:06But then I saw the light and switched over to Vim a few years ago.
- 54:10So I've been using Vim for, I don't know, the past decade or so.
- 54:15And I don't have any good reason for doing it beyond just muscle memory.
- 54:18So I am not dogmatic about text headers.
- 54:21I just think you should pick one that you work well in and just get really good at it, whatever it might be.
- 54:26Yeah.
- 54:27Learn the hot keys.
- 54:27Really just become comfortable.
- 54:29That's important.
- 54:30So the other question is, there's a ton of stuff out on the Python package index.
- 54:36You got any notable favorites out there?
- 54:38Things people should know about?
- 54:41I think that one of the really useful Python packages is more of a meta package.
- 54:47So I think it's called this company called Enthought, which started as kind of a scientific Python company.
- 54:54They make some packages.
- 54:55There's one called Enthought Canopy.
- 54:58And then there's another one.
- 54:59I don't know which company does it, but it's called Anaconda.
- 55:02I think it might be Continuum or Enthought.
- 55:03But look up Canopy, C-A-N-O-P-Y, and Anaconda.
- 55:08And those are really all-in-one meta packages for just installing 100 or so Python packages and a nice one-click installer that contain...
- 55:19Mostly it's meant for scientific programming.
- 55:21So it has things like the IPython notebook and NumPy, SciPy, Matplotlib, all the scientific packages.
- 55:27But also just a lot of stuff for data science, for data processing analysis.
- 55:33The reason why I suggest those is, especially for beginners, is because they have a one-click installer for Mac, Windows, and Linux, I think.
- 55:41Because one of the annoying things about starting up with any kind of new language is just having to install extra packages.
- 55:48So for people who are a bit more savvy, they can use PyPy, Easy Install, pip, those things.
- 55:53But sometimes they get annoying because you try to install it and it says, oh, some dependency is not found.
- 55:57Or your operating system doesn't have this compiler and stuff.
- 56:00Vars.bat not found.
- 56:02Exactly.
- 56:03Especially on Windows, right?
- 56:05Especially on Windows, development is hard.
- 56:07So the one-click installers, Canopy, Anaconda, they have a company backing them.
- 56:11I think there's free versions.
- 56:13And I just want to get past that headache and just get to the programming.
- 56:16Yeah, especially if you're doing data science and you're doing it on Windows, I definitely second that.
- 56:22Because it is super hard to get some of those things to compile over there.
- 56:24Yeah.
- 56:25And people have been talking in Python user groups and on keynotes at PyCon about how if you want to improve Python exposure, we need a better store on Windows.
- 56:36Because the current store on Windows, it's pretty hard to get going.
- 56:40But these one-click package installers are going to help.
- 56:44And I'm hoping in the future, as web and cloud stuff get better, more of this stuff could be hosted in the cloud.
- 56:49So imagine a web-based Python cloud service where the web IDs are so good.
- 56:55I mean, I bet some companies are already starting to do this.
- 56:57You can just have a web-based ID for Python, which is really responsive.
- 57:01And all your stuff just runs in the cloud.
- 57:02It has every single thousands of libraries available.
- 57:05You don't even have to worry about installing.
- 57:07You just import whatever you want and everything works.
- 57:09I think that's the dream.
- 57:11Yeah, that's definitely a cool dream.
- 57:12There's a company called Python Anywhere on anywhere.com.
- 57:16And they're started down that path.
- 57:19It's not quite that far, but it is a pretty cool thing.
- 57:22It's free for people to try.
- 57:23That's pretty cool.
- 57:24All right.
- 57:25So, Philip, awesome conversation.
- 57:26Thank you so much for being on the show.
- 57:28Is there anything that you would like to talk about or tell people about that I forgot?
- 57:32A final call to action?
- 57:33Final call to action.
- 57:35Wow, this is a high pressure here.
- 57:37I think, I mean, I would say the call to action would be to find – actually, here's a good call to action.
- 57:47A call to action is to go on YouTube and watch some of the videos that people have put up, especially talk.
- 57:56So, PyCon, which is the main Python conference, has some great keynote talks or just amazing.
- 58:01They're really good about putting up talks publicly.
- 58:04I mean, they have hundreds of talks on all sorts of topics, and they're well-produced, too.
- 58:09Like, PyCon and also the affiliates in different countries.
- 58:13A lot of times what I do is I just listen in the background if I'm working or I'm doing errands.
- 58:17Both the keynotes, which are more high-level, here's where Python is going, and also very detailed things.
- 58:25Like, if I want to learn about networking in Python, I want to learn about data science in Python.
- 58:29I think those videos are amazing.
- 58:31There are so many of them.
- 58:32I mean, it's just like thousands of them.
- 58:34I totally second that.
- 58:36That's a really good suggestion.
- 58:37And on a more focused level for this conversation, I really recommend people go and watch your 10-hour code walk through the CPython code base.
- 58:47You will absolutely learn something no matter what your experience level is.
- 58:51It's very cool.
- 58:52So, check that out.
- 58:53Great.
- 58:53Well, thank you very much for promoting that.
- 58:56And I'm really glad I made this video.
- 58:58So, I guess the final tidbit you want to include in the outtakes is that I didn't plan on producing those videos.
- 59:06I mean, those are just part of my class.
- 59:08And the great decision I made was I just turned on the screen recording capture.
- 59:13And I have a Microsoft Surface tablet.
- 59:16And that allows me to do a lot of the drawings and the more interactive things.
- 59:20But really, what you're hearing is exactly what I gave in those, I think, 10 lectures or so.
- 59:25That's exactly what the lectures were.
- 59:27I did some light editing.
- 59:29You know, in the beginning, you know, people were setting up in class.
- 59:31And I did some light editing.
- 59:32But if you notice, the audio quality isn't amazing.
- 59:34That's the one downside because I didn't have a nice mic.
- 59:37I just basically was teaching in front of the class.
- 59:40But I feel like maybe another call to action is for people, if you're giving a lecture or giving a talk about something, just record it and put it online.
- 59:49You know, the quality doesn't have to be amazing.
- 59:52But just like the CPython walkthrough, it wasn't like I pre-planned to, like, go to a studio and, like, spend $10,000 making some high-quality production.
- 1:00:01I just recorded this as part of my class.
- 1:00:03And, you know, I set a disclaimer.
- 1:00:04This is kind of rough.
- 1:00:05You know, some parts are, you know, I'm stuttering or I'm kind of backtracking or there are mistakes.
- 1:00:10But it's great to have the resources out there.
- 1:00:12And something like Khan Academy, which is really famous now with Sal Khan, making these very simple sketches explaining basic math and arithmetic.
- 1:00:21That's exactly how he started.
- 1:00:23He just was tutoring his cousins.
- 1:00:24And he had a pen tablet and he just recorded videos.
- 1:00:27And he didn't care that they were kind of very impromptu.
- 1:00:31In a way, people really liked that because it seemed really genuine.
- 1:00:33It wasn't just some, you know, million-dollar production in a studio somewhere.
- 1:00:38So I'm glad I put those up.
- 1:00:39And the cool thing is I didn't actually take much work.
- 1:00:42I just recorded it and did some light editing.
- 1:00:44I probably won't do as much editing as you'll do on this podcast.
- 1:00:49But, you know, and they're up and people happen to like them.
- 1:00:54So I'm glad that I did that.
- 1:00:55Yeah, I think it's a great contribution to the community.
- 1:00:57So thanks for doing it and thanks for being on my show.
- 1:01:00Great.
- 1:01:01Thank you very much.
- 1:01:02Yeah.
- 1:01:03See you later.
- 1:01:03This has been another episode of Talk Python To Me.
- 1:01:08Today's guest was Philip Guau.
- 1:01:09And this episode has been brought to you by Hired and CodeChip.
- 1:01:12Thank you guys for supporting the show.
- 1:01:14Hired wants to help you find your next big thing.
- 1:01:18Visit Hired.com slash Talk Python To Me to get five or more offers with salary and equity
- 1:01:24presented right up front and a special listener signing bonus of $4,000.
- 1:01:28Check out CodeChip at CodeChip.com and thank them on Twitter via at CodeChip.
- 1:01:33Don't forget the discount code for listeners.
- 1:01:35It's easy.
- 1:01:36Talk Python.
- 1:01:37No caps.
- 1:01:38No spaces.
- 1:01:38You can find the link from today's show at talkpython.fm/episodes slash show slash
- 1:01:4622.
- 1:01:46And while you're there, be sure to subscribe to the show.
- 1:01:49Open your favorite podcatcher and search for Python.
- 1:01:51We should be right at the top.
- 1:01:53You'll find the iTunes and direct RSS feed links in the footer of the website.
- 1:01:57Our music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
- 1:02:03You should check out the entire song on our website at talkpython.com.
- 1:02:06This is your host, Michael Kennedy.
- 1:02:09Thanks again for listening.
- 1:02:10Smix takes out of here.
- 1:02:12Outro Music.