Monitor errors and performance issues with

#119: Python in Engineering Transcript

Recorded on Tuesday, May 30, 2017.

00:00 Michael Kennedy: Think about how you learn most technical or detail oriented subjects. You start at the bottom, lowest level and you create building blocks and work you way into the thing that eventually you get to that you actually care about. This happens in engineering. This happens in math, this even happens in programming. Our guest this week, Dr. Allen Downey believes that computation and programming can help us turn this inside out way of teaching right side out again. Join Allen and me as we discuss programming as a way of thinking and physical modeling in engineering and Python. This is Talk Python To Me, Episode 119 recorded May 30th 2017. Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the ecosystem, and the personalities. This is your host Michael Kennedy. Follow me on Twitter where I'm @Mkennedy. Keep up with the show and listen to past episodes at and follow the show on Twitter via @talkpython. This episode brought to you by Linode and Rollbar. That's right. Welcome to Linode who has joined Talk Python To Me as a major sponsor. Be sure to check out what both of them are offering during their segments. It really helps support the show. Hey everyone, I have a quick announcement before we get to our conversation. I'm super excited to announce the availability of my next course and this is one I've been wanting to write for a long time. Its MongoDB for Python developers. This is one of the most practical and real world courses on document databases in MongoDB. You learn the native query syntax, PyMongo and the ODM Mongo engine. We will also cover performance tuning and production deployments. Get the MongoDB course right now at Allen welcome to Talk Python.

02:05 Allen Downey: Thank you its a pleasure to be here.

02:07 Michael Kennedy: It is an honor to have you on the show. I'm really excited to bring this engineering aspect of Python to all the listeners. It would be really fun I think.

02:16 Allen Downey: I hope so.

02:17 Michael Kennedy: Indeed, indeed. Its really cool to see the different ways that people are using programming and Python and certainly to see how its slowly eating away at the big commercial monolithic type things like MatLab and Mathematica and so on.

02:30 Allen Downey: Right.

02:31 Michael Kennedy: Very fun, we're gonna dig into that for sure but let's start at the beginning. What's your story? How did you get into programming and Python?

02:37 Allen Downey: I got to Python in I think the year 2000. I have a great story which is I actually was working in Java. I was teaching at Colby College up in Waterville, Maine. I was unhappy with the books I was using so I started writing a free open source textbook and I wrote it in Java because that's the language I was teaching in. I didn't know Python at that time. I'm not sure I had even heard of Python but...

03:02 Michael Kennedy: There was the snake thing and there was some kind of movie the British make that's kind of funny and then right, exactly.

03:08 Allen Downey: Exactly but I put my Java book out under a free license and Jeff Elkner who was teaching high school in Virginia at that time, kind of took me up on the offer. I said you can take this book, you can modify it. You can do anything you want and he translated it from Java into Python and sent it back to me. So I actually learned Python by reading my own book.

03:30 Michael Kennedy: Wow most people don't learn Python by reading their own book. That's a really crazy story. That's amazing.

03:37 Allen Downey: Its a strange experience because it sounded like me. Its my writing style but its telling me things I don't know.

03:44 Michael Kennedy: Oh no, that is weird.

03:46 Allen Downey: Its like in movies, where the future you comes back from the future and tells you things that you don't know. Its just like that.

03:52 Michael Kennedy: Yeah, oh my God. That's really, really interesting. It was a pretty unique thing to do back in the year 2000 to release books kind of open source. Now its pretty standard. Many books have some online open source component to it but that was not common then was it?

04:07 Allen Downey: I don't think so. And I had no idea what I was doing. In fact the first version, because I was writing in LaTeX and LaTeX is almost a programming language. I released it under the GNU General Public License because I thought of it just being source code. That was the first license I used. This was before the Creative Commons licenses didn't exist yet. I switched at one point to the GNU Free Documentation License because that made more sense. And now I'm mostly using Creative Commons licenses.

04:36 Michael Kennedy: Okay which Creative Commons because there's a bunch of variations right?

04:39 Allen Downey: Yeah different ones for different books. Part of it most of mine are I don't have the non-commercial clause on most of them but for the ones that I'm publishing with O'Reily that's kind of the compromise that we've settled in on, which is that the versions that are on my web page have the non-commercial clause. And then O'Reily has the exclusive commercial license.

05:01 Michael Kennedy: That seems like a pretty fair deal.

05:02 Allen Downey: I think it is not bad. What I've done a couple of times when people have made a substantially modified version I can give them another license. I can grant it to them under a license that does not have the non-commercial clause. So if someone makes a really small change then that's still covered but if they make a bigger change, then I've got some flexibility.

05:22 Michael Kennedy: Right okay, very interesting. I think this way of learning Python is quite amazing and its probably not entirely new given how many people there are in the world but its got to be pretty rare. So tell me what was your experience, what was the impression of the language as you learned it? Were you like why did they take away all the curly braces? This is so weird or were you like oh this is actually kind of amazing? What was your thought?

05:44 Allen Downey: Oh no, I was hooked immediately. Again I was coming from Java and so I knew the frustration of teaching Java which is all the stuff that you have to explain on the first day, just to write Hello World, there is your public static void main string bracket, bracket and all that. And in Python of course is print('hello world').

