Latest / Talk Python To Me / #86: Python at StackOverflow
Transcript
- 0:00If you run into a problem with some API or Python code, what do you do to solve it?
- 0:04Well, personally, I throw a few keywords into Google, sometimes before even checking the full
- 0:08docs. It works great. But why does it work so well? Because invariably, an excellent conversation
- 0:14and answer from Stack Overflow comes back as the top result, and it's usually just what I needed.
- 0:19This week, you'll meet Martin Peters, one of the top Python contributors at Stack Overflow,
- 0:24with over 16,500 questions answered and a reputation of over half a million.
- 0:30This is Talk Python To Me, episode 86, recorded November 2nd, 2016.
- 0:49Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the
- 1:05ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter,
- 1:10where I'm @mkennedy. Keep up with the show and listen to past episodes at talkpython.fm,
- 1:15and follow the show on Twitter via at talkpython. This episode has been sponsored by Rollbar and
- 1:21GoCD. Thank them both for supporting the podcast by checking out what they're offering during their
- 1:27segments. Martin, welcome to Talk Python. Hi there. This is exciting. Yeah, it's an honor to have you
- 1:33here. You've done some really amazing work in the Python space on Stack Overflow, and we're going to
- 1:39spend a lot of time talking about what you've done there, what your experiences were, but also kind of a
- 1:44survey. Some really cool questions that you've pulled out for us to talk about that are representative
- 1:50of good work and basically the Python community at Stack Overflow. But of course, before we get to
- 1:57any of that, let's start with your story. How did you get into Python and programming? I started
- 2:00programming quite early on. My father was a computer engineer. He fixed computers the way you fix a bike.
- 2:07You find the part that breaks and solder a new one in back in the 70s. So in the 80s, I finally got my own
- 2:13computer. I was given a MSX. And I basically haven't looked back since. Python. I started Python in 1999, I think,
- 2:22when I was a web developer and I found a new platform called Zope. It lets you think of web pages as components
- 2:31and as objects, which was interesting. And that called me into Python at the same time. My first project, I gave a time estimate
- 2:38and beat my own time estimate, which blew away my manager because that never happened before. I always go over time.
- 2:45That's all engineers do. And I haven't... That was my start with Python. It really was a love at first sight, I think.
- 2:53Yeah, that's great. And what kind of project was that? That Zope project?
- 2:56It was for a befriended company that was doing software on the web. And when you sell software on the web, you need a web shop.
- 3:06So I built a web shop. I see. And because their software was already built in Python, it was very easy to incorporate their license generator into it too.
- 3:15Oh, of course. Yeah. So they were selling Python software. You needed to run their license thing. It's just like, yeah, we'll just, you know, import that right here.
- 3:22Just plug it in?
- 3:22Yeah, yeah. Beautiful. That's great that it was quick and easy. But I think building e-commerce sites today, quite a bit easier than it was back in 1999.
- 3:31What do you think? Have you built one recently?
- 3:33I tend to stay away from shop. I've mostly done, in my career, I've mostly done content management.
- 3:40So I think an intranet website where everybody has to be able to give their input as to what the company is doing or whatever. Share between teams, that kind of stuff.
- 3:49All right. So mostly content management stuff, which is really, really valuable and helpful. What do you do today? You work at Facebook, right?
- 3:57Today I work at Facebook and I do very different things. I don't so much work on the website anymore. As you know, Facebook does use PHP for that. Strange language.
- 4:07I work on the backend side, on the source control side where I hack on Mercurial, an open source project that lets you do development distributed source control.
- 4:16Oh, that's cool. Yeah. So Mercurial is kind of a cousin to Git, similar type of source control. What's Mercurial written in?
- 4:24Mercurial is written in Python.
- 4:25Interesting.
- 4:26Mercurial is a Python project. And because it's a Python project, we were able to make it scale. So Facebook, everything is turned to 11. Everything is crazy.
- 4:36Everything is just over the top high numbers and skills over the chart. And to be able to follow all the developers and all the changes they make every day, we couldn't actually make Git scale there. We couldn't make Git follow. And Mercurial did follow.
- 4:50So we can, because Mercurial is so written in Python and highly extensible and highly tweakable, we can make it work at the crazy levels that Facebook is at.
- 5:00That's really, I'm sure that's so exciting to work at Facebook.
- 5:02Absolutely. It's a great place to be.
- 5:04Do you work remote or is there a place there in Cambridge?
- 5:07I work in London. So I commute four days a week up to London to work and one day a week I stay at home.
- 5:14How much source code does Facebook have? Is it like, so when you talk about scaling it, is it the number of people using the system? Is it the amount of data? What's the scale look like?
- 5:24It's everything. So we put everything into one monorepo. Repo means that we try and put everything into one place, one repository, so that you can facilitate all the sharing and moving. And that really helps speed things up.
- 5:38But at the same time, you can easily come into the file counts of six figures. So trying to get a full check out of that is not always the best thing you want to do.
- 5:49So we have issues with the number of files, the number of directories, the number of commits each day, the number of developers that work on it. All those things play.
- 5:58Yeah, I can imagine that. Wow. Yeah. And Google also does this monorepo thing.
- 6:03This is a really interesting idea to me when you have that many files. Have you open sourced any of these tweaks or anything written about them?
- 6:12Lots of this stuff is open sourced. So Facebook has a repository with their own extensions in there. They are not perhaps immediately something you can use, but there is a lot of inspiration there.
- 6:23We also contribute straight back to the Mercurial project itself. Until recently, the founder of Mercurial, Matt McEll, worked at Facebook. He recently decided that after 11 years of Mercurial work, he wanted to do something different. So he moved on to other things. And the Mercurial project is now trying to make its way without him.
- 6:44Wow. Yeah. So you had the guy there to help you build this up. That's really interesting. Let's talk about Stack Overflow. Maybe tell the world what Stack Overflow is. The one person who doesn't know it.
- 6:54Stack Overflow is a site for programmers. And the goal here is to help programmers find answers to their common problems. It was born from frustration with forums. You know, the general forum where someone says that they had a problem with this code and can someone help them and 20 people pipe in, but that they have the problem too and they don't know the solution. And then maybe on page 15, someone has got the solution.
- 7:17And then it disappears into a huge pile of posts about different things and you never find it back again. Stack Overflow is very much aimed at trying to surface the question and the answers. So you have just a question.
- 7:33And people, they use gamification to get the best answers on the top. So the general idea is that people vote. This was a question that is worth, that is well asked, that is complete. And these are the answers. And this answer is the best because that gets the most votes on it. That's the idea is that you get an encyclopedia of knowledge, of programming knowledge.
- 7:53And they, you know, Jeff Atwood and Joel Spolsky, the two founders, they have nailed that in some special way, right?
- 8:00They found a secret sauce.
- 8:01They found, they definitely found a secret sauce and it's working really, really well. Like pretty much any programming question you have, if it has technical detail to it, there's probably a Stack Overflow result in the top five Google results.
- 8:16Exactly. For the most common programming problems, you will find a solution there.
- 8:19Yeah. And it's not just, well, you should put this curly brace here or whatever. It's also, it's much deeper than that, right? I think, I think there's a lot of really interesting questions as we'll see.
- 8:31Absolutely. Absolutely. There's such a wide range of things that answer there, provided you stay on topic, which is sometimes a little harder.
- 8:39Yeah, it can be. But yeah, it's, and they're very, very much careful about making sure things stay on target and focused and don't rant and basically become the forum that they're trying to escape from.
- 8:52So let's start.
- 8:53Exactly.
- 8:54Yeah. So let's start with what makes a good question on Stack Overflow. So I guess before you answer that, tell us, I was looking at your, your user profile and there's some pretty astounding statistics there.
- 9:07So for people who know you have about 500,000, a little over 500,000 for reputation, but you have 16,000 plus answers. And it says you've reached 22.9 million people. That's really amazing.
- 9:21The numbers, they keep on growing because I like answering. I like finding solutions to problems. It's, it is kind of addictive. It is addictive with the fact that the feedback that you get and the, the, you learn so much yourself from this.
- 9:35I love finding the key to the problem. So if someone has a particular view on the problem, they have a certain idea about how things should work or not work. And they clearly don't understand something. And I love finding the key that helps them suddenly see, oh, that's why this is how it works. So I'd prefer not just to give you the solution. I also prefer to tell you why.
- 9:57Yeah. I noticed that from your answers. Yeah.
- 9:59In doing that, you learn yourself whether or not, you know why. And that helps me grow as a programmer as well.
- 10:05Yeah. I think that's a really good point because it's one thing to say, this code doesn't run as I expected. You could say, well, change it to this and it would. It's another to say, well, the reason your code doesn't work is if you really look inside, like say the CPython interpreter, it's doing this. And when it does that, here's what it means. And so here's how you fix it. Like that, that both enriches the person's understanding, but yours as well, like you say.
- 10:31Exactly. I get to learn and apply it elsewhere.
- 10:35I can use this in my own daily life. My own work is informed by what I learned from answering on Stack Overflow.
- 10:42Yeah, absolutely. I'm sure it is. I'm sure it is. Let's start with what makes a good question on Stack Overflow.
- 10:48So Stack Overflow is very strict about what it accepts for questions. Over the years, we've learned certain things don't work. So certain things are not on the topic. Stay away from those certain things, like asking what is the best web framework?
- 11:04What is the best is very subjective and it's very hard to answer without a lot more detail about what you're doing. Most people don't give that detail. And what then also happens is that the spammers come along, the people that have something to sell and they say, ours is the best.
- 11:17So those kinds of things are off topic. The same thing for opinion-based things. And we don't want to go on. We don't want to end up writing books either.
- 11:28So if you want to know about the best practices for using object-oriented programming and when to use one technique or another technique, that would rapidly be closed as too broad.
- 11:41Now, once you narrow it down to very specific programming problems, then you already start being on topic.
- 11:47And then what you definitely need to do is, first of all, realize that these questions are not just for you. We want them to be there for everybody. So someone else coming Googling later on, need to be able to recognize that they have the same problem.
- 11:59And the other thing is that if you want answers, you need to help the people that answer you. So you want to show the context of research that you've done.
- 12:09And you want to narrow down your program to the essentials. So if you come in and say, I have this XML document that I want to parse and get this information out and write it to a file, but I want to transform this information this way and that way.
- 12:22How do I do this? You're going to end up disappointed.
- 12:25Yeah. And the XML file is like a thousand lines long with all sorts of complicated stuff. And they haven't focused in on just the essence of the problem. They're basically like, solve this problem for me, right?
- 12:35Exactly. So solve this problem for me. What you can do at such a point is you need to break this down into separate issues. Perhaps you already succeeded in loading the XML file and parsing it. You've already maybe made choices there. Tell us about those.
- 12:49So now you've narrowed it down to perhaps only finding specific information in that file. Leave out the part where you're going to transform it and write it to something else. Those are separate problems. Those are separate steps.
- 12:59And once you narrowed it down to one of these steps and show us what you put in there, what you expected to come out and what have it instead with all the error message and all the full traceback and everything that you can, that you see, then we can see it too.
- 13:14And often you will come to a very quick answer.
- 13:17Or it might be, again, I cannot emphasize this enough. You have to have done your research because it could be that the question was already asked before and answered before and your question will be closer to duplicates.
- 13:31Yeah. So Stack Overflow is actually pretty good at helping with you find answers as you're kind of ignoring the fact that they might exist. I guess is the way to think of it.
- 13:41We don't hate duplicates either. We don't dislike duplicates. The internet is, of course, very impersonal. You can't see the other person's smile or feel any warmth. So people often see this as a personal putting their question down thing.
- 13:56And duplicates, sometimes people actually go, I'm sorry, I asked the duplicates. And to that I say, it's all right. Duplicates happen. You can't always know exactly what you're searching for. We can help with that.
- 14:09And duplicates actually are valuable to Stack Overflow as well because what happens is that you now added more keywords for people to search on.
- 14:17So when you created the duplicate, you asked the question. It was well asked, but it was a duplicate. Google still has indexed your question.
- 14:25And when someone clicks on it on Google, we actually redirect new visitors straight to the canonical question that you were a duplicate of.
- 14:32So at that moment, you have helped someone else find the same solution.
- 14:36Oh, that's interesting. I didn't really think of it that way.
- 14:39So the research part is really important. I suspect it really affects the way that you feel about answering the question.
- 14:46If like somebody has just put zero effort or what appears to be zero effort into finding their solution and they're just like, I don't know, let's put it on Stack Overflow, see if somebody will do this for me.
- 14:56Probably your willingness to give a good solid answer goes down, right?
- 15:00There's a certain type, certain classes of questions that we've seen so many times now, so often asked, and there's so many times that there's a duplicate, these common errors, that some people may lose patience a little bit.
- 15:12And then you get, haven't you done your research?
- 15:16You could have found this in the first five results on Google.
- 15:19Right. I took your title.
- 15:20I put it into Google.
- 15:21And here's the Stack Overflow answer that actually has 10 answers and 100 upvotes and whatnot.
- 15:26Exactly.
- 15:27Interesting.
- 15:28So it is the same kind of thing.
- 15:30I think there was a funny video online, what if Google was an actual person, where you see someone in an office and people come in and ask, how is baby formed to this person's face?
- 15:41The person behind the desk being a comedian does a great job of looking frustrated or can't ask this question 100 times already.
- 15:49Yeah, exactly.
- 15:51Nice.
- 15:52Okay.
- 15:53So I think everyone's got a good sense of more or less what makes a good question.
- 15:58Let's talk about some of the ones that you found that are noteworthy or whatever.
- 16:03First of all, how many Python questions are on Stack Overflow?
- 16:07Do you know?
- 16:08Oh, if I look it up very quickly, it's about 650,000.
- 16:12650,000.
- 16:14650,000 questions today that have been tagged with Python.
- 16:19There can be more.
- 16:20There are several version-specific sub-tags, so Python 2.7 or Python 3.5.
- 16:26And not everybody uses the main tag when they ask about a specific version.
- 16:32Right.
- 16:32It might be just tagged Django, but it would also count as Python.
- 16:36There might just be Django-specific library questions, so Django, Flask, or Pandas, or NumPy, those kinds of things.
- 16:45They're all Python questions, too, but they might like the tag.
- 16:48So there might be more.
- 16:49All right.
- 16:50There probably are.
- 16:50Yeah, it's probably a subset.
- 16:52Okay, cool.
- 16:53So you've, out of the 650,000-plus questions, chose a few that are really good.
- 17:00And you said that some of the questions that are really interesting are these what questions.
- 17:06W-A-T.
- 17:07I think W-A-T.
- 17:09This comes from a talk by a man named Gary Bernard, who did a very short and very funny talk about wah moments.
- 17:16He goes, wah, completely memes.
- 17:19Those moments where you go, it really shouldn't be doing that.
- 17:23That is such a crazy response to the code.
- 17:25Yeah.
- 17:25Usually it is.
- 17:26It's bugs or very obscure corner cases of the language.
- 17:30They are, for me personally, the most interesting ones because they definitely will cover areas that I know nothing about.
- 17:40Or very little about it.
- 17:42If they make me go wah, then it's definitely something interesting.
- 17:45Yeah, absolutely.
- 17:46And depending on the language you're working with, there's more or there's fewer.
- 17:51Like the example that Gary chose was JavaScript, which is full of wonderful watts.
- 17:56Exactly.
- 17:57Python, on the whole, is a very, very low watt count.
- 18:00But there are a few, and usually they are due to bugs.
- 18:03So Python is a very consistent language.
- 18:08The developers do an awesome job of making sure that Python is a consistent and predictable language, unlike JavaScript or even few Ruby examples as well.
- 18:18But there are a few of those.
- 18:19Recently, very recently, I think last week, there was one question that was asked where someone built a set contains unique elements.
- 18:30But if they built a set from a list, they got a different result than when they built a set from a set literal.
- 18:36So they had multiple elements in it.
- 18:38And they listed the elements in the same order.
- 18:42But if you used a set literal, they got a different result from building a list first and then passing that to the set callable.
- 18:49That should not happen.
- 18:51That should not happen.
- 18:53It shouldn't.
- 18:54So if you say set, open parenthesis, and you pass an iterable thing, like a list or something, you get one result.
- 19:01If you say curly brace, thing, comma, thing, comma, thing, comma, thing, close curly brace, and you put the same things in that you pass to your set initializer, you actually get different sets.
- 19:15With the properly constructed inputs.
- 19:18So at that moment, I definitely go, that shouldn't happen.
- 19:21That is weird.
- 19:22I'm intrigued.
- 19:23I'm hooked.
- 19:24And the next hour is going to be spent figuring out what's going on.
- 19:27Where did it come from?
- 19:28Why?
- 19:29Why?
- 19:30Why?
- 19:30In this case, it was a bug.
- 19:32It was a bug.
- 19:33Okay.
- 19:34And I'm looking at your answer here.
- 19:37And of course, everybody who's listening, all these questions and answers will be added as links in the show notes.
- 19:42So I'm looking at your answer here, and you're like, all right, so here I'm trying a few things, and we're trying to understand it.
- 19:48And all right, let's just open up the disk module and do a straight disassembly on this thing.
- 19:54Yeah, because at that point, you're going to have to dig in, what is the Python interpreter doing?
- 20:00So you need the bytecode, and the bytecode is built from the source code, drives the interpreter.
- 20:05And then you can start looking at the interpreter source code and see what is going on.
- 20:10And for me, it was actually hard to figure out what was going on because I looked at the most recent version of Python from source control, so from the Mercurial repository.
- 20:20And the bug had been fixed very recently as well.
- 20:24So you used, if you do this with a release version of Python, you will not see the bug.
- 20:30You will see the bug.
- 20:31If you actually look at the source code as it is today, you won't see the bug.
- 20:36I see.
- 20:36And did you go to the source code to try to understand it?
- 20:38Like, if I can do it?
- 20:40I went to the source code.
- 20:41It looks to me, my hypothesis is that the set literal is parsing these things in the wrong direction, in the wrong order.
- 20:47That it's doing this in the wrong order.
- 20:50But in the source code, I could see that it was parsing it in the right order.
- 20:54So at that moment, I'm trying to figure out what is going on.
- 20:57I could reproduce the issue.
- 20:58It clearly wasn't matching what the code was.
- 21:00So I actually went to search for issues in the bug tracker, found it, and then quickly realized that I was looking at a fixed version of the code because it already had been fixed.
- 21:09So what was happening is that for all currently released Python versions, if you use a set literal, the stack is each element in that literal is pushed onto the stack.
- 21:21And then the stack is taken in reverse to build the set.
- 21:24So you always get the items from last to first added to the set.
- 21:28Now, a set tests for equality.
- 21:31So if two objects are test equal, even though they look different to you as a developer and there are different types, they still say that they are equal, then the first one in the set will win and will stay in the set.
- 21:43And the other ones are rejected.
- 21:44They were not added.
- 21:45So in this specific case, someone was using zero and then the complex number zero, so zero j, and the instance of the decimal class from the decimal module, decimal zero.
- 21:59And because the decimal module in Python 2 doesn't support equality tests with complex numbers, only with integers, it would test equal against zero but not against complex zero.
- 22:10And so depending on the order in which they go in there, it would, yeah, change it.
- 22:15Accept one or the other as being equal to what's already in there and rejected, and therefore you get different results.
- 22:20Yeah.
- 22:20Wow.
- 22:21These are definitely corner cases.
- 22:23These are obscure stuff, and most people won't come across these.
- 22:26But that's the kind of question that I personally enjoy.
- 22:29Well, one, really interesting to think about why that would even be possible and what's happening.
- 22:33But also, you actually found a bug or the person found a bug, and you verified the bug, I guess.
- 22:39In this case, I confirmed the bug.
- 22:40Yes.
- 22:41Exactly, exactly.
- 22:42How often has that happened?
- 22:44It doesn't happen that often.
- 22:45And also for packages, there are bugs and corner cases.
- 22:49Python is a pretty solid piece of software.
- 22:51Usually, when I do find the bugs, they are usually very minor.
- 22:56There might be documentation bugs, or one of the modules in the standard library might have some unexpected behavior that could be improved.
- 23:04The fundamental issue, like the order of set literals being processed, that's pretty rare.
- 23:12Yeah, I suspect most of the bugs that are found are up above the standard library.
- 23:17They're in some external package or something like that, right?
- 23:20Exactly.
- 23:21So usually, if far fewer people look at it, it might be a different project that has a different standard for testing.
- 23:27And so, more likely to find them there than I would find them in Core Python.
- 23:32Yeah, absolutely.
- 23:33Absolutely.
- 23:33This portion of Talk Python To Me has been brought to you by Rollbar.
- 23:51One of the frustrating things about being a developer is dealing with errors.
- 23:55Ah, relying on users to report errors, digging through log files trying to debug issues, or a million alerts just flooding your inbox and ruining your day.
- 24:03With Rollbar's full-stack error monitoring, you'll get the context, insights, and control that you need to find and fix bugs faster.
- 24:10It's easy to install.
- 24:12You can start tracking production errors and deployments in eight minutes or even less.
- 24:16Rollbar works with all the major languages and frameworks, including the Python ones, such as Django, Flask, Pyramid, as well as Ruby, JavaScript, Node, iOS, and Android.
- 24:25You could integrate Rollbar into your existing workflow, send error alerts to Slack or HipChat,
- 24:30or even automatically create issues in Jira, Pivotal Tracker, and a whole bunch more.
- 24:35Rollbar has put together a special offer for Talk Python To Me listeners.
- 24:38Visit rollbar.com slash Talk Python To Me, sign up, and get the bootstrap plan free for 90 days.
- 24:44That's 300,000 errors tracked all for free.
- 24:47But hey, just between you and me, I really hope you don't encounter that many errors.
- 24:51Loved by developers at awesome companies like Heroku, Twilio, Kayak, Instacart, Zendesk, Twitch, and more.
- 24:56Give Rollbar a try today.
- 24:58Go to rollbar.com slash Talk Python To Me.
- 25:08The next one that you said was really interesting, and I agree, is it's so simple.
- 25:14It's like eight or nine words, the question, but it has 3,200 upvotes.
- 25:22And the question is, what is a metaclass in Python, and what do you use them for?
- 25:28So this is, I think, is an example of a really awesome answer.
- 25:33So I'm not talking about the one that's marked as accepted, but the one below it that has the most upvotes.
- 25:39This is one user that has learned that for certain subjects, it is worth it to write an essay, to write a full answer.
- 25:45And his name is Isetus, and his answer for metaclasses is absolutely epic.
- 25:51This is why we have Stack Overflow.
- 25:54This is what needs to flow to the top.
- 25:57Metaclasses are an unfamiliar concept to most people.
- 26:01Metaclasses are the type that creates classes.
- 26:05So classes are a factory, a thing that you use to make instances.
- 26:10But what makes classes?
- 26:11Now, that's a metaclass.
- 26:13Metaclass can produce a class.
- 26:14It can be a mind-boggling and hard-to-grasp concept.
- 26:19But Isetus does an absolute marvelous job of explaining this anyway.
- 26:26So he starts with explaining what classes are, what objects are, and this goes deeper and deeper and deeper and includes not only what metaclasses are and how they work, but also includes excellent advice as to when you want to use them, which usually is not.
- 26:42But when you do need them, when you do need them, metaclasses are a very powerful concept.
- 26:45And he does, I think, one of the best jobs of explaining that.
- 26:49Yeah, it's like a little book chapter almost that he wrote.
- 26:52I think it's like 15 pages, you know, based on my screen size or whatever.
- 26:56That's pretty impressive.
- 26:58And I really do think it's a great answer.
- 27:01Yeah, metaclasses are definitely interesting and useful.
- 27:04But I think we mostly consume them, right?
- 27:06More than create them as average, everyday programmers.
- 27:10Average, everyday programmers, you mostly consume them.
- 27:12Most people don't know that they even exist.
- 27:14This is something that frameworks use.
- 27:17The Django framework or the WT forms framework use metaclasses heavily because they get to have access to all the attributes you just set on a class and transform them and manipulate them and make them do something magic.
- 27:30Yeah, I was thinking of SQLAlchemy's declarative base.
- 27:33Yeah, SQLAlchemy is very similar to that.
- 27:36Again, it's a model where each of the fields defines something about the model that is a little bit more than just the object you just put in there.
- 27:45So define a class that also models the columns in a table.
- 27:49You usually want those attributes to behave differently in different contexts.
- 27:53Like when you are creating a new instance or you are just putting stuff in from the database, that moment, that class has to behave differently.
- 28:01And that complexity, it can be neatly encapsulated and hidden by using a metaclass.
- 28:07Yeah, it's really, really wonderful.
- 28:09Awesome.
- 28:10Okay.
- 28:11How about accepting, next question.
- 28:14Accepting the user input until you get a valid response.
- 28:17Yeah.
- 28:17I picked that one because it's a very good example of, again, what the Python community around Stack Overflow does.
- 28:24So Stack Overflow itself is a site, but next to that we have a chat site as well.
- 28:30So there's a chat.stackoverflow.com where there's various different rooms where people, members of the community come together to hang out or to chat about all sorts of weird things and sometimes even about Python.
- 28:40And there's a Python chat room.
- 28:41And because people talk about and are connected to Stack Overflow, that room sees lots of patterns happening.
- 28:50So questions that keep coming up, certain problems that keep coming up.
- 28:53And there's sometimes a class of them.
- 28:55Like using raw input or input in your Python program to get a response from a user.
- 29:02Most homework starts with take an integer from the user and put it into something.
- 29:09And that is something many new programmers fall over and keep stumbling into.
- 29:15So this particular question was written by a member of the Python chat room together with an answer based on their experience helping people again and again and again with the same issues, the same related issues.
- 29:27What do you do to validate that input?
- 29:29What do you do when the user has got it wrong and you want to repeat it?
- 29:33All the pitfalls all collected into one place and as a self-answer.
- 29:37So this was both the question and the answer have been written by one person at the start and then refined later on by the members of the community.
- 29:45Interesting.
- 29:46So this one, they made the answer, their own answer, a community wiki.
- 29:51Exactly.
- 29:53I've seen that you can make an answer a community wiki or you can sort of keep it to yourself and you get reputation if you keep it to yourself and you don't on a community wiki.
- 30:04You want to talk about that?
- 30:05Exactly.
- 30:05Yeah.
- 30:06The community wiki is definitely aimed to be able to lower the bar of improving a post.
- 30:13So in this case, the community definitely felt this is something we as a community want to do because it's pretty much needed and it's too scattered around the site.
- 30:20And we don't want it to be owned by one person specific.
- 30:24So you should feel more, you should feel freer to actually edit this and improve it.
- 30:29That's why it's made a community wiki.
- 30:30And the moment you actually then invite more people to edit it, then you don't no longer know who can earn more than other people if there's upvotes on this.
- 30:40So that's completely taken away.
- 30:41Yeah, that makes sense.
- 30:42Also see that it's protected.
- 30:44The question is protected.
- 30:46What does that mean?
- 30:46Yes.
- 30:47That is just something, a trick we use as moderators.
- 30:50But high rep users can do the same thing.
- 30:52When a post like this becomes so very popular, what can happen is that lots and lots of new people, so people with low reputation come in and go,
- 31:02my solution is unique.
- 31:03My solution is unique.
- 31:04And they don't have the experience to actually see that their solution is perhaps not that unique.
- 31:09Or they say, I don't quite understand.
- 31:11They don't quite understand yet how Stack Overflow works and they don't understand the answer.
- 31:16So they might post in an answer below it another question where they request that someone explains how the whole thing works.
- 31:23Well, answers are not questions.
- 31:25So that is the wrong place to post this.
- 31:28So a question like this can attract lots of those kinds of answers.
- 31:33So if I have enough reputation that I can see not only the answers that are posted, which currently says 10 at the top, but most people can only see the first three, four, six posts.
- 31:47So there's four more on that same page that have been posted before that are either someone not having understood that their solution is not unique and that they have basically repeated the same thing or explained it wrong.
- 31:57Or are questions.
- 31:59This one doesn't work.
- 32:00How does it?
- 32:01Yeah, interesting.
- 32:02So what kind of powers do you get as you go up in reputation there?
- 32:07Full disclosure, my reputation is like 2,000.
- 32:09I've answered some questions.
- 32:11I've asked some questions, but nowhere near that I would have any of the exposure to the stuff that you get.
- 32:16There's quite a wide range of things that we can do.
- 32:19Mostly what we like to see is that people start, when you start getting invested in Stack Overflow and you start gaining reputation, you get experience with how things work and we trust you more and more.
- 32:30And at that moment we can rope you in to help.
- 32:32So a lot of these, once you get past the initial kind of points where you can start voting and start adding comments, which before to keep spammers out, don't give you to you immediately.
- 32:44You start getting into what we call community moderation privileges.
- 32:48So you can start helping the electric community moderators keep the site clean.
- 32:54Most of the site is kept clean by the community.
- 32:57So you can start doing like, you're allowed to edit posts at 2,000 points.
- 33:02We allow you to edit posts without review.
- 33:05So you can go to any other posts and start fixing things.
- 33:09If you see a typo, fine.
- 33:10You have 2,000 points or more.
- 33:11We trust you that you can make that change.
- 33:14At some point you can start helping gardening the tags.
- 33:18The tags could be marked as synonyms of one another, say.
- 33:21The Python tag has got several synonyms.
- 33:24Like Pythonic was not seen as something that needed a separate tag.
- 33:27It's made a synonym of the Python tag.
- 33:29At 2,500 points you can start helping with that.
- 33:32And then you can start helping close posts or put them on hold.
- 33:35And also reopen them again if you feel that it shouldn't be, stay closed.
- 33:38Maybe it was improved and fixed.
- 33:40So now you can reopen it again.
- 33:41Tag wikis, the things that we keep a bit of documentation about each tag.
- 33:45Is it called a tag wiki and that's that?
- 33:47At some point you're allowed to edit those without review as well.
- 33:50Et cetera, et cetera, all the way to 20,000 points.
- 33:53And that's the highest amount of, oh no, sorry, 25,000 points.
- 33:58It's the highest level that you can get to.
- 34:00And we give you access to internal data, site statistics.
- 34:04Because then we think you're so invested into this, you really want to know how well we're doing.
- 34:07That's really cool.
- 34:09Yeah, and you're a little bit past 25,000 these days.
- 34:12So you've had those privileges for a while.
- 34:14But that's really great.
- 34:15I think I might be a little past this, yeah.
- 34:18Exactly, like 400, I don't know, hundreds of thousands past that.
- 34:22That's awesome.
- 34:23So another question that you put up here has to do with creating type level variables
- 34:28and trying to initialize one of them with a list comprehension from another or something like this, right?
- 34:36Yeah.
- 34:37This is one of those wah moments, again, where I learned such a lot about the Python programming language,
- 34:43about how scopes interact, but also a little bit about how the Python developers definitely see the language as something living
- 34:51and will make changes if that makes sense.
- 34:54So in this case, this is a weird interaction between scopes for classes and functions and list comprehensions.
- 35:02Now, normally when you have a function, that's a scope, and we have the global scope.
- 35:08So we have a local and a global scope.
- 35:09The things are simple.
- 35:11You just have functions.
- 35:12But as soon as you start nesting functions or you start using functions in classes, you introduce more scopes,
- 35:18and you have to start figuring out how you access names that exist outside of the function.
- 35:23So normally in a function, if you use a global, it is available because it can be found in the global namespace,
- 35:30and that's part of the normal search.
- 35:31But as soon as you start using classes, a class object is also a scope.
- 35:36So the class definition of building your class object has a separate scope of names,
- 35:42and different rules apply there.
- 35:44Let's say you have a class that defines a class attribute, and then you define a method in that.
- 35:50The class attribute is not a parent scope, and it's not available to the function in the class
- 35:55because you normally would bind that function as a method, and then you work with an instance over the class,
- 36:00and there might be multiple of these.
- 36:01And therefore, you need to separate out the lifetime of the instance in the class,
- 36:06and defining it.
- 36:08So the names in a class scope are not normally available to the functions that you define inside of the class.
- 36:15That comes later.
- 36:16You can access those via the class object that has been created.
- 36:19How does it play with list comprehensions, you ask?
- 36:22Well, the Python developer started with seeing list comprehensions as very simple constructs,
- 36:29no different than a for loop.
- 36:31If you put the for loop in a function, all the names you use in that for loop,
- 36:35including the target for the iteration.
- 36:38So the for name in an iterable, each time you iterate through the for loop, the name that you've used for that gets assigned the next value.
- 36:48And it's in the sequence.
- 36:51That name lives in the same scope everything else lives in for that function.
- 36:56So this is the local name.
- 36:57So after your for loop is done, you see that local name, and you can still access it.
- 37:00So for i in range 10, you'll make your loop run from 0 to 9.
- 37:04At the end of it, i equals 9 is still available to the rest of the code.
- 37:08List comprehensions were seen exactly the same.
- 37:11Just a local thing in your scope.
- 37:14So the for loop target of that is available.
- 37:16The Python developers then next created generator expressions.
- 37:20A generator expression is evaluated lazily.
- 37:23So you can sort of see it as a function.
- 37:26You first create it.
- 37:27It is an object that will behave in a certain way, but only when you make it to later on.
- 37:33So you deferred execution.
- 37:36Right.
- 37:36So if you want to try to, say, access the iteration variable in a generator, a generator expression,
- 37:42it may have been created, but it may not have been created, depending on whether you've actually executed the generator, right?
- 37:48Exactly.
- 37:49So you actually, at that point, you have executed your generator.
- 37:54So these variables don't even exist yet.
- 37:56So generators were given a hidden function scope.
- 37:59They behave just like functions.
- 38:00Everything inside it is local to a new function, and that's hidden.
- 38:04So that you can execute it just like a function.
- 38:07And then the local variables are part of the generator object, like a function would be, and are cleaned up separately once a generator object is done.
- 38:16And the Python developers, as they built this, then realized that this also really applies to list comprehension.
- 38:23This comprehension and generator expressions are just basically the same thing, except one of them is immediately executed.
- 38:28The other one is deferred.
- 38:29So in Python 3, list comprehensions were given in scope 2.
- 38:33Now, why is this important?
- 38:34I always talked about how classes have a scope, and then the methods in the class can't access the class scope.
- 38:41They will have to go for the class.
- 38:42This applies to generator expressions and list comprehensions too.
- 38:46Well, at least.
- 38:47So they do it in Python 3.
- 38:49In Python 2, where list comprehensions are still sort of simple things without their own scope, that behaves differently.
- 38:55So there was a discrepancy there between Python 2 and Python 3 where things changed.
- 39:00And most of the time, people write simple classes and write class attributes and write their methods.
- 39:07And they don't think about trying to access things that they just defined for class attributes.
- 39:12But when you're writing, say, a list comprehension to make an attribute of your class, it's certainly very surprising that you can't access anything else you already defined for that class.
- 39:22Because it's a scope that is not available to you.
- 39:24I think this is a really interesting example of understanding why this was changed.
- 39:30Do you know if the Python core developers are paying attention to Stack Overflow and possibly making changes to the next version of Python based on things that appear there?
- 39:41Or does it have to bubble up farther through some other channel?
- 39:43Stack Overflow is one of the inputs, one of the sources where you see there's a long tradition of the Python developers looking at how Python is used.
- 39:52There's a longstanding mailing list called Python Tutors where you can ask questions and people will answer those.
- 39:59It's like a mailing list forum that answers Python beginner questions.
- 40:05And I have seen plenty of evidence that that source over the years has already informed the core developers on how they do things, that they see these common problems.
- 40:15A lot of the core developers are themselves consultants that teach Python, teachers or consultants that help companies use Python better.
- 40:22And they use those inputs too.
- 40:25And Stack Overflow is just another input in that way.
- 40:27So I definitely think that they're using it.
- 40:30I know that several of the Python core developers are regularly answering on Stack Overflow as well.
- 40:35So they definitely get that input too.
- 40:38Yeah, that's great.
- 40:38I'm sure they are.
- 40:39But this type of question seems like it can really clearly pull out some of those decisions.
- 40:47And maybe if it came earlier, before that was changed, maybe highlight some of the problems.
- 40:52Exactly.
- 40:53Exactly.
- 40:53This portion of Talk Python To Me is brought to you by GoCD from ThoughtWorks.
- 41:12GoCD is the on-premise, open-source, continuous delivery server.
- 41:16With GoCD's comprehensive pipeline model, you can model complex workflows for multiple teams with ease.
- 41:23And GoCD's value stream map lets you track changes from commit to deployment at a glance.
- 41:29GoCD's real power is in the visibility it provides over your end-to-end workflow.
- 41:34You get complete control of and visibility into your deployments across multiple teams.
- 41:39Say goodbye to release day panic and hello to consistent, predictable deliveries.
- 41:44Commercial support and enterprise add-ons, including disaster recovery, are available.
- 41:48To learn more about GoCD, visit talkpython.fm/gocd for a free download.
- 41:54That's talkpython.fm/gocd.
- 41:58Check them out.
- 41:59It helps support the show.
- 42:08Speaking of newer versions of Python, the next question is, why is Python 3's super function magic or super method?
- 42:16Yeah, but this definitely came also from feedback on how things work and don't work for Python.
- 42:21So the super function, I'm going to introduce it real quick, is the way that you can access methods on parent classes.
- 42:31So when you override in a subclass a method and you still want to use the functionality of the original, you can use super to access methods on classes in your method resolution order.
- 42:44So the linearization of all your base classes.
- 42:50The linearization means that we put all your classes in a specific order and that order is always fixed and predictable.
- 42:56So when you create a subclass and you want to put an under-under init method in it and you want to initialize a few more attributes that your more specialized subclass uses,
- 43:06but you still want to use the original init method that you use super to get there.
- 43:10Now, the way Python inheritance works, I already mentioned the method resolution order.
- 43:16You want to be able to find which class is next in line so you can call its init methods.
- 43:23When you're using multiple inheritance and diamond patterns, it's not always that clear, but Python solves that for you.
- 43:28And so you don't have to worry about it if you use the super method because it will take care of finding the next class for you.
- 43:35Right, there's a predictable, well-known order in which it will search for the thing you're trying to call on the super, yeah.
- 43:41Exactly.
- 43:42So we call it the method resolution order.
- 43:46That's the order in which the next one will come about.
- 43:48But for a super to be able to know where it is, because your class could be subclass and subclass and subclass further,
- 43:56for it to know where on the method resolution order for the current object,
- 44:03because that matters, it's not just the current class, it's for the current instance that may use a subclass,
- 44:07it has to know where on that line you are at this point, this method.
- 44:13So if you have a foo.unit method and you want to call the next one in line,
- 44:19you need to tell super, I am foo.
- 44:22So you can search past that point.
- 44:24You can find foo in the line of other classes in the whole method resolution order
- 44:28and find the next one in line.
- 44:30So just like your current type, the type of object you are, isn't enough because you could have called down into some intermediate level of inheritance,
- 44:38which is then calling super or something that can get really complicated, right?
- 44:42Exactly.
- 44:43Foo could have been subclassed by bar and bar could have called foo.unit via the super trick.
- 44:49And then self, the type of self is bar and therefore you can't use that.
- 44:53You can't say type of self is bar and therefore I'm going to start searching from there.
- 44:57Because you're no longer in the bar class, you're now in the foo class.
- 45:01So you explicitly in Python 2 have to tell it, start searching here.
- 45:06That's the first argument is the current class.
- 45:09Second argument is the current instance.
- 45:11So you can find the MRO from that.
- 45:14That means you constantly are repeating yourself.
- 45:17So you're writing a class foo.
- 45:19And then in all the methods that need to use super, you keep saying, this is class foo.
- 45:24This is class foo.
- 45:25This is class foo.
- 45:26So that violates the do not repeat yourself principle, the drive principle.
- 45:29Then there are other tricks in Python, like using a class decorator or simply storing your class in a different name.
- 45:37Classes are objects, so you can use a new variable, a new global variable, call it spam and assign foo to it.
- 45:44And then you can call spam and suddenly it is called spam.
- 45:47So you cannot also at that moment guarantee that the old name still exists.
- 45:51So what might happen if you have a class foo and you use super foo everywhere in there?
- 45:57It may be that at the moment that you call foo on the internet, the class is no longer available under the name foo.
- 46:05It might be called something different or something else might have been assigned to foo.
- 46:09So now you have a problem because when you created the class, it was called one thing and now it's called something else and the names no longer match.
- 46:16And then you have problems.
- 46:17Yeah, absolutely.
- 46:18So super, super, super, super tied to the class existing on underneath the same name.
- 46:26And you have to constantly repeat yourself.
- 46:28So the Python developers tried full, long and hard as to how they were going to solve this.
- 46:33How can they avoid having to repeat yourself?
- 46:36And how can they avoid record, somehow record the current class on which you just define this method so that it is no longer depending on the run, on runtime circumstances where the class still is available in the same name.
- 46:51And that's where Python 3 super comes from, where you no longer have to pass in anything anymore.
- 46:57You call super without arguments.
- 46:59And that moment, something magic happens.
- 47:02And that magic, some people feel, goes against the grain of certain Python principles.
- 47:09Like there should be obvious things happening.
- 47:13That Python is very explicit about what it does.
- 47:16As Tim Peters once said in a very famous little recorded Python philosophy, there should be one obvious way to do it.
- 47:25And explicit is better than implicit.
- 47:28Super in Python 3 is implicit.
- 47:30When you don't pass in arguments, it implicitly finds its arguments.
- 47:33So that's why people call this magic.
- 47:35But the reason why they're doing it is to avoid having to repeat yourself.
- 47:39There's a lot of extra things going on in the hood in that when you create a method in a class, then a closure is created specifically for it.
- 47:49So it is as if the function has been defined in a context where the name under class is available in a parent context.
- 47:57Basically, it means it captures its setup when it gets created.
- 48:02And then it can't really be influenced from the outside.
- 48:06It can no longer be influenced from the outside.
- 48:08And you no longer have to repeat yourself and passing it in.
- 48:12It was also a common source of problems, a common source of errors where people misunderstood what needs to be passed in.
- 48:18I already said you explicitly have to call, name foo and not take the current type of self because that may no longer be foo.
- 48:26There might be a subclass.
- 48:28And at the time, I did a search on code search engines and found tens of thousands of errors of people passing in either self.
- 48:36On their class or passing in type self, thinking that's good enough.
- 48:41I don't have to repeat myself here and type foo again.
- 48:44I'll just take it from self.
- 48:46And that leads to problems because when you have a subclass that also uses super, you get an infinite loop.
- 48:53Because then you say foo is subclass to bar, bar calls foo, and then foo passes in bar each time.
- 49:00And therefore, you go back up in the circle and we keep calling the same thing.
- 49:05Do you actually get a stack overflow exception?
- 49:07You get an infinite recursion error.
- 49:09Okay.
- 49:09It protects you from stack overflow.
- 49:11Yeah, good.
- 49:12Nice.
- 49:14All right.
- 49:14So that is really cool.
- 49:16And, you know, I think what's really interesting is as you, you know, as you mentioned in the beginning, but as we go through these, it's really clear how it's what you learn by going through this exercise of reading the question, the answer or answering it yourself.
- 49:29It's not just what is the question, what is the answer, but there's so many additional things and techniques and practices that come through.
- 49:37I think it's great.
- 49:38I really learned to understand what the decimal due does and how that works and how the Python evaluation loop works purely from answering on stack overflow.
- 49:47Yeah, I can see that.
- 49:49All right.
- 49:50So another one is about Python 3's range objects.
- 49:54Really two questions and sort of relative to Python 2's, which just turns them into a list of the things, a list of the integers.
- 50:02Yeah, so Python 2, you have range, which is just a function that produces a list of integers and x range, which is a separate object that models the sequence, but it's quite simple and it's quite limited.
- 50:15Python 3, they renamed x range to range because you don't really need that as a function.
- 50:19You can just call list on the range object and then get the same results.
- 50:24So range in Python 3 is a separate sequence object.
- 50:29And I love the object.
- 50:30I think it's a great idea.
- 50:31I wonder why it took so long to make this such a first class object and to make it something that is part of Python core the way range is now in Python 3.
- 50:41Ranges are very lightweight.
- 50:43You just tell it, this is the start, this is the end, and this is the step size, how we get from start to end.
- 50:49And that's all it records.
- 50:50It doesn't need to know all the numbers in between because you can very quickly just calculate those.
- 50:56If you know that you start at 1 and you end at 10 and your step size is 2, then you know that 3 and 5 and 7 and 9 are all part of that sequence.
- 51:07You can just calculate that, right?
- 51:09It's just math.
- 51:10So why would you have to keep that in memory?
- 51:12So most people still don't realize that range objects are smart like that.
- 51:17So you do see lots of questions about them.
- 51:20These are two example questions about someone being surprised, so surprised that if you make the range really large, you think that if you start at 1 and you put the endpoint at 10 million, that's numbers, right?
- 51:32The human mind will see that that's 10 million numbers in that object.
- 51:37That must take a lot of memory.
- 51:38That must be really slow to figure out whether or not the number 10 million and 1 is part of that range.
- 51:44But it isn't.
- 51:45It's just math.
- 51:46It's very easy to calculate.
- 51:48Yeah, and it gives you a good look inside it because the person asking the question says, well, I could write one with generators and yields and so on.
- 51:56But it takes it forever.
- 51:58And so your answer to it was basically, well, let's look at the actual implementation.
- 52:04And it's not just something that generates a sequence but can be smarter.
- 52:09Like it can implement dunder contains and get item and lend and all these different things that have actual.
- 52:14It behaves just like other sequences, just like lists and tuples and strings.
- 52:18You can ask for any of the elements at any point in that range, but it doesn't have to keep them up front.
- 52:25It can calculate them as you need them.
- 52:26Yeah, yeah, that's cool.
- 52:28It's really, again, a really nice look inside of things.
- 52:31And I guess the last example we want to look at is about the order or lack thereof for sets and dictionaries, which is slightly changing, right?
- 52:40That's exactly what's happening.
- 52:44For many beginners, it is surprising that collections like dictionaries and sets don't have a set order.
- 52:50There's an implementation detail of how Python has implemented dictionaries.
- 52:55And that comes from – it usually happens to people also new to programming.
- 52:59So they don't just come to Python as new and as the first thing that – it's also usually the first thing that they come to as a programmer, to programming in the whole.
- 53:10Because if you, for example, have done systems programming in C or C++, most people that come from that kind of bank account already realize this.
- 53:18But to make a dictionary efficient, so to be able to map a key to a value, you want to be able to store this efficiently and quickly find things.
- 53:30So once you start working on this, you realize that it looks like there's an order, but the dictionary can't promise any order because the order that the keys are put in is just a property of the storage medium that we put things in.
- 53:44Because we are putting a bunch of keys into a much smaller space and then quickly being able to find if a key exists or not in such a table.
- 53:55Because we base this on what we call the hash, the property of any of these keys to be reduced to a simple number.
- 54:02Explaining that is surprisingly often needed.
- 54:06Once people understand it, they can – oh, okay, right, fine.
- 54:09And we can go to another type and we can point to things like the order dict that also exists in Python.
- 54:14Or tell them that in Python 3.6, the implementation changed.
- 54:18So now dictionaries actually do remember order just because someone found a more efficient way of building the same kind of data type.
- 54:27So Python 3.6 makes dictionaries ordered, not because everybody wants them to be ordered, but because it was a more efficient way of storing information.
- 54:37Python 3.6 makes dictionaries an order of magnitude smaller in certain cases.
- 54:43And that's actually super important because that's in some sense the backing store for all instances of objects.
- 54:49Exactly.
- 54:49Yeah.
- 54:50Exactly.
- 54:50Lots and lots and lots and lots and lots and lots of stuff in Python uses dictionaries.
- 54:54So you can end up with quite a number of those.
- 54:57So making them smaller is a very good idea.
- 54:59Yeah.
- 55:00So this question is really like you need to understand data structures to understand what is happening here because it doesn't make sense.
- 55:08Like, well, why wouldn't I just want it to have the order?
- 55:10But of course, you know, at least the older implementations, you want it to be fast more than you want it to be other order.
- 55:16Exactly.
- 55:17And it also helped implement a few other new things in Python 3.6 like the keyword argument order can be important in certain cases or the class attribute definition order can be important in certain cases.
- 55:29And they are now as a property of this new dictionary implementation also implemented.
- 55:34So suddenly when you create a class, all your attributes are kept in the same order that you define them, which can help form building libraries, for example.
- 55:44Yeah.
- 55:44Yeah.
- 55:45Currently, you have to do crazy tricks to make keep it order.
- 55:47Yeah, absolutely.
- 55:48Absolutely.
- 55:49And MongoDB, for example, has its own dictionary type thing because it doesn't want to reorder and entirely rewrite big parts of stuff.
- 55:58And there's a lot of areas where this order actually would be kind of nice to have.
- 56:02So very cool.
- 56:04So those were some great questions.
- 56:06And I feel like I've really learned a lot.
- 56:08I hope people have as well just hearing you talk about them.
- 56:11But why – like this is a lot of work.
- 56:14Why do you contribute so much time and energy to Stack Overflow?
- 56:17I already mentioned that I learned a lot from this.
- 56:19I didn't start Stack Overflow because I wanted to learn so much.
- 56:24I started because I was part of the Plone management community.
- 56:27And we discovered Stack Overflow early on as a good idea to support people that wanted to learn about Plone and wanted to use Plone and then sort of fell into answering Python questions as well.
- 56:39But I've since heard in an interview with another Stack Overflow numinary and creator of the C# compiler, Eric Lippert once had an interview, I think, with Stack Overflow actually, giving his reasoning as to why he started with Stack Overflow.
- 56:57And answering questions.
- 56:58And that a manager actually told him that he should become an expert in certain things.
- 57:04It would be helpful for him to become an expert in a certain subject.
- 57:07And that the best method of becoming an expert in anything was to find a source of questions and start answering them.
- 57:15Because then you really discover all the things you don't know yet and start learning those yourself to try and be able to answer these things.
- 57:24And that really resonates with me.
- 57:25That's really why I'm answering on Stack Overflow so much.
- 57:29It's because it keeps teaching me new things.
- 57:33It keeps pushing me into new directions and new areas of expertise that I didn't know I could do before.
- 57:40Yeah, that makes a really…
- 57:41I really enjoy that.
- 57:42Yeah, that makes a lot of sense to me, your answer there.
- 57:45About the expert especially.
- 57:47I think one of the things that makes somebody an expert is not that they've sat down and done programming for five years or ten years or whatever.
- 57:55It's really how you spend that five or ten years.
- 57:58If you just do the same thing over and over and don't run into many challenges and don't force yourself to continue to dig deeper, then you're not that much more of an expert than what you learned in the beginning.
- 58:11But it's more the challenges and the problems and the edge cases that have hit you.
- 58:16And I feel like Stack Overflow is that concentrated.
- 58:21Yes, and it is a constant source of new challenges.
- 58:24And in that way, it can be sort of addictive as well.
- 58:28So you have to be careful.
- 58:30I'm sure.
- 58:30So speaking of addictive, what if I was really convinced that 2,000 for my reputation was insufficient and I decided the next week I'm going to take eight hours a day and just start answering questions and asking questions and just going crazy?
- 58:45Obviously, my reputation would go up, but would there be other effects?
- 58:50Would people start contacting me for jobs?
- 58:53Like, hey, I saw you're doing great on Stack Overflow.
- 58:56And answer these questions.
- 58:57Do you want to come work for us or things like that?
- 58:59People have used my Stack Overflow presence as a reason to contact me.
- 59:04But I think that's not really the norm.
- 59:06So I'm also looking at this from the point of view of hiring people.
- 59:11How would I use Stack Overflow?
- 59:12If I see someone that has a better reputation of Stack Overflow, that it works just like a blog.
- 59:18It gives me a great insight into how you think and how you work and how you look at code and how proficient you are in those things.
- 59:27Because you have this body of things out there that we can look at.
- 59:31Or just like open source work, open source projects that you did.
- 59:33A Stack Overflow profile with a good body of answers can be a real asset to let potential employers know that you know your stuff.
- 59:44That you know a thing or two about what you're talking about because you can actually demonstrate this.
- 59:48Which can give you a huge advantage because a lot of times people applying for jobs can't demonstrate their skills.
- 59:54Exactly.
- 59:54Exactly.
- 59:55So Stack Overflow is actually really building on top of this because they give you ability to develop your CV or developer stories they call it now on the site.
- 1:00:06And that they actually have a nice site business or actually their main business next to it to get employers connected with those people that have filled in a profile there.
- 1:00:17Right.
- 1:00:18The whole Stack Overflow careers thing, right?
- 1:00:19The whole Stack Overflow careers thing.
- 1:00:21And that does give you a lot, can give you a lot of insight into people how they work and how they think and see code.
- 1:00:28So up to a certain level, getting answers on Stack Overflow, provided you, of course, know your stuff a bit, can help you there.
- 1:00:35If I see someone with my level of reputation, I would start asking, are they spending too much time there?
- 1:00:42Will they actually do work for me or will they just come to work and answer Stack Overflow questions?
- 1:00:47Interesting.
- 1:00:48I said, keep people interested, right?
- 1:00:51Yeah.
- 1:00:51You would learn a lot, I think.
- 1:00:54If you seek out questions, there is such a thing, it's the fastest gun in the West where someone already knows the answer, can type faster than you and gets the first answer in and then that gets upvoted.
- 1:01:05So if you're in it for the reputation and the upvotes, you're going to have to wait a little while because you're going to probably be a little slower than the experienced hands, the people that can type out the answer quickly.
- 1:01:17Sure.
- 1:01:18But at the same time, at that moment, you can compare your answer to theirs and see, did I miss something?
- 1:01:24Did I miss a detail?
- 1:01:25Did I miss a trick?
- 1:01:27Did I use something interesting out of the standard library that I didn't know about yet?
- 1:01:32So next to that, you're having to figure out how I'm answering this.
- 1:01:36Do I know the answer?
- 1:01:37You also get to see how other people are answering.
- 1:01:40So that's something different than you're trying to find the solution to a problem you have.
- 1:01:44You are actually looking at new questions as they come in and see how other people are answering them at that moment.
- 1:01:49It's a slightly different angle.
- 1:01:51You get to see how other people think about their problem.
- 1:01:53And you might learn a thing or two about that.
- 1:01:55Okay.
- 1:01:56Very interesting.
- 1:01:56I probably won't take a week and go work on Stack Overflow, but it's interesting to think about what would happen if I did.
- 1:02:02It is certainly an interesting thing you can do for half an hour when you're maybe waiting for the bus or something like that.
- 1:02:07Yep.
- 1:02:08Absolutely.
- 1:02:08All right.
- 1:02:09So let me ask you one final Stack Overflow question.
- 1:02:12And I've seen a couple of articles lately that felt like Stack Overflow was unfriendly to beginners or to newcomers.
- 1:02:19And you had an interesting thought on that.
- 1:02:21There's two angles here.
- 1:02:22First of all, there's often a mismatch of expectations what Stack Overflow is for.
- 1:02:29Stack Overflow is often seen as a personal help desk, something you can quickly put a question on and they'll help me fix my problem.
- 1:02:39And then get upset because their question might get put on hold or downvoted because they didn't meet the expectations of what Stack Overflow has, which is to build a knowledge base, to build a repository of good questions and even better answers that help future visitors.
- 1:02:57So if you forgot to explain what inputs came out of it or what the full error message is or you show a clear lack of having actually done the research about how to solve your problem, then you might actually find Stack Overflow very disappointing.
- 1:03:15And then there's the other thing is that people say that Stack Overflow is only for professionals and not for newcomers and for new people, newbies new to programming or new to our programming language.
- 1:03:25Again, that's not true.
- 1:03:26It's usually what happens at the same time is that people are new to asking questions and they don't know how to ask a good question.
- 1:03:33And that then really fires back on them.
- 1:03:36So, and then there's, of course, the fact that because we are trying to, Stack Overflow is so hugely popular, we get maybe a few thousand of such people come in every day and asking questions.
- 1:03:49So the community, on the other hand, is running out of steam and running out of power to keep helping each and every one of those learn about Stack Overflow.
- 1:03:56So a lot of people don't get the hand-holding that they might expect.
- 1:04:01Well, I'm new to this site.
- 1:04:02Why didn't you tell me?
- 1:04:03Well, Stack Overflow tries to automate this, tries to give you the help up front.
- 1:04:10You get a lot of information about how to ask a good question.
- 1:04:13There's lots of information in the help center.
- 1:04:15But when you have a programming problem and your homework is due tomorrow, not everybody will reach that.
- 1:04:19And then they skip by that very quickly.
- 1:04:22And then what they see is what...
- 1:04:25Yeah.
- 1:04:26I feel a huge difference based on whether or not the person is legitimately trying to solve the problem and needs help or if they're just being lazy.
- 1:04:34You know?
- 1:04:34I do want to avoid the term lazy.
- 1:04:36It is often just a misunderstanding.
- 1:04:38And a certain sense of urgency can...
- 1:04:42Because you have this problem and you're so into this problem and trying to solve it that you can forget to see the larger picture around it.
- 1:04:50It's not necessary that you're being lazy always.
- 1:04:53Sometimes there are lazy people that do post their homework on the site or even their exam questions as they sit in the exam.
- 1:05:02I have literally seen posts where that consists of nothing more than a photograph of a paper that's clearly taken underneath the desk.
- 1:05:12No, no, this is not an exam.
- 1:05:14This is a trial question.
- 1:05:17But can you give it to me in the next 10 minutes?
- 1:05:21I'm going to need that before 9 o'clock because I've got to turn this in.
- 1:05:24I'm going to turn this in.
- 1:05:26Some people are lazy but most people just don't understand what makes a good question and why Stack Overflow is there.
- 1:05:36And that clash can lead to frustration.
- 1:05:39Yeah.
- 1:05:39So I think this conversation has definitely helped everyone who's listened to it understand what makes a good question and so on.
- 1:05:47So hopefully we've done a small part to reduce the frustration on both sides, the people answering the questions, being frustrated with the unprepared homework folks coming in.
- 1:05:59I guess we'll leave it there for Stack Overflow.
- 1:06:02But, Martin, that was very, very interesting.
- 1:06:05And I think reading through your answers and other people's answers and questions is definitely enlightening.
- 1:06:12Thanks for the work on that.
- 1:06:13That's cool.
- 1:06:13Before I let you go, two final questions I'd always ask my guests.
- 1:06:17First of all, favorite PyPI package?
- 1:06:19What would you recommend to people out there that they might not know about?
- 1:06:22This is one I discovered.
- 1:06:23Someone else used it in an answer and I love it.
- 1:06:26I have been using it ever since.
- 1:06:28It's called FTFY or Fix This For Me, For You.
- 1:06:32Fix This For You.
- 1:06:33It is a library to fix Mojibaki or text encoding errors.
- 1:06:41So if you ever try to make sense of UTF-8 encoding text decoded as Latin 1 and then re-encoded as something else,
- 1:06:51the Fix This For You library, FTFY library, will do it for you.
- 1:06:54It automatically detects when an encoding was misapplied and fixes it for you,
- 1:07:00as well as some other common noise in incoming text.
- 1:07:04I love this for content management.
- 1:07:07I love it for handling badly decoded webpages, anything like that.
- 1:07:12Fix This For You has saved my backside a couple of times already.
- 1:07:16That's fantastic.
- 1:07:17All right, favorite editor?
- 1:07:19If you're going to write some Python code, what do you open up?
- 1:07:21If I'm on a terminal, Vim.
- 1:07:23And generally on my desktop, it's Sublime Text 3.
- 1:07:26Nice.
- 1:07:26Yeah, I was just using Sublime Text earlier.
- 1:07:28I like it a lot.
- 1:07:29All right, how about a final call to action?
- 1:07:31What should people do to get more involved with Stack Overflow?
- 1:07:34Common and try and answer stuff.
- 1:07:36There are always niche tags that need more people answering.
- 1:07:40Things like Python may be overflown with people that know their things.
- 1:07:45But if you have a specific expertise in programming, there usually is a tag for you.
- 1:07:51And finding more answers to these questions are always helpful.
- 1:07:54All right, excellent.
- 1:07:55Well, thank you for all the work you've done on Stack Overflow around Python.
- 1:07:59It's really amazing.
- 1:08:00And thanks for being on the show.
- 1:08:01Great to talk to you.
- 1:08:02Cool.
- 1:08:02Great.
- 1:08:03Thanks.
- 1:08:03Bye.
- 1:08:05This has been another episode of Talk Python To Me.
- 1:08:08The guest today has been Martin Peters.
- 1:08:11This episode has been sponsored by Rollbar and GoCD.
- 1:08:14Thank you both for supporting the show.
- 1:08:16Rollbar takes the pain out of errors.
- 1:08:19They give you the context and insight you need to quickly locate and fix errors that might have gone unnoticed until your users complain, of course.
- 1:08:27As Talk Python To Me listeners, track a ridiculous number of errors for free at rollbar.com slash Talk Python To Me.
- 1:08:33GoCD is the on-premise, open-source, continuous delivery server.
- 1:08:38Want to improve your deployment workflow but keep your code and builds in-house?
- 1:08:43Check out GoCD at talkpython.fm/G-O-C-D and take control over your process.
- 1:08:49Are you or a colleague trying to learn Python?
- 1:08:51Have you tried books and videos that just left you bored by covering topics point by point?
- 1:08:56Well, check out my online course, Python Jumpstart, by building 10 apps at talkpython.fm/course to experience a more engaging way to learn Python.
- 1:09:05And if you're looking for something a little more advanced, try my Write Pythonic Code course at talkpython.fm/Pythonic.
- 1:09:12You can find the links from this episode at talkpython.fm/episodes slash show slash 86.
- 1:09:19Be sure to subscribe to the show.
- 1:09:21Open your favorite podcatcher and search for Python.
- 1:09:23We should be right at the top.
- 1:09:25You can also find the iTunes feed at /itunes, Google Play feed at /play, and direct RSS feed at /rss on talkpython.fm.
- 1:09:34Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
- 1:09:39Corey just recently started selling his tracks on iTunes.
- 1:09:42So I recommend you check it out at talkpython.fm/music.
- 1:09:46You can browse his tracks he has for sale on iTunes and listen to the full-length version of the theme song.
- 1:09:51This is your host, Michael Kennedy.
- 1:09:53Thanks so much for listening.
- 1:09:54I really appreciate it.
- 1:09:56Smix, let's get out of here.
- 1:10:06I'll see you next time.
- 1:10:18Bye.
- 1:10:18Bye.
- 1:10:19Bye.