- Podcasts
- Programming Throwdown
- Python Programming Language
About this episodeThis show covers Python, a popular interpreted language. The show begins with discussion on javascript and browser updates, then goes into…
This show covers Python, a popular interpreted language. The show begins with discussion on javascript and browser updates, then goes into the Goldman Sach's stolen code trial, eco-friendly programming, and the origins of Oregon Trail. The tools of the day are Fossil a distributed version control system and Unison, a two-way file synchronization utilities.
★ Support this podcast on Patreon ★Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
Python Programming Language
Yeah? I've been—I've noticed that I turned to YouTube for learning just about anything. Like, I wanted to cook snow crab, so I went on YouTube and I saw how to cook it. And then I cooked it, but you know, the snow crab has a really tough, you know, exoskeleton. So I couldn't figure out how to get the meat out of the crab. So again, I turned on YouTube and put in 'how to eat the snow crab.'
guy on wrote a book. I think it's called Moonwalking with Einstein. Supposedly it's about a guy who tried to become like the world or U.S. champion of memorization. And I don't know. I haven't read the book. I just heard about it, but it sounded interesting. I'm about to check that out because I always wanted to have better memory. I'm pretty terrible at it.
Yeah. So this guy, basically he built himself like a base-300 number system where he took a bunch of words and he associated them with large numbers. So he can do really amazing things. Like he's like, you know, give me two six-digit numbers and I'll multiply them in my head. And he does it by converting each of the numbers to—it might even be more than 300, but he has this whole lexicon and he knows that like 'slippers' is 493 or whatever, you know? Wow. And so he converts your number to some really high base and then does the multiplication in his head and then converts that.
is the best. It's true. It's like everyone you watch is like, oh man, this is life-changing. And then you get to the next one. And although, you know, they've been going downhill. Yeah. They franchised. Yeah. They franchised. And now like the TEDx Talk sometimes take the front page and you can just tell the quality isn't there, you know?
So the first news story I had was an interesting thing, you know, had a little bit of delay in recording this podcast. So I saw this a while ago, but I thought it was really interesting that with the new version of the iPhone OS, iOS, I guess iPhone and iPad and iTouch. But Apple had an upgrade to their JavaScript engine. And I don't know if they started calling it this, which is what's always been called, but I guess it's Nitro. I know, I think Google's is V8 or something. So everybody, I guess, has their own cool name for their JavaScript engine. But they made a bunch of performance updates to actually improve the speed of JavaScript on their iOS platforms. And it did a really good job. And everybody's pretty excited about it. But then people figured out that if you do, if you don't have an iOS device, you won't know this, but you can like bookmark a page, a webpage to your desktop basically, and run it from there. It's like if you double-click on it, it's like a hyperlink and it just kind of runs it in the browser. Oh, sorry. No, no, no. So you can do that. But I was missing. Some people just have apps that run basically websites from within the app. So they're kind of like an embedded browser or whatever. But they're really just like Google's works this way. So Google's app mostly just, you know, references stuff on internet. And if you're using, I think the way it works is if you're using the embedded browser instead of using, you know, natively written iOS stuff, you don't get the speed-ups that they gave to all the other Safari stuff. So it's kind of an interesting thing that they left—I guess it could be a bug, but people are suspecting maybe they did that on purpose. So how
Right. I guess they were saying for possibly for security reasons or something, but I thought that was interesting that they, yeah, that they would, you know, kind of cripple those. Interesting. Because you can do with the HTML5 stuff, you can do a lot of things that you would normally do in a native app.
Apple is always so paranoid about someone writing some app that compromises, you know, either the hardware itself or even worse, like your information or your contacts or something like that. Right. So maybe in doing so they left out, you know, some of these updates. Hmm. I always felt like, you know, there should be kind of like one browser engine to rule them all, you know, like, and there's, it's kind of starting to head this way with WebKit. Like WebKit, WebKit is, I believe it's on the PlayStation and WebKit is part of, you know, Google Chrome. It's like the engine for that. Yeah. But yeah, there's no like just generic engine that isn't really tied to like a particular OS or anything like that. Like there's no, there's no web engine that just writes to OpenGL or something like that.
But I guess that's good because, you know, the competition between them, they drive features from each other. So kind of relating, spilling, transitioning into our next topic, you know, talking about the new release of Firefox 4 and IE 9 that they've both picked up, I guess, what was started with Chrome, I believe, with the tab styles where instead of having the traditional File, Edit, View menu, whatever at the top, they just kind of have tabs at the top and they get rid of a lot of that extraneous stuff unless you go looking for it. Right. So I guess that's good, right? Because if you only had one, it just would have always stayed kind of what it was.
Yeah, that's true. That's true. I just, I feel, I think that because, you know, what they want to do is, is tie into the theme of the particular operating system. So like in the case of Windows, if you change your theme, they want, you know, to, that theme to be reflected in your browser windows. Which makes sense. And so, yeah, that's fair. And, but because of that, they're kind of tied to, you know, those particular OSs. So there isn't just some generic, like, right to a frame buffer or something like that. Yeah. You know, web layout engine. So have you downloaded the new Firefox? No, not yet. I want to. I actually, I have the beta on one of my machines and it seems to run well. I haven't had any, any crashes or anything with it. But one thing I have done is in Google Chrome, I went ahead and changed my YouTube settings so that they use HTML5 instead of Flash. That was pretty cool. They didn't have the, like, seeking in the video. I don't know if maybe I'm using too old a version of Chrome or something, but I have to play a video all the way through, which kind of sucks. But, but the support is there. I mean, it's using the, you know, the on four, I guess, video codec or on one or something like that. And yeah, it works nice. Works well.
Hmm. Yeah. So I've been using Firefox 4 since, yeah, like, I guess it's like beta 4 or beta 5 or something. It's been a while and I kind of went upgraded. It was even pretty good back then. And yeah, it's been nice. I haven't really noticed that much difference to going to the actual, you know, now the full release. But yeah, I've been running it for a while and things have been nice. A couple of the plugins I like to use haven't been ported over yet, I guess. But other than that, I've had no problems.
Oh, nice. Oh, it's called On2. On2 is the company that Google bought and they created their own video codec called VP8. Oh, yes. Yeah. The interesting thing about it is there's no patents at all. I guess it's a completely different, you know, setup or a completely different algorithm than, you know, H.264. And when Google bought it, they opened it up completely, which is really useful because anyone who's done video compression knows, or even audio MP3 compression knows what a nightmare that stuff is with respect to patents and all that.
Yeah, that's interesting. I wonder if, you know, Microsoft decided to really kind of pick it back up because they have just gotten so much flack. Nobody seems to like Internet Explorer. And remember that thing on the White House where somebody asked Hillary Clinton if they could have Firefox in the White House? And she, you know, she clearly had no idea what Firefox meant. I mean, for her, it was like she thought that something was burning.
That's funny. All right. So it looks like you got the next news item here. Yeah, let's see. Okay. So former Goldman Sachs employee goes to jail for eight years. And so the deal is this guy, you know, he worked for Goldman Sachs. He's making, let's see here. I think it was, yeah, 400,000 a year to write code for their high-frequency trading applications.
Yeah, insanely fast. And I think they do arbitrage, but they also speculate, right? You know, in that short amount of time. Yeah. And so this guy is writing the software that, you know, essentially becomes an arms race. You know, someone has this kind of software and then he writes this, you know, software that learns to exploit their software and so on and so forth. But they're paying him $400,000 a year. And he decided that he was going to take his software over to a small company that they offered to double, I think double his salary. So he tried sneaking the software into that company. He got caught and he got eight years of federal jail time, which is serious business.
is interesting, right? For several reasons. One, it's, you know, he didn't actually make any money off of it or steal any money. So in that respect, it seems like eight years is extremely serious. You know, but this goes to show that, you know, people in companies take this stuff extremely seriously. And it's your responsibility, you know, as a software engineer to, you know, be ethical in these types and not try and pull these types of shenanigans. Yeah,
Definitely. That's, I mean, I guess it's good that it shows that, you know, he didn't get off easy for doing something that's, you know, stealing essentially the livelihood of the business. Not that I'm a big defender of the banks, but still. Yeah. Yeah, exactly. It's wrong. Yeah, definitely. Yeah.
know, programming languages usually serve one of several purposes. One is, let's say efficiency, in the case of C or C++, where you just really need to push data through or do some real expensive computation. Or they work on the, they try and maximize productivity. So Python, one of the languages that we'll be talking about later today, is sort of focused on productivity and trying to save your time and be programmer efficient, if you will. No one really that I know of has up until now looked into this energy-efficient computing. So this is really quite interesting. And as we're moving to mobile devices, and in general, as being green is kind of in right now, this was, you know, this has been written all over it from a professor's standpoint. Yeah. So he got some really nice grant money. And I thought this was pretty cool. Pretty cool stuff. I like to see what comes out of it.
Sure. But those seem things that would, you would do already just to improve performance. I guess if you're willing to sacrifice—this would be a hard thing to do—but if you're willing to sacrifice, you know, kind of the deterministic execution speed, you could, you know, do things like pausing and collecting up all the disk accesses or RAM accesses accessing at one time and kind of doing them all in a bundle, even if it means waiting to do it. But it seems like they kind of already tried to do that.
I mean, I've heard before this is at a much, much lower level, but the whole idea, which is extremely fascinating. And if you want a time sink—a black hole of your effort for the next couple of days—look into reversible computing. Really? So the idea of there's this whole, and I'll quickly show how much I don't know to anybody listening who knows anything about this field. But, I guess it comes down to kind of information theory that one of the reasons why we're hitting an upper limit on the density of transistors and doing stuff in our chips. And is that when you do an operation, so like an AND, right? So you do one AND one is one, one AND zero is zero, but zero AND one is also zero. So you're losing some information there that that operation's not reversible. Neither is an OR. Most of the operations are not reversible. XOR is reversible, right? Cause you just nod it back so that you don't actually lose any information. So the idea is that when you destroy information that is kind of somehow related to energy. And so when you lose information, you know, kind of destroy it, you're going to expend energy that that information has to go somewhere and it dissipates into heat or whatever. And so the idea with reversible computing is to say, if you can kind of keep track of all these sets of operations and be able to at some level undo it, and you kind of accumulate this log of everything, that you'll run more efficient. And then at some point you could kind of choose to get rid of all the information, all the bits you don't need and kind of exude power at that point on your terms and your choosing. It's very—it gets very weird. And the information theory gets crazy. It gets tied in with like, you know, black holes. I think it just blew my head. Black holes destroy? Do they destroy information or not?
So I don't—the way I've seen it explained is with billiard balls. So you can make an AND gate out of billiard balls, but you can also make that kind of, you end up with, so if you do an AND, you end up with the output of the AND and also like another bit that represents to distinguish between the zero one one zero case. So you end up with this extra bit of information that kind of allows you to know how you got to having the zero, whether it was from two zeros, a zero one or a one zero. And so you kind of record or maybe you end up—yeah, maybe you end up with three bits. Somehow you end up tagging along that extra information that allows you to reverse the computation. Anyway, like I said, it's a time sink. I don't really understand it. And I probably just made a bunch of people who know what they're talking about realize how stupid I am, but that's okay. No, I think you just made them angry, which is
If you hate us, give us five stars at the worst rating you can give us on iTunes. So, this is—so I think also not just extending, you know, he's in this particular article, they're talking about making energy Java, which is an extension of Java that would somehow be more energy efficient, but also more different languages I think would be inherently more energy efficient provided that you're running on a multi-core system. And so, for example, you know, a GPU per watt or whatever can deliver a lot more computation than a CPU, but it has limitations because, for example, all the cores in a GPU have to execute the same instruction at the same time. So if you can, if you have a programming language or a construct that sort of helps guide you to work within those limitations, then maybe something that is like very highly multi-threaded could allow you to save energy because that's really where a lot of the energy is wasted and is in the bottleneck where you have this huge bank of memory but then only one small tiny sliver of it can be used at one time on a single core processor.
we knew the answer, we wouldn't need to research it. Yeah, exactly. Yeah. So, this is a news article on Brainiac and it was on the origins of Oregon Trail. And I don't know if you had this or if this was just something that we had in Canada, but in Canada we had these Apple IIEs, you know, there was like a computer, I don't know, I guess using period in school. And we'd jump on these Apple IIEs and play Oregon Trail and Odell Lake. And did you guys do that?
and designed by some teachers who just happened to be really geeky and into coding. And they were inspired by choose your own adventure books. And it was really, you know, the thing about Oregon Trail is it's a complete simulation. I mean, it's very egocentric. It's not like other wagons are passing you by or anything like that. But in the sense that, you know, you're traveling along this trail and you're having to deal with hunting for food and the environment can influence, you know, the hunting grounds and things like that. It's almost a complete simulation, which makes it just very interesting that something, you know, this old, that old could be that powerful.
Oh yeah. It's great. www.virtualapple.org. And it has a number of Apple IIe games. I'm not sure. It says that it's copyrighted, all rights reserved, et cetera, et cetera. So I'm not sure what the legality of it is. But you know, it seems legitimate. It doesn't seem like it's that they're doing anything illegal. Maybe they have permissions. I'm not sure. But the Oregon
Yeah, I mean, at nine years old, you know, we had no idea. So there was this river. It was like, uh, I don't know, Swanee River. I don't remember. But it was, it was something like, like 20 feet deep. And I was like, oh, yeah, just fjorded. Just walk across it. You know, and then, you know, you lose everything. You have been washed away. You end up crying at recess. Yeah.
Oh, okay. We're nerds. All right. So my tool of the day is a cool distributed version control system. So, you know, in the vein of Git, Mercurial. What are the other big ones? There's a couple other ones. But, um. A Subversion. Well, Subversion's not distributed, though. Oh, that's right. So, um. So distributed ones. But this one's interesting. So the thing I kind of like, and I've been trying to do better about, um, it's not really the new year anymore, but my semi-new year's resolution for the last couple years has been to do better about version control at home/for personal stuff. And, um. One of the nice things, Subversion has some tools that will let you do that, but it's not really set up to do that. The nice thing about the distributed stuff is that that's kind of how it always is, is you can just have a repository on your local machine. And then at some point, you kind of merge repositories with other people who, um, could have previously, you know, had a version from yours. And they kind of split up and move throughout. There isn't one central repository that's the repository everybody refers to. Um. So that kind of confuses people, makes it a little bit hard. Um. And I'm not an expert by any means on version control, much less distributed version control. But Fossil's nice because it's a single executable, um, that you put in your path and you're able to, so I use it on Windows and you're able to like check stuff in and out and there isn't a complicated, you know, system behind it. Uh, I've used Mercurial before and get to some extent and they're, they're nice, but they're kind of, you know, tangled up in, they do a lot more. This, uh, you know, I guess it probably does a lot, but it's really simple. Just, you know, one executable, really basic. And I've been using it to do, um, you know, version control on my local computer for stuff that I should have been always using stuff for and just haven't really been doing.
This looks nice. I have had so much grief with Git, um, using GitHub. I've gotten to the point now where I use the, um, I use the Tortoise Git to do a Git commit because I like that interface better and it integrates with Explorer and all that good stuff. But then I have to use the Git GUI, which is a separate program that comes with Git to do the push. It has something to do with like, I could never get the SSH key working right in Tortoise Git. And I've just, it seems like I just have so much trouble with Git. So this, this looks awesome. Definitely going to check this one out.
Yeah. So I, you know, like I said, I'm not an expert, but I liked it and it has the ability to set up a server within it. So like, you know, I could put it open and then, um, somebody else on my network could, you know, download my repository or whatever and clone it. So it's nice. I like it. It's worth looking into.
really get people mad at me now. Quiz mode. I'm really going to get people mad at me because I, I'm ashamed to say I'm not very polished on my knowledge of version control. But, um. No, me neither. So the way I understand it, is, you know, Subversion CVS, they kind of work on the idea of a central repository. There's one location that is the master and you, um, depending on your workflow and the exact nature of the system, you check out files or, you know, get a copy of the repository, work on your own. And then you submit back to that central repository. So you can like lock files there, um, you know, work on them and then resubmit them back with changes. And then other people go check against that, can pull changes, um, you know, do their updates, fix stuff, whatever. Um, the difference with a distributed version control system, uh, is that certain operations, which are complicated to do, um, in one of these others are become very easy to do. Like branches, branches are really easy to do. Um, and having multiple versions of the code existing at one time, like, you know, eight different kind of parallel paths going at one time, isn't really a big issue. Uh, and the way that you do, and even on your computer, having multiple versions is easy because there is no central repository. Uh, you can have one, right? Like you and I could say, oh, we're gonna, you know, host, uh, you know, on GitHub, that's our, you know, official repository. But in reality, it's just another version of the repository. And everybody's is just as important or, um, authoritative as anybody else's. And so for instance, I could, um, push to you my changes. You can make them in your repository and then you could push them up to the GitHub server. Um, I don't have to push them up to the GitHub server. You get them, bring them back down. We can like share with each other and co-mingle those because there is no, you know, one branch that everybody has to come down from.
Oh, interesting. Yeah. I mean, in Subversion, if you were to create a new branch, you would have to go to the master server and say, hey, I want you to split, you know, and make a new branch for me. Whereas it sounds like with this system, um, you're making your own branch and, and, uh, it has nothing, you don't need the server's permission. And the server doesn't even know you have your own branch. Right.
Right. And I can make multiple revisions, multiple check-ins against myself for those to you, merge some changes, do additional, and then you merge back to the quote unquote, you know, central, you know, authoritative, whatever base. And, um, then if you actually look at the, it's kind of cool when you look at the, you know, version history, you see all these merges and splits and you can do things that would just cause a nightmare under most repositories. Oh, nice. That's good stuff.
My cool, my tool doesn't have fossils or tiger blood, sadly. But it is actually extremely useful. I've been using it for a while now and, it is, I think it's fantastic. It's called Unison. And specifically I'm talking about the Unison file synchronizer. So what this does is you give it two directories and they could either be local directories or one can be an FTP. One could be an SSH, you know, an SSH location on the remote server. And it essentially compares the two directories recursively and then gives you a list of changes. And it can do this in a variety of different ways. It can compare the dates. It can actually compare the content. And, in the end it presents you with this list. If one of the files is newer on one of the directories than the other, it will automatically suggest to move the newer file over to the older one, and vice versa. Otherwise if it can't figure it out, either because it doesn't have access to one of the dates or it gets confused or something like that, or if both dates, both files have been modified since the last time you ran Unison, then it will put up a little question mark and you can make the call on do you want to diff these two files manually and merge them together that way? Or do you want to just pick one file or the other?
have a bunch of docs or a bunch of files on your USB stick, you don't want to run the risk of losing the USB stick and losing all of that data permanently. So you can run this Unison program and put your USB stick and then put a directory on your hard drive and it will sort of keep everything in sync.
But so I don't know if you use Dropbox before, but Dropbox, you know, uses their server in the cloud to kind of take data from a folder, store it there, and also push it out to other folders, kind of keeping them all linked up together. Right. And I've been looking for a version that I could host like in my home network and do the same thing across all my computers. So like keep all of my documents together. Oh, interesting. And there's no, you can do it with Dropbox. Like that'll work fine, but there's a limit to their free size and you have to pay if you want more. And I kind of just want something that, you know, I don't care about how much data it's syncing across. And I found one, but they're not in release yet and I haven't tried it yet, but it's called Sparkle Share. And that's kind of that. It doesn't help you with like USB sticks like you're talking about, but keeping, you know, multiple computers in your household synced. Like I'm constantly moving from my desktop to my laptop and I would love to be able to just know that all the files are on both and not have to worry about, oh, that's on my laptop. I need it on my desktop. Let me email it to myself or put it in a USB stick or whatever that's.
Yeah, this is interesting. This is good stuff. So. Yeah, it seems like, you know, it shouldn't be that hard. Like they have to kind of hook into the OS, but whenever they see that a certain file has changed in a directory at their monitoring, they can go and propagate, and give that file to everybody else. It's one of those apps that seems kind of straightforward, but then the devil's probably in the details
Well, is it time for the throwdown of Python? I think so. Let's throw it down. So, I guess I'll cover this. So, Python is an interpreted language. It is semi-compiled, which means that there is a Python Virtual Machine similar to Java, and you can compile Python files into bytecode for that virtual machine. Python.
I know it's the genies. They're just there. I think that, yeah, you're right. You have to be experienced in Python. And it's one of those languages that does come with a learning curve. One of the big things about a lot of these high-level languages like Python is that it gives you a lot of flexibility. But because it does that, you can kind of hang yourself with all the rope that it gives you. And so that's why, you know, having a strong foundation in one of the imperative languages kind of will allow you to sort of remain grounded in your architecture, even with all of the flexibility that Python gives you. So, why is it named Python? Oh, that's a great question. Do you know the answer to that? Or are
Interesting. So, let's talk a little bit about, more about Python. It's garbage collected, similarly to Java. So, in other words, you don't have to, you know, as you might remember from our C podcast a couple of weeks ago. In this case, you don't have to tell the system when to allocate or free memory. You just say, hey, you know, I have this list of data. I have this dictionary. And, you know, it's a dictionary of, you know, it's a dictionary of phone numbers. And I want the phone number of Joe to be, you know, 999-999. And it automatically decides, I'm going to create a dictionary. I'm going to allocate memory for that dictionary. There's a new entry. Maybe I have to increase the size of the dictionary to handle the new entry. It does all of that. So, you're completely oblivious to the memory manager.
Yeah, I mean, definitely. If you're working on a system that doesn't have a lot of memory, such as, you know, an embedded device, you have to watch out for running out of memory. And, in fact, with Python, this is especially an issue because it has a virtual machine. I believe the virtual machine has a memory limit. So, you know, in the case of C++, you can, for the most part, allocate memory and just keep on going, keep on allocating memory. And it'll eventually start putting memory, what's called virtual memory. It'll start creating memory regions on your hard drive. But it'll essentially give you the freedom to do whatever you want. In the case of Python, there's a hard limit in the virtual machine. And if you try and allocate, I don't know, 27 gigs of memory, it's just going to throw up. It's going to cause an error in the virtual machine.
if you've ever downloaded one of those off the internet, that's using Zlib. And Python supports that natively. So just let's look at that, for example. Let's say you wanted to write a C program that opened a .tar.gz file. Or let's say you wanted to write a C program that created one of those. You would have to go grab the Zlib library, compile it along with your code, read up on the API and work your way through that. With Python, all that stuff's included. So you don't have to worry about building Zlib and what sort of compile parameters you need to give it and things like that. All that stuff's in there. It has, you know, comma-separated values for writing stuff that could be read by Excel. It's got hashing, just tons of JSON encoding and decoding, email handling. It actually, the Python Standard Library has an HTTP web server built into it. So you can host your own website using just Python.
Yeah. So, you know, under the kind of one of our charter goals here is that help people, you know, see the uses of other languages. So, for instance, we talk about Python being helping you be more productive potentially. And so as part of that, you've got to learn those languages so that you can exploit the benefits to the fullest. So we talk about, you know, a little bit about our experiences, if we have any, with learning the language. And one interesting thing, if you're listening to the show and you don't yet know any programming languages, I think a lot of people consider Python a good first one to learn. What do you think, Jason?
Yeah, definitely. I think that, I think Python was one of the, you know, goals of Python was to sort of be simple to use and to understand. And it seemed like there was almost an educational focus to Python. And because of that, I think that, yeah, Python would definitely be a great starter language. One of the things that you really have to watch out for in languages like C and C++ are dealing with these sort of these really high level structures and manipulating structures and memory and reading and writing structures to files can be challenging. And so Python obfuscates all of that from you. I mean, you don't really have to deal with a lot of that low-level stuff and you can get right to doing what you want. I mean, typically, you know, what people want to learn programming is so that they can, so that they can do something, so that they can accomplish something—whether they want to write their own little web calendar to keep themselves focused or whether they want to just kind of make a game or something to entertain themselves and their friends. And you don't want to get bogged down in a lot of the details, especially as a beginning programmer or working on a project by yourself. And so Python really does a lot of that heavy lifting for you, you know, at the expense of being slower than one of the more low-level languages.
Yeah, definitely. And so my first kind of learning link that I had here is something I ran across. Of course, already, you know, having a fair amount of experience with programming, this was, you know, not that helpful to me, but it was really interesting. And I believe the guy who started this—but it's kind of a community effort now—I think his name is Zed, Zed Shaw, maybe. He has Learn Python the Hard Way. We'll include the link in the show notes, but it's learnpythonthehardway.org. It's kind of interesting. It's a book and it kind of goes through and says, 'Look, this is going to be confusing. When you learn these programs, it's not going to be easy and straightforward.' So he kind of starts out by going through stuff that, you know, would have kind of been nice in the I remember learning, you know, programming kind of on my own without before going to school for it or having a class on it. And it's he kind of takes you through what I think a lot of people end up doing, which is, you know, type this code in. You're going to make mistakes, but type it in, you know, just copy this code into a thing. Don't copy and paste it. Type it in. And you're going to begin to kind of understand, become familiar and intuit what the programming, what the programs are doing. And then also that'll kind of, since you've typed it in, you'll kind of lead you to experiment and start trying little things and seeing how it changes or reacts or what breaks, and kind of approaching it from that way, which is an interesting way. I hadn't really—it's a refreshing take on how to learn programming. Yeah, that sounds awesome. I'm definitely going to have to give that a shot. So the other resource I had here is PyCon, which is the big Python conference. I think just recently the 2011 PyCon happened; I think it was in Atlanta. Is that right?
Yeah, so Google has employed the creator of Python, Guido van Rossum. I believe he worked at a number of large, well-known companies, but right now he's been employed by Google. And Google is definitely taking Python seriously. They're one of only two diamond-level sponsors of PyCon 2011. So, yeah, they're definitely interested.
Here, I'll do it really quick. Okay. Basically, you know, most people are familiar with OSs, operating systems like Windows, Linux, OSX, etc. RTOS stands for real-time operating system. To make a long story short, basically, they operate within certain limitations. So, in the case of Windows, again going back to this memory thing that I talked about earlier, if you want to allocate, you know, a gig of RAM and you don't have a gig of RAM on your machine, it'll go into virtual memory. It'll make a space on your hard drive and treat that space as memory. So, a real-time operating system has certain limitations. Like, you cannot do something like that because it would take away from the real-time nature; it just takes too long to do something like that. And so, there are many other—it gets complicated. But the basic gist of it is that they're interested in high-performance, low-power operating systems. Interesting. So, yeah, actually, that gets to an interesting point, which is another lesson of this is it's true that Python has a reputation well-suited for being slow. But, again, it comes down to how the language is used and, you know, a lot of the algorithms that are going into the language. So, in other words, you can write some code in Python. Someone else who can write the same code in C, and it could be 100 times slower just because of the way that you designed your algorithm. Let's say they're constantly creating and deleting arrays, and in your case, you're able to use just one single array. So, a lot of the speed issues can be solved algorithmically or using—you know, being efficient in the way that you allocate and deallocate memory. And, you know, I wouldn't worry too much about Python being slower than other languages.
Yeah. I mean, especially for, you know, prototyping or even in full-up production stuff, I mean, using it as kind of like the scripting aspect. And we haven't talked about this yet, but Python integrates really well with C code. Yep. So, you can, of course, you know, one of the good paradigms to go by in your programming is don't optimize too early. Don't worry about getting your code to run fast. Worry about getting it to run first.
Definitely. And I think that, you know, to sort of extrapolate on that point, you know, the biggest thing I see with like a lot of kind of new or green engineers is that they'll write some code, but it will be slow and they'll sort of look at things which are somewhat myopic, like maybe if I do a compiler optimization or if I change languages or. But really, you know, there's something fundamentally slow in the algorithm or in the architecture that can give you just a gigantic speed up. Definitely.
Definitely. And being aware of how the computer operates, which we haven't talked about here yet. But I mean, understanding at a fundamental level why your computer does what it does, how it ticks, even down to, you know, not that you have to go that far. But we were talking about AND gates and OR gates a few minutes ago. But I mean, understanding a computer at that level helps you write code that uses a computer in the best way possible.
So, PyCon, the Python conference, just finished up in Atlanta. And they actually—and I don't know if they posted all of them, but they have a lot of videos, recordings of their sessions posted online. And we'll post a link, but it's pycon.blip.tv. And I've been watching a few of them, and they're actually pretty good quality and really interesting. So, you know, if you've always wanted to go to a conference or never thought about going into a conference and you look at the topic list and see some interesting things there, go check it out and watch some videos. Most of them are, you know, 30 minutes to an hour in length and talk about everything from everyday parts of Python and panels on what's the best IDE to use for Python all the way to, like, really, you know, specific optimization, you know, kind of libraries and techniques.
Yeah, this gets to kind of a little digression, but I think an interesting point, which is, you know, many of you out there work for, you know, tech companies or maybe IT companies, but work, you know, sort of in the software engineering industry. And, you know, you should definitely, you know, ask the, you know, your management if they can send you to PyCon or one of these conferences. You know, that's sort of a win-win. I mean, most of the time, most companies have a budget for training and very often people don't take advantage of the budget and that money gets wasted. You know, by going to one of these trainings, you can learn a lot about Python or something else. And you can also, you also become more valuable. I mean, your employer knows that, you know, you've went and gained the skill set or you've went and, you know, gained some connections with the top people in a certain field or in a certain topic. And, you know, that can really help you down, help you along further down the road. It's an investment.
Yeah. I mean, worst case, they tell you no. At least, you know, even by asking, you can, you know, remind them that you're inquisitive. You know, I think that's useful. Yeah, definitely. And I think we could all stand to be told no a little more often. Oh, yeah, that's right. What is it you're trying to? I think your metric was to get told no once a day, right? Yeah.
So this was an interesting thing on Hacker News a while ago. I haven't seen anything about it recently. And I don't remember exactly how they phrased it. But it boiled down to this guy came out and said, you know, we assume too much in our lives about restrictions and barriers placed on us. And so if you just make it a goal every day to get told no on something, anything, you know, not a silly thing, but an actual something get told for real no, that you will learn quickly that people don't—we're trained from very young age not to say no to people. So for instance, he, I think one of his examples was he was in some big city and took a cab ride and said, 'Oh, I forgot my wallet,' or getting in the cab and said, 'Oh, I forgot my wallet. Do you mind taking me, you know, for free?' And the guy's like, 'Oh, okay.' You know, just kind of like, you know, didn't want to tell him no, or he would wander around areas that looked restricted. And people would come up to him and say, 'What are you doing here?' He's like, 'Oh, I don't know. I'm just wandering around.' And he's like, 'Do I need to leave?' And they're like, kind of—but they had a really hard telling him like, 'Yes, you need to leave.' So this is amazing. Yeah. So this thing is, you know, go to your boss and ask, you say, 'Oh, no, I don't want to be told no,' they're going to think I asked too much. Well, go ask. Cause you don't know, like Jason pointed out, they probably have a budget for it. And if that budget's not getting used, it'll disappear. So they may in fact be glad to send you to the conference.
Oh man, I'm in the hot, I'm sweating. So the Virtual Machine, a Virtual Machine is basically a software implementation of, you know, the fundamental components of a computer. What that means is essentially a memory space. So a block from which you can, you know, allocate chunks of memory. A processor, which you can, you know, pass instructions to and a set of registers, which you can pass sort of as arguments, these instructions to do computation. So, let's talk a little bit about an actual machine, you know, about a computer. Basically the way the computer works is you have a bank of memory and we'll just say the memory is indexed by a number. So you can get memory location zero through, let's say, 10,000. And if you want the number that's in memory location 650, you can go and ask and query the memory for that, for that information. Once you get data from memory, it goes into registers, which are locations on the processor itself on the chip that hold information. Once you've sort of loaded the registers with information, you can run computations on them. So you can load two registers and then add them together and put the sum of those registers into a third register. That would be an ADD instruction. The instructions can be simple like that ADD. They can also be very complicated. So, on the VAX machine, there was actually a hardware instruction that would sort a list. So you gave it, you know, 16 registers as 16 operators or 16 parameters and you gave it the SORT instruction. And in hardware, there were physical, you know, copper traces that would do the sort algorithm for up to 16 elements. So that's the way a real machine works. In the case of a Virtual Machine, everything is in software. So in other words, the implementation of your instructions, if you let's say you have a SORT instruction, the sort is actually done in software. And the sort is actually done by, you know, in this case, like using some for loops or whatever, which execute on the actual machine. Your registers are also just locations in memory on the actual machine. So there's no chip in this case because it's virtual and your memory corresponds to memory in the actual machine. So that's not too different. So the interesting thing about a Virtual Machine is that for one thing, you can give it any instruction you want. You can make your own instructions because you're not actually doing anything in hardware. You're just composing new instructions from the instructions that already exist on your machine. You can also have more error checking. So if you let's say do a divide by zero, in hardware, that's going to produce some answer. I mean, the electricity is going to flow through those wires and something's going to happen. You're going to get a number. So it'll probably be,
Oh, right. That's right. So there's some specific number that corresponds to not a number and you'll get that number. On the Virtual Machine, if you do, you know, a floating point divide by zero or an integer divide by zero, you can crash the Virtual Machine. But because the Virtual Machine is all done in software, you're not actually crashing something on the hardware level. And so it's much easier to debug. One of the bad things about a Virtual Machine is that it's inherently slower. So if you call ADD, well, that's kind of a bad example because it just calls the machine ADD, but let's say there's some, like, let's say there's some instruction called Foo. Yeah. There's some instruction Foo, which actually corresponds to doing 10 adds or something like that. Then, that instruction is actually going to be quite slow because it's going to, you know, actually turn into many different instructions. So... Oh,
ahead. Yeah. So basically a Virtual Machine sort of gives you a lot of control. You can see exactly what's going on with the system. Since it's all in software, you can take a snapshot. So you can save the state of the Virtual Machine and then go back. So you can reload your crash over and over again and see exactly how it happened.
Yeah, definitely. So let's say, for one example, if your processor has SSE on it, you might have access to SSE hardware instructions that someone else doesn't have access to. But in the case of the virtual machine, all of your instructions are in software. So as long as you can compile the virtual machine for your particular computer, you know that you have access to every single instruction.
And interesting things, which are another kind of gotcha, but you know, the virtual machine on the computer with SSE could have SSE acceleration, but then you can run on another computer and assume that that's there because those instructions are still there. But that acceleration can't happen because there isn't a hardware. So that has to be done in software. Right. That's right.
Yeah. You can tell me if I'm right or wrong. But I mean, so an emulator, which we haven't talked about, is kind of taking a real world, and these are generalizations, but taking a real world device. And so we're talking about the Apple emulator online before the Apple IIe emulator. So taking a heart of a real device and creating a program that runs on other hardware typically. For instance, a Windows OS running on an Intel processor and simulating every ask, every hardware aspect of the Apple IIe that matters so that you could take a program that was written for an Apple IIe, and without changing anything in that program, run it through your emulator and it would know no difference and it would behave the same, and the user could interact with it if it's a user interacting kind of machine. Versus a virtual machine can implement essentially a hypothetical machine, a machine that doesn't exist in the real world. So Python doesn't implement a virtual machine that is a facsimile of another machine. It could have, you know, 1024 registers where no real machine is going to have that many registers. It could have, in theory, an infinite stack that no hardware could actually have. It can do stuff that isn't possible in real hardware or even has just never existed in real hardware. And it's not bound to trying to emulate some other kind of hardware, just providing a consistent interface to programs that are written for it.
don't think that. I think a lot of it is connotative. You know, emulators are typically where you're going and trying to emulate a machine, a specific piece of hardware like a Nintendo or something. Whereas a virtual machine is often referred to, emulating an operating system. Like running Linux inside of Windows using VMware or something like that. Yeah. Or in this case, running a Python machine inside of a Windows or a C-based machine. Yeah, so let's talk a little bit about the different Python virtual machines.
So, so there's CPython, which is the original Python virtual machine. And it's, as the name suggests, coded in C. It's compiled for whatever actual machine you're running it on. So if you're on Linux, you're using a Python virtual machine that was compiled for Linux. And there's a bunch of compile defines to try to use the same code base on many different machines. There's also Stackless Python. And Stackless Python is actually quite interesting. It gives some extensions to Python that make it more multi-core and multi-processor friendly. And do you know, have you ever used Stackless Python?
Yeah, one interesting thing about stackless Python is it's used by EVE Online, which is the which boasts the largest user base, largest single online server user base of any multi-user environment. So there's, I believe there's tens of thousands of people on a single bank of servers that can all potentially interact with each other simultaneously using EVE Online. So, you know, World of Warcraft has millions and millions of users, but it's split up into several what's called shards. Actually, sorry, it's split up into several servers and each server is split up into shards. So what that means is, let's say, I might be playing on server X and Patrick is playing World of Warcraft on server Y. We have no way of really interacting with each other. We're in completely different universes. And so they're completely disjoint. So you can think of each of those as a completely different game. Then on top of that, different areas of the world of a single server are sharded. So if I'm in one area and Patrick's in another area of the world, we're on different physical servers. In contrast with EVE Online, everyone can be in exactly the same location at one time. All of the users in the entire game. There are no there isn't multiple servers. And so they boast that they're able to do this because of stackless Python.
Yeah, that's right. That's right. And there's crazy news stories on the New York Times and other papers on just on just crazy things that have happened. And I think one time, one faction or one I think it's called a corporation went to war on another corporation. And over the span of a few weeks, something like 10 or $20,000 of real money, because apparently there's a conversion between real money and EVE Online money. It's like $20,000 was lost in this battle. It's just insane, the kind of the magnitude. And so, yeah, stackless Python works basically by enhancing Python using something called tasklets, which are actually, I think in Python they're not called tasklets. I think they're called micro threads. But basically just to explain it briefly, you know, variables and data, when you're doing programming, certain, you might have access to a certain, you know, set of data and you're doing computation. And you might say, okay, I want to sort both of these arrays. There's just these very large arrays and I need to sort both of them. What I'm going to do is create two threads. In the first thread I'm going to sort the first array and in the second thread I'll sort the second array. And if you have a multi-core CPU, it can do both of those things simultaneously. And that gives you, you know, a 2x speedup in time. So, stackless Python is very has a very high affinity to being able to create threads. Typically when you create another thread you have to sort of tell it what variables are yours, what variables are mine. And you have to create what's called a frame for that thread. With stackless Python you can create micro threads which don't have a frame and don't require don't have a context. And because of that it runs extremely fast. So, if you need to create a lot of threads, you can do so very efficiently. So, to go back to EVE Online, they might have, you know, a thread for every player, that's, you know, that's constantly updating the player's statistics and things like that. And that what that's that architecture is what allows them to scale to that to those levels.
there's PyPy, which is a Python virtual machine written in Python. And I always thought that this was sort of an educational thing, something that Python developers can use to learn more about the language. But I'm learning more now that Python, that PyPy actually runs Python code faster than CPython. And it gets really hairy as to why this is, but basically it boils down to again, coming down to these frames. So, in CPython, every time you enter a new function, it has to create a new frame. So, if you create a new variable inside of a function, it has to know that that variable's with that function. And when you return out of the function, that variable needs to be destroyed. So, the set of all variables inside of a function is called a frame. Local variables. Yeah, local variables, that's right. So, CPython, I guess the frames require a lot of overhead. And as you're calling functions and returning out of functions, you're wasting a lot of time. And PyPy somehow gets around this by using something called virtualizables. So, yeah, I still have more to learn there. But it is another Python virtual machine to consider if you're developing in Python, and performance is important.
Yeah, I mean, just really quickly, the way that kind of works is, you know, computers like absolute numbers. I mean, if you have a loop and you're trying to loop through these items in a list and you loop from one to the size of the list, but you don't really know what the size is, the size could be changing. Computers, you know, they can't optimize that because they don't really know every time they go through this loop, they don't know if this is going to be the last time or not. What a just-in-time compiler does is it's able to say, okay, I know that the size isn't going to change in the next millisecond. So I'm going to lock that down and I'm going to tell the system, you know, the actual machine that I'm looping from one to 30 instead of from one to the size of the list. And so, yeah, because of just-in-time compilation and being able to limit what things are changing and at what times, the actual machine is able to run much faster.
Yeah. I think that you can people who are just learning Python or learning programming for the first time can sort of go back later and learn more about virtual machines and things like that. By listening to this podcast a second time and people who are really experts can hopefully learn one or two things from us today.
Definitely. And I'd be happy if they listened to it once. We'll worry about them listening to it the second time later. Let's get enough people listening to it the first time. Yeah, that's right. So on that, I guess, as a conclusion, I don't know if you're listening to this, you probably found us on either our website or on iTunes, but we are now on iTunes. So that's a little bit of a yay. Yeah, that's awesome. And we're starting to get a few comments and ratings in. So if you like what you hear, or if you don't remember, Jason said the, how, if you think we're terrible, just give us a five-star rating and make us feel so bad that you think that we're terrible. And yet you still gave us a five-star rating. That's right. And if you liked us, give us a five-star rating and tell us how great we did.