06:06 Michael Kennedy: Exactly its amazing. I feel like people that work in those languages like Java and I consider myself among them. I did for a long time C++ development and some C# development and there are highly structured with symbol type languages not structured in format but structured with many, many symbols around it. And you just feel like those are required. Those are the right way to do it. Everything must have curly braces and extra parenthesis and what not. Until you realize that it doesn't have to be there. You can actually have a nice clean language. Its just equally expressive. Its really liberating on you. You get there finally I think.

06:42 Allen Downey: Right 'cause you end up having to do the indentation anyway.

06:44 Michael Kennedy: Yeah exactly.

06:45 Allen Downey: At that point, if you have to indent, you might as well as take away the squiggly braces.

06:50 Michael Kennedy: Exactly, fully embrace it. Great so you said you wrote the book when you were teaching in Maine and now you are still teach at the university right but you are doing it a little further south?

07:00 Allen Downey: Yes I am at Olin College which is just outside of Boston and its an engineering school. So its a little bit of a different environment. I used to do computer science in the context of a liberal arts education. And now I'm doing computing in the context of an engineering education.

07:16 Michael Kennedy: Interesting. So is it a little more exploratory, let's try to model these things and less, learn how to write operating systems, learn how to create web apps, or things like this. How's the difference?

07:29 Allen Downey: Right, yeah part of it is that. Maybe less emphasis on theory. Less emphasis on getting very deep into how things work and more on using what's there and using it to solve the problems that you're trying to solve. Sometimes its about engineering. Sometimes you are modeling physical systems, other times its developing software systems but maybe more like software engineering and less like computer science.

07:57 Michael Kennedy: Right, people may disagree with me but just coming from my background where I just minored in computer science. I didn't like go all in. I feel like computer science and programming software development kind of are the same thing but the true computer science part of it is much more theoretical than what a lot of people do day-to-day even though they might call themselves CS folks. I think you guys might have this more explicit here in your program right?

08:24 Allen Downey: Yeah I think that's right. Computer Science as a field is kind of a historical accident. It came out of math departments and then it combined with some parts of engineering. There are pieces there that are mathematics. There are discrete mathematics. There are parts that are the engineering of working with software. And then there are parts that are applications. Using computation in science and engineering and other fields. Those are three kind of different things that don't necessarily belong together in one department. I suspect that in 50 years they won't be one department anymore.

09:04 Michael Kennedy: In 50 years, would you imagine there might be an artificial intelligence department?

09:08 Allen Downey: Oh interesting. I don't know that might...

09:10 Michael Kennedy: Or data science where that AI is a big section of it or something?

09:13 Allen Downey: Yeah data science might make more sense as a field. I don't know. I can't even begin to think about what this will look like.

09:22 Michael Kennedy: It is hard to predict that far out isn't it?

09:24 Allen Downey: Yeah.

09:24 Michael Kennedy: Sure. Alright so you teach a number of classes there, which is really cool. We will dig into some of the learnings and takeaways from those around sort of fixing engineering education through programming but let's start a little bit further back. You wrote a really cool article called "Programming as a Way of Thinking" in Scientific American right?

09:45 Allen Downey: Yes, it was on their blog yeah.

09:47 Michael Kennedy: That's an honor right to be on Scientific American, a pretty cool place. I recommend people check that out. I'll put a link to it. But could you maybe give us the synopsis?

09:56 Allen Downey: Sure I mean its the idea, its not just Python but other modern programming languages are now so expressive that I think we can move away from programming as translation. It used to be that you had to write everything out using mathematics and then translate it into executable code. And you see things like the name of FORTRAN is formula translation. That's what programming was.

10:24 Michael Kennedy: Its right in the name. I remember learning FORTRAN, I actually did a little bit of engineering work in college as well and they told me FORTRAN is the most important language you'll ever learn. See where that went. But I remember that when they would teach programming to some degree was and you make this flowchart and then you translate it into the language. And that just seems so in the way these days right? Why would you ever do this? You write it out in the language.

10:52 Allen Downey: Right and you see this now in the history of pseudo code which is if you look at early pseudo code it looks like mathematics notation and then gradually it starts to look more and more like Python until you get to the point where it is Python that you realize that pseudo code is more readable if you just write it in Python and furthermore its executable. And of course being executable is huge. Not only because that's the purpose of code, but also now its debuggable. So now you're taking these ideas that are in your head, you are expressing them directly in code without going through all these translation steps and now while you're debugging that code you are debugging your understanding of the ideas that you are expressing. You are debugging your own brain.

11:42 Michael Kennedy: Yeah its really is amazing and the fact that you can push a button and get the answer means some of these conceptual debates about things are often instantly solved. I think of a lot of mathematical proofs like I'm thinking of particular one in topology where I sat there for days working on this problem. And you can work out the proof and you can write it down and it seems very much like programming, very much logical step step do this and you come to a conclusion but you're never really sure. You are not a 100% sure. Whereas if you can do this with the program, the cool thing is you can push a button or hit the enter key and see do I actually have this right.

12:25 Allen Downey: Right there is this great story about Paul Erdos. And I don't know if you've heard this. This is the Monty Hall problem which is this notorious problem in probability that almost everybody gets it wrong when they first hear this problem. And even when somebody tells you what the right answer is most people don't believe it. Its just so counterintuitive. So Paul Erdos, when a friend of his told him this problem that is one of the greatest mathematical minds of the 20th Century.

12:52 Michael Kennedy: Yeah he was truly amazing and he lived in the world of mathematics unlike so many people. He didn't really have possessions. He just went from department to department.

13:02 Allen Downey: He is a great story in his own right but this particular problem just it did not click with him. He refused to believe what is actually the correct answer. Until his friend showed him a computer simulation. And exactly as you said, the power of writing code and seeing it happen is what it took. There was no amount of mathematical proof that was going to be as persuasive.

13:25 Michael Kennedy: Yeah that's really, really, amazing. So one of the things that really resonate with me from this program is the way of thinking and I think anybody who presents ideas to other people, you may be working at a company, you are leading a team. You want to tell them about something. If you are a public speaker or if you are a teacher, or whatever it is, traditionally I feel like we've taught things in the reverse order. In the wrong order like what I'm gonna do is I am gonna spend three weeks teaching you a billion little details and then in a month, you will see that what you've actually learned is kind of cool and we will see what we can do with it.

13:59 Allen Downey: Right.

14:01 Michael Kennedy: That's such a problem isn't it?

14:03 Allen Downey: Yes, yes, and this is a major theme of these textbooks, that I'm working on, which is exactly as you said, put the fun stuff first. Show me that it works, show me why its useful what can I do with it and now I'm interested. Now I want to know how it works and we can start going top down. We don't have to start with all the details and work our way up.

14:26 Michael Kennedy: Right what's interesting and basically what makes this really possible is we can execute the ideas and understand them from the outside in. If you are gonna teach math, you can't solve a Fast Fourier Transform unless you literally want to learn all the steps. But if you are doing programming, you could grab like a simulation library or if you want to teach threading, you could just use the simple async and await stuff and just start from the outer shell like how does this look? How do we use it? What's amazing about it and then now let's dig in one layer and then another layer and another layer like basically in reverse.

15:00 Allen Downey: In fact your Fourier Transform example that's exactly what I do in Think DSP which is chapter one I'm using Python and I'm using SciPy. Its all in Jupyter Notebooks so right away you can grab, download a sound, download an MP3 or make your own recording, look at the Fourier transform, look at what that spectrum looks like and understand what the Fourier Transform does how you're breaking a sound up and expressing it as a sum of frequency components. At the end of chapter one, you understand 90% of what you need to understand. Then the last 10% is how the Fourier Transform actually works.

15:40 Michael Kennedy: Yeah I remember learning the stuff and it was always just like wow this is a serious integration. What is going on here? But you don't actually see like amazing signals being extracted from some noise environment or some signal or something, its really cool.

15:55 Allen Downey: You can start with auto tune and work your way down.

15:58 Michael Kennedy: Exactly. One of the quotes you ended that article with I wanted to share with everyone, I thought it was pretty cool was basically that modern programming languages are quantitatively different from their predecessors and we're only beginning to realize the implications of that difference. You want to add a little to that. That's a pretty awesome thought I think. I agree that people are just beginning to realize.

16:18 Allen Downey: Yes, so if we do translation, if we start out thinking in natural languages, and then we express it in mathematics and then we have to translate it into code, we are limited to the set of things that we can express in all three languages. And we lose something at each step of the translation. So my conjecture is, if we don't have to do the translation if we work directly in code, potentially we will start writing things that look very different. We will start writing things that we would never have come to if we approach them mathematically. But I don't think we know yet what that's gonna look like because that's not how we have been trained to think. I think it will have to be the next generation who start out in Python, who start out using programming languages for exploration. And we will see what they do that ends up being different from what we do.

17:12 Michael Kennedy: That's for sure. I talk to people about how they got into programming and what was exciting to them all the time and a lot of times its, well I first wrote my simple basic program and it did something on the screen, like I put my name a 100 times or I made this turtle draw a square or something I can easily see a world in 10 or 15 years where people start answering that question. Like the first thing I did was, I pulled up this Jupyter Notebook. And I typed in these things and then I understood something totally different than before right?

17:44 Allen Downey: Yes or if they are going through grade school and every class that they take involves an element of computation. Right now there is kind of obvious stuff like if people are doing trigonometry then maybe they will do some computing along the way but they're probably not doing things like analysis of word frequencies, when they study a text. But you could do that, you could have students in middle school take a couple of different authors and look at the distribution of sentence lengths or the number of different words that people use in different types of articles or different authors. They could do that kind of analysis.

18:24 Michael Kennedy: That's really interesting. I can imagine a world where the study of literature somewhat involves sentiment analysis on the text using machine learning or something like that.

18:35 Allen Downey: And where that's not something that's unusual but its just look, we've got computation as a tool, we're going to apply it to everything that we study.

18:45 Michael Kennedy: This portion of Talk Python to Me is brought to you by Linode. Are you looking for bullet proof hosting that is fast, simple, and incredibly affordable, look past that book store and check out Linode at That's Linode. Plans start at just $5 a month for a dedicated server with a gig of RAM. They have 10 data centers across the globe, so no matter where you are, there is a data center near you. Whether you want to run your Python web app, host a private Git server or even a file server, you will get native SSDs on all the machines. Afford a gigabyte network, 24 x 7 friendly support, even on holidays and seven day moneyback guarantee. Want a dedicated server for free for the next four months? Use the coupon code Python17 at There is this big push for all kids around the world learning to code. And I think what we are touching on definitely highlights some of the amazing reasons why that is. I don't feel like we need more programmers per se although there's gonna be a need for more programmers. I think we need more people with these skills that can like you say apply a little bit of computation to everything, whatever it is they are doing, bring a little computation to it.

19:58 Allen Downey: I agree. I'm not trying to make everybody be a software engineer. We don't need that and they don't want that.

20:05 Michael Kennedy: Yeah.

20:06 Allen Downey: But I do think if people have basic programming skills, that becomes a pedagogic wedge. You use that as a lever to learn everything else. I don't know if its a wedge or a lever. I might be mixing my metaphors but it gives you a tool for learning.

20:20 Michael Kennedy: Yeah for sure and you have a pretty interesting place to apply that at least see that in action at an engineering school where most of the people aren't probably programmers but they really kind of need some computation right?

20:30 Allen Downey: Right, we have a range of students both when they come in, not everybody has programmed when they get here. So we are the first contact for many of them. And then when they leave, not everybody is gonna do software. We have some who love it and that's gonna be their career and others especially not to stereotype but the folks doing mechanical engineering are not necessarily the ones who love software but the chances are they're gonna do something with software at some point in their careers.

20:58 Michael Kennedy: Yeah even if its just to write some Python script to automate something that's actually is the application they are modeling with right?

21:04 Allen Downey: Right at the very least they can automate the boring stuff.

21:07 Michael Kennedy: Exactly. Maybe that's a good place to segue into your physical modeling stuff. Let's talk about physical modeling in Python. You're doing a course there. You've got some cool libraries and stuff that you're working with. You said you are basically trying to fix engineering education. Maybe we can start with that.

21:26 Allen Downey: That's the Olin mission. So Olin College was founded because the founders thought that engineering education is broken.

21:33 Michael Kennedy: Why is it broken?

21:34 Allen Downey: Couple of ways. One of them is that its divorced from the people that we're designing for. So engineers I use this analogy that its as if the engineer is sitting in a box. Somebody comes and slides a well formulated problem under the door and you have no idea where it came from. But you craft a beautiful engineering solution and you slide it under another door with no idea where its going. And that doesn't work. Engineers have to understand the people they are designing for. They have to identity opportunities. They have to formulate those beautiful problems and figure out first of all is there an engineering solution because not always is there gonna be one and then if there is, great, lets do the engineering. Lets craft a beautiful solution but now there is a ton of work to get that idea out of the lab and make it real in the world. So engineering education has to hit all three parts of that, designing for people and then crafting an engineering solution and then getting it out into the world.

22:37 Michael Kennedy: That sounds like a really nice way to structure everything. You also talked about the science and math death march. What is this?

22:45 Allen Downey: That's the other big problem with engineering education is that there is not enough engineering. Students don't see anything that really looks like engineering. That looks like the practice of engineering. At least for the first two years, very often they are doing math, and science and other prerequisites and they treat engineering as if its the reward that you get for surviving past all those hurdles but even then it tends to be, even in the second and third and fourth years, it tends to be very theoretical, so students often graduate with a lot of ability to solve the problems that are in the text book but very little ability to do real engineering.

23:24 Michael Kennedy: Yeah that was my experience in college. I feel like taking programming and simulations and letting you start before you fully understand all the way down, is a way you can maybe move the engineering up.

23:38 Allen Downey: Yeah this is the course that I'm working on right now is called Modeling and Simulation. And this is part of the first semester at Olin we have three classes that go in parallel. Modeling and Simulation is about doing physical modeling. You've got a physical system. You make a model of what are the important parts that you have to include, what are the things that you can leave out and simplify. And then do either mathematical analysis or computational simulation to use that model to either predict something, what will the system do in the future explain why the system behaves the way it does or to design something, to do some kind of optimization.

24:19 Michael Kennedy: This is like welcome to the university. Here's your dorm. Here's where you will get textbooks. We will see you on Monday in this class like that early?

24:27 Allen Downey: Yes that's exactly right. And we do some programming. Of the first year classes, this is the one that has the most software in it but again I mentioned most people are coming in. They haven't programmed before so we are simultaneously learning a little bit of programming but with the immediate goal of modeling physical systems. That carves it down. We can teach a very small subset of the language because its not general purpose programming. Yet its really application focused.

24:59 Michael Kennedy: Its not a full multi tier web application with a database backend, the scale. No, no, we are gonna run this math problem against this data and go right?

25:11 Allen Downey: Exactly right so some of the first examples are just four loops, where you are updating a variable that just measures the quantity of something. We are doing a bike sharing example. Probably one of the first examples is you know you've got three different stations and your customers are moving bikes from one station to another. And we're gonna simulate that process and figure out is there gonna be an equilibrium or are we gonna run out of bikes? Do we have to move the bikes around? So with a very simple model, we are talking about three variables and addition and subtraction but we can get some interesting questions. We can see equilibrium. We can see non-equilibrium. We can evaluate different strategies like should I move the same number of bikes everyday or should I measure something and make decisions dynamically, all kinds of things.

26:00 Michael Kennedy: That definitely ties back to the real world. I just heard today, I think it was today. Maybe few days ago that Uber is running some program where or a feature where its cheaper to get cars when there's too many cars, if your destination is in a place where they need to basically move a car to effectively.

26:19 Allen Downey: Yes.

26:20 Michael Kennedy: Here it is, just on a much larger scale, right?

26:24 Allen Downey: Right so almost the opposite of surge pricing. It will be a discount if you happen to be going where we want you to go.

26:29 Michael Kennedy: Yeah they called it like a power zone or something. I think it was Uber. It could've been Lyft but I'm pretty sure its Uber.

26:34 Allen Downey: Interesting.

26:36 Michael Kennedy: Okay you come in, you have them do these models and they can do it computationally. Do they do that in Python?

26:42 Allen Downey: Until this coming year, everything has been MatLab which has worked okay. Its got some nice tools built in. So there are things like there is an ODE solver. There is a route finder. There's an optimization tool. And those are great. Again thinking about going top down, we can use those tools before we understand how they work. So that's been good. But we're switching to Python starting this fall.

27:05 Michael Kennedy: Oh that's exciting. So you guys are getting ready over the summer and then it's gonna launch in Python for the next set of students huh?

27:11 Allen Downey: Yes so this is my big project this summer is rewriting a lot of the materials that we have switching over from MatLab to Python.

27:19 Michael Kennedy: Okay excellent and this time you are gonna be writing the Python, not someone's gonna be handing it back to you.

27:23 Allen Downey: Exactly.

27:25 Michael Kennedy: That sounds really great. Do you think that this would be, I'm sure would be possible, would this be a likely thing without iPython notebooks and Jupyter and all that kind of stuff.

27:33 Allen Downey: It certainly could. I think it would be less good. I think one of the nice things about Jupyter is the students can just check out a notebook and there's a nice pedagogic process there where the first time through they can just read the code and execute it and see what it does. And maybe on the second pass, they are just making small changes, like try and experiment, change your parameter put a couple of extra statements here or there and I think you're modifying code. You can learn a lot from doing that before they get to the third step. Which is really okay, now you're gonna create code from scratch.

28:09 Michael Kennedy: Sure, I think that's nice to start that way. Especially this is almost like their first programming course at least for some of them. So they come in and say well what if we moved three bikes a day instead of just two. How does that change equilibrium and play with it and you have the nice pictures, yeah its pretty cool.

28:25 Allen Downey: And there's a lot of room for the students who are just learning to program. We're gonna have kind of the lower bound that says okay we want to make sure that everybody gets to this level. At the same time, people who are coming in with experience or people who just pick it up quickly, they can go crazy. There's a ton that they can go and do.

28:41 Michael Kennedy: Yeah cool, so what are some of the libraries you're planning on using for this?

28:46 Allen Downey: Lot of it is SciPy. I mentioned some of the tools in MatLab. We need an ODE solver and there's a good one in SciPy. Route finder, optimization tools, that's basically it and that's coming straight out of SciPy. And then the other library that I'm looking at is called Pint. And this does units; units and dimensions. This I think if this works, will be really good. Because we are doing physical modeling. And in physical modeling, everything is a quantity. If you tell me that the answer is five, my question is gonna be five what? Five meters, five seconds, tell me the units. Tell me the dimensions. So one opportunity here is to do computation where every quantity has its units attached to it and they carry through the computation. So if you try to add two things, its gonna check to see if they have the same units and if they don't, its gonna give you an error.

29:47 Michael Kennedy: You can't add joules and kilograms. What are you doing?

29:49 Allen Downey: Exactly. And if you look at the number of real scientific and engineering projects that have run into problems because the units got messed up including I think it was at the Mars climate probe, that was destroyed because they had I think both feet and meters and that was the end of that.

30:10 Michael Kennedy: Yeah that's truly unfortunate. We in the US, probably have a little bit of blame to take for keeping the imperial units still around.

30:21 Allen Downey: Oh yeah.

30:22 Michael Kennedy: The rest of the world is trying to move on and we're like no, we love our feet.

30:26 Allen Downey: Still measuring things in grams per fortnight.

30:28 Michael Kennedy: Exactly but even so, you still have centimeters versus meter. I mean there's certainly room for this error even in the unit system, the metric system. You mentioned Pint earlier when we were getting things set up and I had forgotten. I did check this out. This is really cool. So you can say create one of these Pint type things and you can say three times meters plus four times centimeters and it will make that 3.04 meters. Things like that, it really makes it obvious and easy.

30:57 Allen Downey: Yes, so it will do error checking or if you multiply two things together the result will have the right units. And it will reduce units, so if you express something as some crazy combination, it will say oh that's joules.

31:10 Michael Kennedy: Yeah really, yeah Joules is a crazy unit. I think this highlights one of the things where say MatLab or one of these package systems is kind of nice in that its self contained and what not but I don't think MatLab has this concept of this pint library. If it has the pint, there's a 1000 other Python such libraries that are really cool to bring into just sort of make it more expressive.

31:35 Allen Downey: When you are comparing languages, there is theoretically all languages are equivalent in the sense that they can compute all computable functions but there are pragmatic things. There are some things are hard or easy, but there's also culture which is around MatLab culture people tend to write fairly simple programs that are mostly script like in the sense that you are just combining existing features. You are not often writing functions or functions that use other functions. You are not writing objects. You are not building up layers of abstraction.

32:12 Michael Kennedy: Right you are not building reusable concepts. You are taking other people's reusable concepts and making it like a final product. Maybe not a well factored one but something that like this is done when this runs. I'm not gonna like open source this in a way that other people can easily build on probably.

32:29 Allen Downey: I think that's often true and not because its impossible, I mean I think there is object oriented MatLab out there, but its not commonly used. When you come to the Python cultural ecosystem its more of a software engineering world. There is more abstraction, more functional decomposition more object oriented programming. So at the risk of starting a programming language war, the overall level of software engineering tends to be higher so the tools you're working with are more abstract and then from my point of view, as an instructor. Now I can build abstraction to put between the students and the tools that they are using. So I'm making a library that's called Most of what the students do at least when they're getting started is, they're gonna use things from my library so I can put wrappers around things. I can hide the details that they don't need to know about yet. If I see them making the same errors over and over I can generate really good error messages. I can do argument checking and I can just help them get over what I know the rough spots are gonna be.

33:40 Michael Kennedy: I think that's a great point. I've had a couple of people who were teaching classes and then they've had students, teaching classes that were somehow computational and using Python, said why do I need to learn Python? Can't I just learn MatLab or Mathematica and just go on. I've asked Jake VanderPlas what he thought about this, what he would respond, what would you tell a student who comes and says I don't really want to learn Python or programming. Can we just use MatLab for this example or this class.

34:10 Allen Downey: Well you could and I'm not trying to say I'm not a total zealot. And we've been teaching MatLab for this class since 2009. Its not impossible, its not terrible. I think its an okay first language. But I think Python is better. I think its a better first language. Just I think the rough spots are smoother. Its easier to get started. And its a general purpose programming language which means that all of the effort that you put into learning it will pay off not just for this class but for any other class that you are taking so you get a little bit more reward from that investment.

34:46 Michael Kennedy: Yeah I think that's really interesting and I think Jake VanderPlas maybe even touched on this on his keynote at PyCon last week in that not everybody who goes through an engineering program or astronomy program or whatever is going to be just an astronomer or just an engineer on the other side. And so learning something like Python gives you a super marketable and flexible skill. Learning something very focused in that discipline makes it less. So its also good job diversification possibly I guess.

35:18 Allen Downey: Yeah I think that's right. I'm teaching at an engineering college so in some sense, we are focused but not all of our students are gonna be engineers. One of the things that we say is that engineering education is great preparation for a lot of things. Not just engineering.

35:33 Michael Kennedy: Sure and you could go work at something like Autodesk and work on AutoCAD for example. Or something like some company that makes software for engineers but you could end up only using a little of engineering and a lot more programming skills.

35:46 Allen Downey: Sure yeah.

35:48 Michael Kennedy: Hey everyone, Michael here. Let me take just a moment, and thank one of our sponsors, who makes this show possible. This portion of Talk Python To Me has been brought to you by Rollbar. One of the frustrating things about being a developer is dealing with errors, ah, relying on users to report errors, digging through log files trying to debug them, or, a million alerts, just flooding your inbox and ruining your day. With Rollbar's full stack error monitoring, you get the context, insight, and control you need to find and fix bugs faster. Adding the Rollbar Python SDK is just as easy as pip install Rollbar, you can start tracking production errors and deployments in eight minutes or less. Rollbar works with all the major languages and frameworks, including the Python ones, like Django, Flask, Pyramid, as well as Ruby, .NET, Node, iOS and Android. You could integrate Rollbar into your existing workflow, send error alerts to Slack or HipChat, or automatically create new Jira issues, Pivotal tracker issues, and a lot more. They have a special offer for Talk Python To Me listeners. Visit, sign up, and get the Bootstrap plan free for 90 days. That's 100,000 errors tracked for free. But you know, just between you and me, I hope you don't encounter that many errors. Give Rollbar a try today, just go to You talked at the beginning about your book, did you say the title? Think Python right?

37:06 Allen Downey: Think Python yes.

37:08 Michael Kennedy: That's a really great book and its almost like Computer Science 101 getting started with programming right?

37:15 Allen Downey: It is, its meant for people who have never programmed before so it really starts from x = 5, this is a variable, this is a value but its meant to be mostly language agnostic. So the principles are the same across lots of different programming languages. Certainly the family of imperative programming languages. In fact now there are translations of the book in Java and Python and actually the most recent one is Think Perl 6. Just came out this week.

37:50 Michael Kennedy: That's pretty cool, very nice okay. What other books have you written? I know you talked about your digital signal processing one.

37:58 Allen Downey: That's Think DSP, and then the two data science books are Think Stats, which is mostly about exploratory data analysis. And then Think Bayes, which is specifically about doing Bayesian statistics.

38:12 Michael Kennedy: Are those open source in the same sense that Think Python was?

38:15 Allen Downey: Yes, they all are. So those are all my web page is, Or if you just Google my name.

38:24 Michael Kennedy: I'll be sure to link to them as well in the shownotes.

38:26 Allen Downey: Great and so all the books are there. As I said, not all under exactly the same licenses but they're under free licenses. And then Think Complexity, is the other one, which is about complexity science. I'm working on the second edition of that one now so that's a work in progress.

38:42 Michael Kennedy: That sounds interesting. Give us a sense of what complexity science is.

38:45 Allen Downey: Its kind of an odd set of topics. One way to think about it is its the physics of complex systems, systems where you have components that interact with each other.

38:56 Michael Kennedy: Like three body problem and gravity, something like that?

38:59 Allen Downey: Yes, so that would be an example of a system that gets chaotic and among continuous mathematics those are interesting systems too. And then in discrete math world there are things like grids and cellular automata so things like Conway's Game of Life and Stephen Wolfram's work in CA's, cellular automata. And then also graph models. Things like small world networks and scale free networks. And agent based models, one of the big topics. So voids, things moving around in three dimensions. Or there are some economic models like Sugarscape and Schelling's model of segregation so those are some of the topics.

39:41 Michael Kennedy: Yeah that sounds really interesting. I just need an excuse to study them but it sounds cool.

39:45 Allen Downey: Its great stuff and they are fun. They tend to have a lot of leverage like a small amount of computation for a lot of very interesting results. And there are philosophical implications to almost all of it. So almost every chapter ends with here's some reading that you might want to do from the philosophy of science because we've just come face to face with instrumentalism and reductionism and all kinds of other isms.

40:14 Michael Kennedy: Yeah cool. It seems to me if there are parents out there listening who have to help their kid with a science fair presentation, you could probably take something pretty interesting from there and put a little simulation on it and make that aside for presentation.

40:28 Allen Downey: Its pretty good. Its not as good as the volcano with the baking soda but Game of Life is pretty good.

40:34 Michael Kennedy: Yeah for sure. So another one that you are working on is called Think OS, right?

40:39 Allen Downey: Yes.

40:40 Michael Kennedy: That one looks interesting and this takes people who's sort of you assume the reader knows Python and says alright lets write an operating system and see.

40:49 Allen Downey: Yes, so this is filling a gap that I think has opened up in the computer science curriculum because it used to be that the intro classes were often in C or Java or languages that are similar so that when people get to the operating systems class they already know a low level language and now they are ready to find out how to implement an operating system.

41:12 Michael Kennedy: I think you are right that this is changing and its for the better in the large scale that people are starting with the higher level languages. I think even with Java if you learn Java and you stay in a manage language or you learn Python which is more common these days, understanding malloc and all of these sorts of low, low, low level things is pretty new right?

41:35 Allen Downey: Right and that's a good example. I think memory management is one of the gaps. So now when students get into a second or third computer science class, now maybe they need to learn C but they need to learn memory management. They need to learn a lot about that kind of system level what are the operating system calls look like. What are those APIs? So Think OS is an attempt to fill in some of that space with on the one hand we are gonna learn system level programming in C and on the other hand, we're gonna learn about operating systems, but what we're gonna learn is the stuff that you need to know in order to be a good application level programmer.

42:19 Michael Kennedy: Right I think you need to know C to be a good professional programmer. I don't think you need to do it all the time but I think knowing really what happens down at that level really what does that mean for pointers to do their thing. What does it mean for memory management and so on and have that experience that's pretty important. Even if you spend 99.9% of your time in Python or something.

42:42 Allen Downey: Yeah I think I agree although I tend to be skeptical about people telling me what everybody needs to know.

42:51 Michael Kennedy: Yes of course.

42:53 Allen Downey: But I think you're right. At the very least one of the things that you're gonna have is a mental model of what's happening while your program is executing.

43:01 Michael Kennedy: I'm not necessarily, I said C, I'm more thinking like just a language that you need to have a concept of how the thing actually runs. That's more of what I'm trying to say and I think C is probably where most people get that model.

43:15 Allen Downey: Yeah I agree and maybe it used to be assembly language. So we are still moving up but I think you are right in that you're gonna have a performance model as well of what's fast and what's slow, so when you start writing at the application level if you are surprised, if things are slower than you expected maybe you can debug that because you know what's going on one level down.

43:37 Michael Kennedy: Enough tools to go and explore that and go oh I see why this is happening, rather than that's weird. Didn't know that would be slow because that just won't do that anymore. Interesting okay so I think that is a really cool book so if you come in from Python and you want to get some experience in C sort of tailor made to take you from that one step to the next is cool and certainly understanding operating systems is good as well. Let's see, where you are going with courses in this, do you have other courses that you're teaching? Do you have other areas you are trying to explore this like let's use computation to help people understand stuff in the right order, not the reverse order?

44:19 Allen Downey: Right, I've got a bunch of projects that I work on in parallel so I mentioned complexity. That's the immediate project. Sort of medium to long-term, I'm still thinking about linear algebra. I think there's a big opportunity there for people to really understand that in a way that lets them do things with it. I think a lot of people who have studied linear algebra they walk away with a vague notion that they can prove things about matrices but not necessarily a lot of skills for really using the entities of linear algebra to do work. To solve problems by expressing them in that vocabulary.

44:59 Michael Kennedy: Right I could tell if a matrix is singular or I could do various other things to it but there's no useful skill I could take away from this right basically. Its the way lot of people end up experiencing it I suspect.

45:11 Allen Downey: Yeah that's another place we are doing things computationally can flip the order. You can go top down, starting with applications and gradually understanding how they work.

45:20 Michael Kennedy: Alright well that all sounds really fun. Do you think that we should be trying to get this computational stuff in middle school like 10, 12, 13 -year-old kids? Maybe little bit less math; a little bit more programming or something or how do you think we could take this in and make a more, so its not something they experience when they get to college but sort of everyone gets a chance to see it?

45:45 Allen Downey: Yeah I know. I think everybody should see it and earlier than that I think you can do it in elementary school for some definition of do it. What I'm talking about is using computational tools in the context of whatever it is that you're studying at a level that's appropriate for where the kids are. It can't be another class. You can't go and study English for an hour and then math for an hour and then computing for an hour. I think the computing just has to be embedded everywhere just in the same way that we use paper and pencil as a tool, we should be using computation as a tool but not just using applications that other people wrote. There should be a gradual process of programming for some definition of programming. For basic things, languages like Scratch that are block based, where you are just organizing computational elements gradually working up to general purpose programming languages.

46:44 Michael Kennedy: Yeah I totally agree. I think it would be great to see that. I suspect we will see that over time but who knows when it really kick in at that level. That's a pretty big battleship to turn the curriculum for children.

46:58 Allen Downey: Yeah no question.

46:59 Michael Kennedy: Alright we are getting near the end of the show, so let me ask you the two questions I always ask everyone. First, if you're gonna write some Python code, what editor do you open up?

47:10 Allen Downey: I do most of my programming in Emax. And then more recently I'm writing more and more of it in Jupyter Notebooks while I'm exploring. And then at some point I end up taking that code out of the notebooks and putting it into modules and then either Emax or other IDEs.

47:27 Michael Kennedy: Alright excellent. Most notable or favorite PyPI Package? We're over 100,000 by quite a ways now.

47:35 Allen Downey: Right, I guess Pandas is probably the thing I'm spending most of my time working with. I love it. I did a lot of statistics using my own tools for a while and I ended up just writing a whole lot of pointless code that I never should've written because 90% of what I was doing would've been a one line pandas method. And then the other package I mentioned is Pint that I'm very interested in. Again for doing computation with quantities that have units.

48:05 Michael Kennedy: Pint is really simple. Pandas is something that's very powerful but definitely take some study into really leverage it but its great as well. Alright so for the educators, for the students or even professional programmers listening in, what's the final call of action? How can they take these ideas and do more with them?

48:22 Allen Downey: So the physical modeling project, as I said, I'm working on that this summer. We're gonna be developing that course and I'm really interested to hear from people who are doing physical modeling of lots of different kinds. In particular, we are probably gonna start with population models and other discrete things where you've got either animals that are breeding or I mentioned bicycles moving from place to place so discrete things moving in discrete spaces. And then probably some first order systems like thermodynamics and chemical kinetics, maybe some pharmacokinetics. So just looking for examples that are interesting because the applications matter. So real world problems that have consequences and really examples where you have a simple model that does a lot of work for you that you can take a complex physical system and describe it with a model that is just the right amount of simple.

49:24 Michael Kennedy: The interesting problems that are not so complex, they are too daunting right?

49:29 Allen Downey: Right, and really do something with that you know you are either making predictions that are real predictions that people care about or explaining something that's genuinely an open question or doing design, where you can actually optimize something by modeling it, finding an optimum and then building that product or whatever the system is.

49:49 Michael Kennedy: That's really cool. You said you're gonna be working with this thing called for this class. Is that gonna show up on GitHub and could people come give you feedback and stuff on it?

49:58 Allen Downey: Yeah I will probably start the GitHub repository soon. In fact I might already have. We will have a link to that.

50:04 Michael Kennedy: There's a little bit of time, interesting. So whenever you get it done, even if it comes out after the podcast, send it to me, and I'll put it in the shownotes. People can then go and check it out. Alright Allen, thank you for being on the show. Its really great to chat with you.

50:15 Allen Downey: Thank you very much. It's been a lot of fun.

50:17 Michael Kennedy: Yeah you bet, bye. This has been another episode of Talk Python To Me. Today's guest has been Allen Downey, and this episode has been brought to you by Linode and Rollbar. Linode is bullet proof hosting for whatever you are building with Python. Get your four months free at Just use the code Python17. Rollbar takes the pain out of errors. They give you the context insight you need to quickly locate and fix errors, that might have gone unnoticed, until your users complain, of course. As Talk Python To Me listeners track a ridiculous number of errors for free at Are you, or your colleague, trying to learn Python? Have you tried books and videos that just left you bored by covering topics point by point? Well, check out my online course Python Jumpstart By Building 10 Apps at to experience a more engaging way to learn Python. And if you are looking for something a little more advanced, try my Write Pythonic Code course at Be sure to subscribe to the show. Open your favorite podcatcher, and search for Python. We should be right at the top, you can also find iTunes feed at /iTunes, Google Play feed at /play, and direct RSS feed at /rss, on Our theme music is "Developers, Developers, Developers" by Cory Smith, who goes by Smixx. Cory just recently started selling his tracks on iTunes, so I recommend you check it out at You can browse his tracks he has for sale on iTunes, and listen to the full length version of the theme song. This is your host, Michael Kennedy. Thanks so much for listening, I really appreciate it. Smixx, let's get out of here.

Back to show page
Talk Python's Mastodon Michael Kennedy's Mastodon