Latest / Talk Python To Me / #85: Parsing horrible things with Python
Transcript
- 0:00Do you have horrible convoluted things that need parsing?
- 0:02Well, you're in luck because this week we're covering parsing horrible things in Python.
- 0:08Obviously, you'll learn a bunch of tips and tricks from this episode,
- 0:11but you'll see that advanced parsing is actually a gateway to many interesting computer science
- 0:16techniques. Listen in as I speak with Eric Rose about his journey to parse weird things at Mozilla.
- 0:21This is Talk Python To Me, episode 85, recorded October 27, 2016.
- 0:28Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the
- 0:57ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter where
- 1:02I'm at mkennedy. Keep up with the show and listen to past episodes at talkpython.fm and follow the
- 1:08show on Twitter via at Talk Python. This episode has been sponsored by GoCD and Hired. Thank them
- 1:14both for supporting the show by checking out what they have to offer during their segments.
- 1:17Hey, everyone. A little bit of news for you. So first of all, I'm doing a webcast next week,
- 1:24Tuesday, November 22, at 11 a.m. Pacific time. The topic is Write Pythonic Code for Better Data Science.
- 1:31And I've partnered with Kevin Markham from Data School. And this is 100% free. You can drop in.
- 1:36And it's kind of like a super miniature version of my Write Pythonic Code course. So if you want to come
- 1:42check it out and register, just go to crowdcast.io slash e slash Pythonic or click that same link in
- 1:49the show notes. I was talking to the PyCharm team this week, and they agreed to give away a free copy
- 1:55of PyCharm Professional every week to one lucky listener. So all you have to do to be in the running
- 2:01for this is be a friend of the show. Just visit talkpython.fm/friends, enter your email address,
- 2:07and randomly I'll choose an email address out of the list, and somebody will win. And because we're
- 2:12doing every week, the odds are pretty decent for you to get a copy. Let's get to this excellent
- 2:16interview about parsing horrible things with Eric Rose. Eric, welcome to Talk Python.
- 2:22Thanks for having me, Michael. Pleasure to be here.
- 2:23Yeah, it's great to have you. I'm really looking forward to parsing horrible things and a bunch of
- 2:28other stuff.
- 2:29Well, nobody in their right mind really looks forward to parsing horrible things, but it's something we
- 2:33have to do.
- 2:33Well, when you have horrible things and you want to parse them, someone's got to do it, right?
- 2:37That's right.
- 2:38So I think it's, we're going to talk about some really cool techniques, some libraries,
- 2:42some algorithms, and whatnot to pull that off, and some interesting work and talks that you've done.
- 2:47But of course, before we get into those, let's start with your story. How do you get into
- 2:50programming in Python?
- 2:50Well, I mean, I used to be a Legos kid, right? You know, like snapping those things together.
- 2:55And of course, the thing about being a kid is you have no economic power, so you've only got the
- 2:59ones you've got in the box, and you get at birthdays, and you get at Christmas or what have you.
- 3:03And so I kind of discovered programming as a way to program with, to build with Legos without ever
- 3:09worrying about running out of parts. And so I became kind of an early collector of programming
- 3:13languages, you know, before the internet. So you have to get these things kind of happen upon them
- 3:17on floppy disks or whatever. And I did basic and I did hyper card and kind of learned programming
- 3:22through mimicry like we all did in the 80s. You know, you get these magazines with program listings
- 3:28in them. And you just kind of have to type them in if you want to play with them. And so you're just forced to plow
- 3:34linearly through these things, making mistakes throughout. And that kind of teaches you debugging and proofreading.
- 3:39And you come to all kinds of wrong conclusions. Like I remember in hyper card, there's this statement global
- 3:45start flag, which of course the global variable declaration, but I thought it was this round checkerboard cursor,
- 3:51which totally looked like a global start flag to me. So, you know, fast forward two dozen languages later
- 3:57and I ended up working at a university over at Penn State and we had this crazy seminar registration
- 4:03system called SEMREG. Maybe they're still running it. I really hope not. And it was, well, the simple thing
- 4:10I could say is it was written in VBScript, but really it was written in PHP and then transliterated into
- 4:17VBScript via a series of regular expressions. Wow. That's crazy. I've never heard of anything
- 4:22being compiled from PHP to VBScript. Absolutely insane. And compiled is probably too kind of a word,
- 4:27but, so I didn't realize this when I took the job, you know, I've become a lot smarter about
- 4:33interviewing since then, I hope. And I thought I'm going to give this a chance. You know, I'm this big
- 4:37Mac guy and I, it was, it was the height of the platform wars and windows was terrible, but I, you know
- 4:42what? I'm going to, I'm going to not be a jerk. I'm going to give this thing a chance. I'm going to see if I
- 4:45can write stuff in VBScript. And the short answer is you can't write anything in VBScript.
- 4:49The thing has classes, but no inheritance. And, so, you know, with a little detour through making
- 4:56my own, prototype based inheritance language out of the call statement, I thought, okay, we need to
- 5:03bridge this over to something more usable. And Python was very well supported at the time on Windows
- 5:09scripting host, which allowed me to do ridiculous things like share a database connection between the
- 5:14legacy VBScript code and the new Python code. And that's how I got into Python, believe it or not.
- 5:20Interesting. Because if you can get a drawer in the script host, you can basically get it the same
- 5:24environment as this other bad thing, right? Yeah. You can kind of mash it all together. It'll bridge
- 5:28strings to strings. It'll actually bridge objects to objects and methods to methods, numbers to numbers.
- 5:34And if you bang on it hard enough, you can get database handles shared and share a single
- 5:38transaction between the two languages. So I was very fortunate to happen upon Python that way.
- 5:43Yeah, that's great. And it looks like you've been doing a bunch of Python since then, huh?
- 5:47Well, Python is a really, nice little patchwork of, of, of stolen bits of language.
- 5:53There's not a whole lot unique about Python, which I think is one of its strengths apart from maybe the
- 5:57width statement, but it knows where to steal all the best things, the list comprehensions out of Haskell,
- 6:03for example. And, you know, Hey, we're going to steal, you know, class-based object orientation
- 6:08from wherever that came from small talk, I guess, but we'll also have top level functions from any
- 6:13number of languages. So I've been pretty happy with it. Yeah, absolutely. And it's still,
- 6:17still on its way to doing that thing with like async and await in the latest version, right? Which is
- 6:22a fantastic language feature. Yeah. We'll see where that goes. I haven't played with it myself.
- 6:26Yeah. I'm still looking for a good use case for that as well, but it's, it's definitely a neat
- 6:29concept. So how about now? What do you work on these days?
- 6:33Well, day to day, I maintain a project called DXR over at Mozilla, which doesn't really stand for
- 6:39anything, but is a language analysis and navigation tool for large code bases. So
- 6:45Firefox is something like 17 million lines of code. You know, if you want to make a change,
- 6:50you've got to be thinking, well, what am I going to break with this change? Who am I affecting?
- 6:53What functions call this function that I want to change? What, what eats the result of the
- 7:00contents of this variable that I want to alter or, what invariant might I be violating here?
- 7:06And DXR answers those kinds of questions through a structured query language and through both text
- 7:12search and a cleverly accelerated regular expressions search. So you can get through these 17 million
- 7:17lines with a regex in, you know, sub second. Wow. And how you said 17 million lines of code. That's,
- 7:24that's quite impressive. That's bigger even than I thought it would be, but I knew that was huge.
- 7:29How many languages are involved in that? Oh, that's a crazy question to ask. Well,
- 7:34okay, I'll just go with language. So HTML is a language though, not programming language,
- 7:39arguably CSS is Turing complete. Someone has proved as long as it's level three. So that's a programming
- 7:45language. Now a lot of the UI is written in JavaScript. A lot of the down and dirty stuff
- 7:50is written in C++. And more recently we've begun importing, Rust into the code base.
- 7:55Rust is now a part of the released Firefox and, and more and more with the release of project quantum,
- 8:01which was just announced last week, will be ported over to rust. So it's, so we can make more
- 8:07guarantees so it can be safer and more concurrent. Nice. And what's, what is project quantum?
- 8:12Project quantum. Let's see if I can get this right. Is a Mozilla project just became unsecret to import a lot of our
- 8:22experimental, a Rust based rendering pipeline into Gecko, which is the current released,
- 8:28Firefox pipeline. So project, that I mentioned serve already. I forget.
- 8:33No, the sort of thing we're importing things from is servo an experimental web renderer written in rust,
- 8:40a CSS renderer, HTML, all that jazz. And, yeah, we're, we're pulling bits of that into Gecko.
- 8:47Okay. That's awesome. It's a very exciting time that'll let us be more concurrent and use all these
- 8:52different cores on all these different things. You know, phones even have four cores now.
- 8:55Yeah. Watches even have multi cores now.
- 8:57Yeah. It's crazy. It's a crazy time to live.
- 8:59It is a crazy time. You said another thing you're working on is fathom. What's fathom?
- 9:03So fathom kind of, fits into all this, this parsing subject. Fathom is my new kind of toy over at
- 9:08Mozilla. It's a mad scientist project to see if we can make it easier to write semantic extractors for the web.
- 9:14So an example of a semantic extractor you might know is something along the lines of readability
- 9:18or a browser's reader mode, where it just pulls the content text out and dispenses with headers and
- 9:24footers and ads and such. But other things you might want to extract are, Hey, let's, let's teach a browser
- 9:30to recognize what a previous or next button looks like. So that maybe the browser can let you assign
- 9:35a keystroke to that in the general sense and not have to chase them as they bounce around as you advance
- 9:40through a slideshow. Or maybe we can teach the browser at a deeper level to appreciate what an
- 9:45advertisement is or what a navigation element is. So maybe we can collapse those on small screens and
- 9:50hide them in a menu. There really, there's really endless potential to this. And I'm trying to
- 9:56fix it. So those extractors are easier to maintain, faster to write and become less of a mess.
- 10:02If you were to read the readability source code, which is kind of the thing that both Firefox's
- 10:08reader mode and Safari's reader mode are based on, you get the sense that it's been written by hand,
- 10:13maintained over time. There is state flying everywhere. It's hard to tell where to make tweaks.
- 10:21So what Fathom does is express these extractors as lists of unordered rules in a prologue sense. If
- 10:28you've ever played with prologue, it's just a whole bunch of kind of, logical statements. And then
- 10:32the environment figures out how to fit those together and run them. Well, Fathom, works along those
- 10:37same lines. And as a result, since order doesn't matter, third parties can tweak and, can tweak an
- 10:45existing extractor just by inserting their own rules. They can say here, whenever you see a,
- 10:50uh, whatever kind of element, for example, I want to boost the score by this much or lower it by that
- 10:55much. Nice. So you could put like understanding of time of calendars and dates and whatnot, possibly
- 11:01as another rule. Exactly. Hey, this looks like a calendar or, Hey, this looks like a payment form.
- 11:05Let me help you fill it. Yeah. Okay. Yeah. That's awesome. Is that in Firefox yet? Or is this,
- 11:11this is just a project so far? We hope to get it in so that, other things,
- 11:15can make use of it more easily, but, it's already embeddable within Firefox add-ons and has
- 11:20been embedded in, at least one add-on. It's kind of a Fathom debugging add-on.
- 11:25it runs on the server side. It's all just kind of vanilla ES6. You can compile it down to ES5 for
- 11:30older browsers. It kind of runs all over the place. I wrote it in JavaScript despite not liking
- 11:35JavaScript myself so that we could get it, popular. Yeah. Sometimes, sometimes you got to go with
- 11:41that. Well, that sounds really cool. And then another thing that you're involved in is
- 11:44let's encrypt, which is very exciting. Yes. Let's encrypt has probably got the easiest
- 11:49business plan I've ever heard, which is to give away a hundred dollar bills.
- 11:52How's that work? How do I, how do I get my a hundred dollar bill?
- 11:55Well, if you've ever bought a, well, it's very easy. So certificates,
- 12:00this is all certificates have historically been fairly expensive on the order of a hundred bucks.
- 12:04And there are some other ways to get cheaper ones through start SSL or Komodo or whatever is kind
- 12:09of a hassle. But what we do is we have a little command line tool that you run. And if,
- 12:14if you can authenticate yourself to our little, certificate creating server through a DNS record or
- 12:21putting a little thing on your server temporarily, then we will give you a cert, which is recognized by
- 12:27all the major browsers. So really there's no way, no reason not to use it at this point.
- 12:32Yeah. So having encrypted content is obviously important if you're doing like e-commerce or something
- 12:38like that, but it's also just becoming increasingly important to be a first class citizen on the web,
- 12:43right?
- 12:44It really is. It, I mean, it gives you the impression of trust. First of all, if people are
- 12:48watching their URL bars, but also it's important for your visitors just to have the requests be private.
- 12:53If I'm surfing to Wikipedia and, not doing anything particularly suspicious, but say I have a
- 12:59suspect, I have a medical condition and I'm reading about all these different skin diseases or whatever
- 13:04is ailing me. I don't want my ISP logging that away and selling it to their marketing partners,
- 13:10which until the FCC's ruling last week was perfectly legal to do state actors. I mean,
- 13:16the best defense we have against really anybody in the future coming to power and looking into our past
- 13:23and seeing things they don't like, and then coming down on us is keeping things that are our business,
- 13:27our business and using, SSL certificates and surfing to secure sites is the best way to do that
- 13:34right now.
- 13:34Yeah. And the fact that let's encrypt is, is free makes that very, very possible. And I think that's,
- 13:40that's great. You know, there's a really interesting studies quoted in the original Edward Snowden book
- 13:47that came out, I think, by Greenwald. I can't remember that guy's glad Greenwald, I believe.
- 13:52Yes. That guy. And it was a great book. And basically, you know, a lot of people say, look,
- 13:56I don't care about this privacy stuff. Like I have nothing to hide, but there've been psychological
- 14:01studies and social, social studies saying people behave differently. If they know somebody's listening,
- 14:07they might not break a rule in private, but they behave differently. They are slightly more private,
- 14:13less willing to think, you know, sort of contrarian ideas and at least share them. And the less that
- 14:19people are watching the better as far as I'm concerned for, for people in general.
- 14:24Yeah. It's really the idea of chilling effects, which came out of some academic institution. It's
- 14:29a wonderful phrase. And when you have chilling effects in operation, where you are afraid to do
- 14:35perfectly legal things, which otherwise you might not do, democracy really cannot function.
- 14:40How democracy works is by means of, well, really the Overton window, this range of things that you're
- 14:46allowed to say and think that don't get you kicked out of cocktail parties.
- 14:50And this window moves around over time. It's, you know, yesterday's conservative, rather yesterday's
- 14:56progressive is today's conservative. And if we're not allowed to play with ideas that are just outside
- 15:02the bounds of the Overton window, then the future really has nowhere to pick its new ideas from.
- 15:07And we just kind of stagnate and the powers that be become the powers that always will be.
- 15:12And the ideas that are, are the ideas that always will be, and we can't really go anywhere.
- 15:17So, yeah, I think privacy is key to having a functioning democracy at all.
- 15:22Yeah, I totally agree. And if you don't buy that, Google ranks sites higher if they have SSL.
- 15:28We all want to rank higher in Google, right? So there's the Google juice.
- 15:31There's the final straw to, like, start encrypting stuff. My blog's encrypted. This podcast site is encrypted and so on.
- 15:38And I think it's great. Happy to do that on as much as I can.
- 15:42I'm wondering, how did you become interested in parsing all these horrible things? Where did you get started with that?
- 15:48Well, I guess, I guess it probably started when I was seven years old and playing around with basic and hypercard and thinking,
- 15:54oh, you know, I want to write my own programming language because, of course, you're seven and no one has told you that it's hard.
- 15:59And if you spend a couple of days trying to do that with just if statements, you end up in this spaghetti-fied mess and you can't get anywhere.
- 16:07And you're just amazed that anyone has ever managed to write a language ever.
- 16:11So, you know, then put in a little pause of about 25 years and it came up at work.
- 16:17Over at Mozilla, we had a support site. We still have a support site.
- 16:22Support.mozilla.org. And it's got a wiki and it's got a Stack Overflow clone and all this different stuff to help out people who are using Firefox and our other products.
- 16:30And our wiki is powered by not MediaWiki itself, but the MediaWiki syntax for various hysterical purposes, as we like to say.
- 16:41And not only do we want the MediaWiki syntax, but we wanted to be able to add our own little directives to the syntax.
- 16:48Crazy little things that'll maybe, well, one example is we wanted to change the text that would come up according to which version of Firefox someone was using to visit the site.
- 16:57It was very, very difficult to make those edits to the implementation of MediaWiki that we were using, which was a port by David Kramer, very nice little port, of the original MediaWiki machinery.
- 17:10Such a direct port, in fact, that it still had dollar signs in the comments from the PHP.
- 17:15Right. Yeah, it was originally PHP and you guys translated it over to Python and that helped because at least you were working in Python.
- 17:22But you said the way that it worked was the parser was pretty insane.
- 17:25Like it was just like a crazy bunch of regexes, right?
- 17:28Yeah, there were, I think, 41 regexes.
- 17:31And then there was another 2,100 lines of PHP, which just ran them over and over again against the source text, finding and replacing and finding and replacing, hopefully in the right order, interacting with each other, dropping little markers so that they didn't smash over each other when they shouldn't.
- 17:47And then hopefully at the end out comes the proper rendered text.
- 17:51Of course, in reality, MediaWiki language changes from release to release as they find little corner cases that this crazy slapdash loopy way didn't handle.
- 18:01Yeah, you called it the Klingon MediaWiki.
- 18:04Yeah, I look at these regexes and I think, well, this is the original Klingon, clearly.
- 18:08Yes, obviously.
- 18:09Nice.
- 18:11And so you were looking for a way to escape this Klingon parser world and create something nicer.
- 18:19Like one of the problems you said that was inherent in the algorithm was it would directly parse into its new representation.
- 18:26Right.
- 18:27There was never an intermediate representation.
- 18:29So tell people what, like, is, like, why do you care?
- 18:32Like, what's the intermediate representation do for you?
- 18:35Well, it gives you flexibility, like any abstraction.
- 18:37So let's say we have this imaginary intermediate representation for MediaWiki syntax.
- 18:42We bring in the MediaWiki syntax.
- 18:43We parse it into a tree because that's what all these things end up as in parsing land.
- 18:48And then we have a lot of options.
- 18:49We can output plain text from that, ignoring the bits of the tree that say bold or italic.
- 18:55We can render out HTML from that, not ignoring those things.
- 18:59We can go hunting through for just, say, date or time elements and pull out some date and timey entities.
- 19:06Once you have this abstraction, you have any kind of output you like.
- 19:09Or you can do any kind of analysis or transformation you like.
- 19:12Nice.
- 19:12So, for example, if you wanted to possibly represent stuff by a markdown output or an HTML output or plain text, those are super easy because both, like, markdown and HTML have a bold concept.
- 19:25One is a bracket, you know, angle bracket strong.
- 19:27One is a star.
- 19:29But it's, you know, you can do that final translation pretty easily once you have the tree, right?
- 19:34Exactly.
- 19:34That's the trivial part, going from tree back to a linear representation.
- 19:38So the hard part is getting it into a tree, huh?
- 19:41Right.
- 19:41Now, we're doing that as we talk, which is nice.
- 19:44Now, you make a linear sequence of sounds.
- 19:46And I hear them.
- 19:47And I deconstruct them back into, you know, phrases and word pairs and things and idioms.
- 19:51And I say, wow, that's probably what he means.
- 19:53And then you do it back from my end.
- 19:55Yeah, exactly.
- 19:55So pretty much pulling structure out of any flat, linear stream of data is parsing, right?
- 20:02Exactly.
- 20:03And so the applications are as wide as you like.
- 20:06I mean, anything that has any kind of structure, text, sound, you can think of musical phrases
- 20:11and the sorts of, a lot of music has a theme in variations or development of a thematic statement.
- 20:17On one hand, I sort of can see how you would do some of this with regular expressions.
- 20:22But it's really the goal is to move it into this parse tree because then it's not just transforming
- 20:27one bit of text into another text, but it's actually transforming into the structure that
- 20:30we can do all kinds of interesting things, huh?
- 20:33Well, right.
- 20:33And more formally, regular expressions can't really support nesting.
- 20:37Now, there are little corner cases that people were going to write in about where things that
- 20:42are called regular expressions nowadays, like in Perl, have support for nesting bolted on,
- 20:47but then they cease to become proper regular expressions.
- 20:49Exactly.
- 20:50Proper parsers, on the other hand, descend into the, what we call, like, Chomsky type one or
- 20:56two grammar and can support nesting.
- 20:59So you could say, understand sets of nested parentheses of arbitrary depth.
- 21:04And that's how things like, well, HTML, for example, are.
- 21:08You could have a bold tag with an italic tag in it with another bold tag in it at infinitum.
- 21:13Yeah.
- 21:13Div, span, A, all sorts of stuff.
- 21:17Yeah.
- 21:17More div.
- 21:18And in addition to the nesting, a proper parser gives you the ability to read what you're doing,
- 21:22essentially.
- 21:23Regexes are famous for being a write-only language.
- 21:27Absolutely.
- 21:27I definitely think of them as write-only.
- 21:29Yeah.
- 21:29And you can comment them as much as you like and put white space in there, but it still
- 21:33becomes, you know, at least awkward to name sub-patterns, to repeat sub-patterns, and to
- 21:39maintain something where you have repeated bits of regex.
- 21:42Sure.
- 21:42Well, and as it gets increasingly complicated, the more you need the regular expression, the
- 21:46less you can understand it, I think.
- 21:48Yeah, for sure.
- 21:48There seems to be a ceiling for one reason or another with straight-out regexes.
- 21:52Yeah.
- 21:52So you talked about there being different types of grammars that are different complexities
- 21:58of grammars.
- 21:59Yeah.
- 21:59There's the idea of the Chomsky hierarchy of grammars.
- 22:02And Chomsky is really a linguist.
- 22:05And so he spoke of these grammars in terms of generative power, where, you know, I can
- 22:11start from a production, a production name, something like sentence, and then descend in
- 22:16one level and say, well, sentences, you know, phrase, and then maybe another phrase, and maybe
- 22:20another phrase.
- 22:21And what are the phrases?
- 22:22Well, we have a subject, and we have verb, and we have an object.
- 22:25And he's interested in creating sentences from the top level.
- 22:28Now, as computer scientists, we're usually more interested in going in the opposite direction,
- 22:34starting with this complete sentence, and then kind of inferring out the structure, recognizing,
- 22:40as they call it in the literature.
- 22:41So Chomsky came out with Chomsky hierarchy of grammar, something like that.
- 22:46Anyway, levels 0, 1, 2, 3, and 4.
- 22:49And type 0 is basically a free-for-all.
- 22:53It kind of comes out looking like a directed graph.
- 22:56And there's not really, really available kit for parsing that sort of thing, or any algorithmic
- 23:02bounds to its complexity.
- 23:03When we get down to a level 1, that's your context-sensitive grammars.
- 23:08And Python is actually a context-sensitive grammar, I believe only for the reason that it has,
- 23:13only because it has whitespace sensitivity.
- 23:15So I was actually trying to parse something like Python the other day, a little side project
- 23:20of mine called Turtles.
- 23:21And I ran up against this.
- 23:23When you indent in Python, in a normal language, in a curly brace language, when you go inward
- 23:29a block, you say, curly brace.
- 23:31And then when you end a block, you say, end brace.
- 23:34Now, in Python, think about trying to write a tokenizer for Python, trying to find those
- 23:40instances where we go in a level or out a level.
- 23:42You're reading along, you're reading along.
- 23:45You're at the beginning of a line, and you see eight spaces.
- 23:48Did you go in a level?
- 23:49I don't know.
- 23:50What is the previous line?
- 23:52Is it four spaces?
- 23:53If so, I went in a level.
- 23:54So you can see that eight space span is interpreted differently depending on our context, depending
- 24:01on what the previous line had done.
- 24:02So Python is a context-sensitive grammar.
- 24:05Now, the rest of Python is at Chomsky level two, which is a context-free grammar.
- 24:12So if you were to dig into the Python source code, one of these files there, there's a little,
- 24:16let's see if I have it sitting here, a nice little sort of summary where it says, okay,
- 24:22here's what a suite is, a series of statements.
- 24:24A suite is a statement, statement, statement, or statement star.
- 24:27But it's always that.
- 24:28A suite is always this.
- 24:30An if statement is always that.
- 24:31You know, a function definition is always this.
- 24:34It doesn't matter what came before or what comes after.
- 24:36It's context-free.
- 24:38Right.
- 24:38Like, the if statement doesn't mean something different if it's in a while loop.
- 24:43It always means the same thing.
- 24:45So if you know what an if is, like, if you can define the structure of an if, you can define
- 24:49its meaning.
- 24:50And you don't have to do more interesting parsing.
- 24:52Yep.
- 24:52All the time.
- 24:53All the time, if means the same thing.
- 24:54There are no modes to go into or out of.
- 25:11This portion of Talk Python To Me is brought to you by GoCD from ThoughtWorks.
- 25:16GoCD is the on-premise, open-source, continuous delivery server.
- 25:20With GoCD's comprehensive pipeline and model, you can model complex workflows for multiple
- 25:26teams with ease.
- 25:27And GoCD's value stream map lets you track changes from commit to deployment at a glance.
- 25:33GoCD's real power is in the visibility it provides over your end-to-end workflow.
- 25:38You get complete control of and visibility into your deployments across multiple teams.
- 25:43Say goodbye to release day panic and hello to consistent, predictable deliveries.
- 25:47Commercial support and enterprise add-ons, including disaster recovery, are available.
- 25:52To learn more about GoCD, visit talkpython.fm/gocd for a free download.
- 25:58That's talkpython.fm/gocd.
- 26:02Check them out.
- 26:03It helps support the show.
- 26:04One of the things that you said, a quote from your PyCon 2012 talk, which I'll link to
- 26:18the show notes, of course, was that parsing is a gateway drug to other areas of computer
- 26:24science.
- 26:24It's true.
- 26:25I mean, once you have this tree-shaped intermediate representation, you can do anything you want.
- 26:30You can get into natural language processing, which if you're doing any of this in Python,
- 26:35NLTK is a not-to-be-missed library.
- 26:38It, first of all, is a shining example of what all library documentation should be.
- 26:43There is an NLTK book freely available and is a fantastic place to start if you want to
- 26:48start understanding human language with a computer or doing sorts of data mining and machine learning.
- 26:53It's also full of those sorts of algorithms.
- 26:55Great piece of kit.
- 26:56Yeah.
- 26:56Awesome.
- 26:57Awesome.
- 26:57Also, from the intermediate representation, you can get into programming language design.
- 27:01That's fun.
- 27:02Make your own little toy language.
- 27:04Anybody can make a lisp in a couple of days because the parsing is so darn simple.
- 27:10It's just a bunch of nested parentheticals.
- 27:13There's a lot of parentheses there.
- 27:16Yeah.
- 27:16Now I'm a lot less intimidated to reach for custom little query languages.
- 27:21Like, DXR has a custom little query language, which looks a lot like Google's custom little
- 27:25query language.
- 27:26And it's, you know, 10 or 20 lines of grammar description that I feed into my library parsimonious.
- 27:32And out comes the tree.
- 27:33Yeah.
- 27:34That's really cool.
- 27:35I feel like when you learn these new techniques and these data structures and algorithms, like, you see problems where you just saw opaqueness before.
- 27:44You're like, oh, I could actually apply this thing.
- 27:46And out would pop interesting answers.
- 27:48Whereas before, you're just like, there's no way I can answer that.
- 27:50That's just text blobs, not structure.
- 27:53Yeah, for sure.
- 27:53It's just pattern recognition.
- 27:54The more you've exposed yourself to, the more you'll say, hey, this is just one of those.
- 27:59Let's review some of the various options for parsing text in Python today.
- 28:04So there's two pretty well-known ones that have been around for a while.
- 28:09There's PyParsing and there's PLY.
- 28:11So David Beasley's Python Lex Yak.
- 28:14Yeah, PLY is fantastic.
- 28:16And anything that David Beasley does is fantastic.
- 28:19You should immediately pause the podcast and go watch all of his talks.
- 28:24PLY came out of when he was teaching a course on building your own little Pascal interpreter, I believe.
- 28:31PLY has the advantage of being tripped over by hundreds and hundreds of students.
- 28:36And they've hit every little corner case and made every possible mistake.
- 28:39And so the error reporting is top notch.
- 28:42And really, I would seriously recommend taking a look at PLY if the complexity of what you're parsing is amenable to it.
- 28:50Now, the limit of PLY and why I couldn't use it for the MediaWiki stuff is that it implements what we call LR1 parsing, which you can look up the formalisms.
- 29:00And I probably forget most of them.
- 29:01But this is something we did.
- 29:02I think most languages that are currently in production probably use something along the lines of LR1 just because it's very, very memory efficient and CPU efficient as well.
- 29:13So it was a thing that we implemented when we had tiny little computers.
- 29:15But where you run into problems is that LR1, that one means we can only look ahead one token to decide what kind of thing we're recognizing.
- 29:27And in the case of MediaWiki, that wasn't actually enough.
- 29:31For example, I believe it was internal links that begin with two brackets, bracket, bracket.
- 29:37So it's not every time that bracket, bracket means an internal link.
- 29:42It has to be followed by, oh, I'm going to get this wrong, but something along the lines of maybe a URL or page name, and then maybe a vertical bar, and then maybe a page title.
- 29:56And so you might have to look ahead two or three tokens to see if your internal link is going to work out.
- 30:02And if it doesn't, that bracket, bracket is just part of plain text and should be emitted verbatim.
- 30:07And so we couldn't use any LR1 parser, and I put that on my shopping list and ruled out a whole lot of libraries because of it.
- 30:14Right.
- 30:14It just needs to keep more of it in its head, in the algorithm, all at once, right?
- 30:19Pretty much, yeah.
- 30:20All right.
- 30:20So what's the story with py parsing?
- 30:22So py parsing is what I consider or was the canonical, I reached for it first, Python parsing library before I wrote my own, of course, because I'm in that bad habit.
- 30:32And py parsing is, you know, fairly Pythonic.
- 30:35It mashes all the grammar definition stuff into Python objects.
- 30:42So you literally say in a piece of Python, bold toggle equals literal parentheses, and then you construct an object, you say, quote, quote, quote, and say, okay, well, quote, quote, quote, is the thing that turns on bold in media wiki syntax.
- 30:57And then on that object, you call methods like set name bold toggle, so that when you have this tree, you can actually tell that this thing was a bold toggle as you're walking the tree.
- 31:07And kind of on you go.
- 31:09Now, the disadvantage of this is it's kind of hard to read.
- 31:14It's kind of wordy because, after all, we had to make this a valid Python.
- 31:18And you can't do certain things like make forward references.
- 31:22And oftentimes there are cyclical references in a non-trivial grammar.
- 31:26In the case of py parsing, they had to put a little hack around that and say, you know, bold toggle equals forward, which is sort of a promise that I'm going to declare something later.
- 31:37And then later on, you kind of jam that on.
- 31:40For people who haven't seen the syntax of py parsing, it's kind of like formalized Python that acts as regular expressions.
- 31:49So you'll see like Python objects, but they're clearly coming from sort of regular expression land like groups and whatnot, right?
- 31:58Well, I mean, groups is a valid word to use when you're talking about parsing.
- 32:02After all, we're talking about trees here, and a tree is nothing more than a nested list.
- 32:06And so every sub list you can think of as a group.
- 32:09So that's what py parsing is doing with the groups.
- 32:11Yeah, okay.
- 32:12And py parsing is of, I think, equal power with parsimonious.
- 32:17They're both able to describe all the context-free grammars and probably a subset of context-sensitive ones.
- 32:25And parsimonious is your library that you wrote, right?
- 32:28Yes, it's my mad scientist experiment.
- 32:30Though its version number starts with zero point, I have it in production all over the place.
- 32:35There are lots of people using it, so.
- 32:36Nice.
- 32:36Do you have some examples for what it's being used for?
- 32:39Yeah, well, I'm using it in DXR to parse our little query language.
- 32:42What awesome people are using it for?
- 32:44You know, they don't report back to me, but it gets a lot of downloads.
- 32:47Yeah, excellent.
- 32:48So it's out there somewhere.
- 32:49Excellent.
- 32:49So to me, it seems like parsimonious, it's a little simpler to define the grammar.
- 32:54Is that right?
- 32:55That was really my goal, both to make it simpler, to make it run fast, and to make it optimizable.
- 33:01One of the goals you said was frugal RAM use, which I thought was just a great way to phrase it.
- 33:08Yeah, and I haven't done a lot of RAM profiling, so I'm not ready to make any claims about that just yet.
- 33:13But the formalism underneath parsimonious, which is parsing expression grammars, which come out of a 2004 paper by Brian Ford, meet that goal just fine.
- 33:22I think RAM use is something along the lines of order n to the third, but n is the grammar size, so it's actually not that big an n.
- 33:31And as a result of blowing that RAM, it's caches for each individual little production, each individual little context-free equals.
- 33:40You get linear parse time.
- 33:42Yeah, which is great.
- 33:43Yeah, that's really, really nice.
- 33:44So the reason people care about RAM is, I mean, if you're running this over some text and you're just going to dump it out and produce a text version, that's fine.
- 33:54But if you're wanting to keep that in memory and say like a web server and continuously serve requests from it or something, then all of a sudden you care way more about RAM, right?
- 34:04Well, just imagine serving up a bunch of media wiki pages and you've got to be parsing 100 of these at a time on a web server.
- 34:10You know, RAM is not free.
- 34:12No, it's definitely not free, especially if you've got a lot of traffic.
- 34:15So one of the algorithms involved in here is you said that it uses something called the PackRat algorithm, which sounds fun.
- 34:23What's that?
- 34:25Yeah, I think Ryan Ford came up with that too.
- 34:26It's really simple.
- 34:28It's what you would come up with yourself if you're implementing one of these.
- 34:31These PEG parsers, PEG parsers, they're really just recursive descent parsers.
- 34:36And as you descend, you might find out, hey, now that I've looked ahead to tokens and I find out this internal link isn't going to work out for me, I need to rewind a little.
- 34:45Let me take a couple steps back up the stack and let me try parsing it as plain text, for example, or maybe as an external link, for example.
- 34:52And in the course of that, you may need to use a partial parse from a previous stack frame.
- 34:58And rather than redoing that work, it makes sense oftentimes to cache the results of each partial parse.
- 35:04And that's all the PackRat does.
- 35:06Just keeps all these intermediate results around.
- 35:08I see.
- 35:09Basically to allow you to look ahead an arbitrary number of tokens and then adjust.
- 35:14Without paying a penalty of redoing work.
- 35:16Exactly.
- 35:16Right.
- 35:17Yeah.
- 35:17Yeah.
- 35:17Very cool.
- 35:18Well, one of the things I was mostly trying to do with parsimonious, one of the things that really the thing that differentiates it so much, was that its grammars look a lot like what you'd find if you looked up the definition of the grammar in a book or in the documentation.
- 35:30They're just big blobs of multi-line text in the Python quote, quote, quote, quote way.
- 35:35And so it's able to do forward references because it's not bound to the idea of undefined symbols in an outer programming language.
- 35:42We're able to do compile time optimizations on it really without limit because we haven't lost anything in its transformation down to a bunch of Python objects prematurely.
- 35:54And it's also very easy to read as a result.
- 35:56And you also keep the representation part as a separate phase so you can render to multiple formats, which is cool.
- 36:04Yes, exactly.
- 36:05A lot of these Python, not Python rather, but a lot of these parsing kits tend to inter-twingle output rendering with parsing.
- 36:12And that way leads to pain in my experience.
- 36:17Certainly rigidity.
- 36:19Interesting.
- 36:20It sounds like your parsimonious project is really cool.
- 36:24And it's on GitHub.
- 36:24People can check it out, right?
- 36:26Please.
- 36:26Send feedback.
- 36:27Play around with it.
- 36:28Send patches.
- 36:29Okay, cool.
- 36:29Yeah, one of the things that made me a little bit sad about PyParsing is it's on SourceForge, which I don't know.
- 36:35Wow, still?
- 36:36Yeah, when I see things on SourceForge, it kind of makes me feel like, oh, I'm not really sure that thing's actually still going.
- 36:42Yeah, right on the homepage it says, download now from SourceForge.
- 36:45It's like, oh.
- 36:46Oh.
- 36:46Oh.
- 36:47Oh.
- 36:47Okay, that's unfortunate.
- 36:49It's still fine code.
- 36:50I mean.
- 36:51Yeah, of course.
- 36:52It is a single 3,000 line file.
- 36:54But, you know, old doesn't mean bad.
- 36:58It means proven.
- 36:59Yeah, absolutely.
- 37:00Absolutely.
- 37:00So that was a really cool talk on parsing horrible things you gave.
- 37:04Do you have some other favorites?
- 37:04Oh, let's see.
- 37:05What else have I done?
- 37:06I have a talk called Poetic APIs, where I kind of will expand on the idea that, you know, these grammars, they should be really easy to read.
- 37:15In fact, all programs should be easy to read.
- 37:17In fact, here are seven, you know, kind of checklist-y things you can bang against what you're writing to make sure that you set a good language for the users of your API.
- 37:27Oh, interesting.
- 37:27Yeah.
- 37:28What we're doing when we're programming is always creating language.
- 37:31Every time we name a function, name a variable, create semantics of an object, we're kind of creating the mental model in which everybody who interacts with that code in the future has to play.
- 37:44So if we do that irresponsibly, we can really make people think terrible, stupid thoughts that make their jobs hard.
- 37:50But if we give them really good symbols that correspond well to reality and are easily composable and flexible, like the requests package is a great example.
- 38:00Like, hey, you know what?
- 38:01We could just totally represent HTTP requests instead of making everyone think about raw sockets all the time, like URL lib.
- 38:07Then people can have their efforts magnified.
- 38:09Yeah, it really does define the way that you think about a problem, the APIs and whatnot you have to work with, and the language itself, right?
- 38:17And so I think Python itself is something, an example of, like, why that's important, right?
- 38:22Well, yeah, I mean, so Python is a fairly close match to what we tend to write as pseudocode.
- 38:29Right, and the reason we write pseudocode is it's easy to understand and communicate, so.
- 38:33Exactly.
- 38:34I was just reading the topographical sort algorithms on Wikipedia, and you know what?
- 38:38If you put some colons in there and take out the eaches, it's about valid Python.
- 38:42That's awesome.
- 38:43Yeah, I've heard that before, that people have copied algorithms out of Wikipedia, more or less, just straight up.
- 38:48Turn that into Python, and it works beautifully.
- 38:50That's great.
- 38:51Which is also interesting verification of Wikipedia content.
- 38:54Yes.
- 38:55This portion of Talk Python To Me is brought to you by Hired.
- 39:10Hired is the platform for top Python developer jobs.
- 39:13Create your profile and instantly get access to 3,500 companies who will work to compete with you.
- 39:18Take it from one of Hired's users who recently got a job and said,
- 39:21I had my first offer on Thursday after going live on Monday, and I ended up getting eight offers in total.
- 39:26I've worked with recruiters in the past, but they've always been pretty hit and miss.
- 39:29I tried LinkedIn, but I found Hired to be the best.
- 39:32I really like knowing the salary up front.
- 39:34Privacy was also a huge seller for me.
- 39:37Sounds awesome, doesn't it?
- 39:38Well, wait until you hear about the sign-in bonus.
- 39:41Everyone who accepts a job from Hired gets $1,000 signing bonus.
- 39:44And as Talk Python listeners, it gets way sweeter.
- 39:46Use the link Hired.com slash Talk Python To Me, and Hired will double the signing bonus to $2,000.
- 39:52Opportunity's knocking.
- 39:53Visit Hired.com slash Talk Python To Me and answer the door.
- 40:04There's another one that you talked about called the Code Review Review.
- 40:07What's the story of that?
- 40:08Yeah, this is a newer talk.
- 40:09So something we're trying to do at Mozilla is make sure we don't drive people away by being jerks,
- 40:16doing code review or otherwise having kind of unwelcoming culture.
- 40:20Mozilla is historically and today largely driven by volunteer contributions.
- 40:25I mean, even the guy who owns our security sockets layer or something,
- 40:32or the NSS, whatever that is, like the module owner for this, the one who has the final say,
- 40:36he doesn't get paid by Mozilla.
- 40:37He does something else, and he just takes it on this responsibility out of his own free time.
- 40:42And so it's really important for Mozilla to keep that rolling, you know,
- 40:46welcome people into the community, take in contributions,
- 40:48help people level up to become better programmers and more familiar with the project.
- 40:52And so the Code Review Review is a piece of our onboarding right now
- 40:56that I'm turning into a more generically applicable talk where we talk about,
- 41:00well, you know, how do we create that kind of welcoming atmosphere?
- 41:02How do we do a proper review so that good programs come out?
- 41:07And how do we do a review such that better programmers come out of it?
- 41:11Yeah, that's really important that people, when they come to these new projects
- 41:15or when they stick around, that they feel like it's a delightful experience
- 41:18because they're doing it of their own free time and energy, right?
- 41:22Yeah, for sure.
- 41:24You definitely don't want it to be like slugging through a hard code.
- 41:27I mean, I think an example of the opposite comes to mind is the old Python packaging,
- 41:33PyPI web code.
- 41:35I talked to Donald Stuffed on episode 64, and he was like,
- 41:40a lot of people want to come along and help maintain and evolve this,
- 41:44but it's like two files in this hugely complicated old custom web framework that they built for it.
- 41:52It's just people look at it, you know, actually, thanks, but no thanks.
- 41:56And finally, they're rewriting it at pypi.org, and it's in Pyramid and Bootstrap, and it's lovely.
- 42:05But for a long time, I think it turned people away from pushing that project forward,
- 42:09and you could tell that it kind of, it was just getting maintained, which is good,
- 42:13but it's also evidence of this anti-approachability, I guess.
- 42:17Yeah, it's kind of funny how all those old projects tend to be like two enormous files.
- 42:22All I can think of is folders must have been expensive 20 years ago.
- 42:24Yes, exactly.
- 42:25Really expensive.
- 42:26All right, so what else?
- 42:28We've got a few moments to talk about a few other things,
- 42:31and I know you've got a lot of interesting pieces out there.
- 42:34What else is going on?
- 42:35You're doing something with pip, right?
- 42:36Oh, pip, yes.
- 42:37So we deploy a lot of Python at Mozilla,
- 42:40and we used to check everything into a vendor library,
- 42:44you know, just to be sure no one had slipped anything under the radar,
- 42:47anything malicious like that.
- 42:48And vendor libraries are a pain to maintain.
- 42:50You know, you have to update the versions of things,
- 42:52and that creates enormous diffs in your version control,
- 42:55and then checkouts take forever, and your checkouts are huge.
- 42:57And so we, for a while, ran an internal PIPI mirror.
- 43:02A lot of people run their own little index server,
- 43:04and you kind of keep track of who's allowed to upload what to the server,
- 43:08and then who did it last,
- 43:09and what versions are going to work with your own projects,
- 43:13and you have to keep an access control list and an audit trail.
- 43:15And that was a pain, and it slowed things down.
- 43:18And then I thought, well, you know,
- 43:20we were actually having a beer and tell.
- 43:22We have these little sessions where we have a beverage of our choice
- 43:25and talk about something that we've been playing around with as a side project.
- 43:28And I needed something to talk about one day,
- 43:31and I thought, well,
- 43:32why not just hash the results of what you download from PIPI
- 43:37and make sure they match some local hash that you've pre-vetted,
- 43:43and then go ahead and install it?
- 43:44And so I put this thing together as this little tool called PEEP for prudently examine every package.
- 43:50And we ended up moving the whole production lifecycle over to that for a number of years, year or two.
- 43:57And then I thought, well, okay, this is proven out.
- 43:59And PEEP called deep into pip's internal APIs, and so it would break all the time.
- 44:04And it was a pain to maintain.
- 44:06I thought, you know what?
- 44:06I'm going to lift this up into pip, see if I can get people interested.
- 44:10And long story short, I did.
- 44:12People were interested, and it's in pip 8 and above.
- 44:15So if you're out there deploying Python and running your own index server
- 44:21or keeping up to date with a vendor library,
- 44:24hey, consider just putting a bunch of SHA-256 hashes into your requirements file
- 44:29with a funny little syntax and running pip 8 over it.
- 44:32And it'll vet these things for you.
- 44:34I mean, it won't vet them for you.
- 44:35You have to make sure that there's nothing malicious in a given version of a package,
- 44:38but it'll make sure that what you got that first time is the same thing you got.
- 44:42Yeah, once vetted, it'll verify it can't change.
- 44:44So what do you do?
- 44:45You can't just say, I depend upon SQLAlchemy.
- 44:48You've got to say, I depend upon SQLAlchemy 1.0.whatever, and here's its SHA.
- 44:54Dash, dash, hash equals whatever it is.
- 44:57Right, because obviously if the version changes,
- 44:59you'd imagine the code would change and the package would change.
- 45:01Absolutely.
- 45:01I see.
- 45:02And I try to keep the handholding in there
- 45:06so that if you forget to pin the version but provide a hash,
- 45:09it'll say, you know what?
- 45:10You should really pin the version because you're going to have an unpleasant surprise down the line.
- 45:14This is a really stable product.
- 45:16You're going to find out that this is not the same.
- 45:19Awesome.
- 45:20And you mentioned Turtles before.
- 45:21What's Turtles?
- 45:22Turtles is a real mad scientist project.
- 45:25So I used to do a lot of Zope and Plone consulting back in the day,
- 45:30and I watched a lot of really smart people from all different walks of life.
- 45:36You know, it was in higher ed, so there were professors, and there were very good writers,
- 45:40and there were sys-ops, and there were chemists,
- 45:42and they'd come in, and we'd have to teach them,
- 45:44okay, how do I build a website,
- 45:46or how do I use this content management system that has Python underlying it?
- 45:50And they'd have to learn HTML, and CSS, and JavaScript, and Python,
- 45:56and then ZCML as a control language,
- 45:58and DTML for dynamic CSS back in the day,
- 46:02and all these crazy different languages.
- 46:03And it was ridiculous,
- 46:04and they would get discouraged and go away, a lot of them,
- 46:08or at least not work to the potential that I thought we could provide them.
- 46:11And so Turtles kind of had its genesis there.
- 46:14I thought, you know, if only we had a single language that we could use end-to-end,
- 46:19and we didn't need to constantly reinvent, say, for loops,
- 46:24or variables that allow us to not repeat ourselves,
- 46:28and have a different way to do variables in Python,
- 46:29and a different way in CSS, and another way in JavaScript,
- 46:32wouldn't things be easier to learn, and easier to remember,
- 46:35and heck, easier to read?
- 46:37And wouldn't we have all of these synergies?
- 46:40Turtles is one of those.
- 46:48Turtles is a single-language system, or will be, I hope, for web development.
- 46:53Right now, it is just a context-sensitive parser that does run,
- 46:58but everything else is still up in the air.
- 47:01Interesting.
- 47:02So basically, instead of teaching people these three or four languages,
- 47:06when they come, plus the frameworks, you're like, look, learn this one thing,
- 47:09and you'll have a website, a full-on website.
- 47:12That is the idea, to teach them, you know, an hour or two's worth of stuff,
- 47:16and then have them be able to make real progress without an internet connection.
- 47:21You know, make this thing explorable, like the old small talk environments used to be,
- 47:25where you can drill into an example and take it apart and rip out pieces that you want to use,
- 47:30where you can make changes to a live system and see what happens.
- 47:34I mean, that's really how I learned programming, by mimicry, which we don't really do anymore.
- 47:39You know, I had to type this stuff out of magazines, make mistakes,
- 47:42see what the effects of the mistakes were, fix the mistakes,
- 47:45and then screw around and make my own new mistakes and see what effects they had.
- 47:50I think that's how we learn human language, and I think it's a powerful way to learn programming.
- 47:53It is a powerful way, but we've definitely moved beyond that in lots of areas.
- 47:57I mean, I try to, I think of getting started with, like, Node.js and, like, the crazy packaging and requirements and all that,
- 48:04and it's like, I thought that was a simple thing to get started with, you know?
- 48:07But I feel like I've done a better job of keeping it simple.
- 48:11But still, how do I know where a package comes from?
- 48:14If I type import requests, why doesn't that run, right?
- 48:17Like, when you're new, all these challenges that we are just like, yeah, whatever, just pip install or whatever,
- 48:22I just, you forgot that step.
- 48:23These are all levels of friction.
- 48:25Yeah, that's one of the things that I'm trying to solve in Turtles by making the answer always the same.
- 48:30You ask, where does this come from?
- 48:32Or where do I put this?
- 48:33And the answer is always in Turtles, it goes on a page.
- 48:37Your config goes on a page.
- 48:39Your program goes on a page.
- 48:41Everything goes on a page.
- 48:43The thing that we've lost in the web, because the web is a state-free kind of environment,
- 48:48is that the default behavior is for everything to go poof.
- 48:51You put something in a forum, you leave the page, poof, it's gone.
- 48:55Unless you're, you know, using a nice browser like Firefox where you can say, hey, reopen that tab,
- 48:59and then your content comes back.
- 49:01But as a developer, you have the same problem, right?
- 49:03You end up writing these template languages, and you end up having to take state and shuttle it aside
- 49:07into some other process, into a relational database or a document store or something,
- 49:12and then reconstitute, rehydrate these pages all the time out of these databases,
- 49:17where the representation may not look anything like the structure you're actually trying to pull out.
- 49:23And so the idea with turtles is put everything on pages and have a single representation for everything,
- 49:28which I think is going to be trees.
- 49:30Because as we said with the parsing stuff, trees are a very good choice for universal representation of things.
- 49:38You can do a lot with trees.
- 49:39It definitely sounds like an interesting project.
- 49:41So there's nothing quite yet that we can go play with, but you're working on it, huh?
- 49:44Nothing but 100K of design notes and parser up on GitHub.
- 49:48But yeah, not quite ready yet.
- 49:49All right, cool.
- 49:50I'll keep us posted on that.
- 49:51That's great.
- 49:52All right, so another thing that you said you're into these days is GTD or getting things done, right?
- 49:57Oh, my gosh.
- 49:58Changed my life.
- 49:58So as a repeat offender of Python library creation, I have the open source guilt.
- 50:06I put this thing out there, and people are like, oh, well, it's broken this way, and it's broken this way,
- 50:11and I wish it did this, and here's a patch, and why don't you review my patch,
- 50:14and shouldn't you be doing this instead of watching Netflix and spending time with your family?
- 50:17I'm like, well, I guess.
- 50:18And the guilt builds and builds and builds, and you're just kind of,
- 50:22you know, you're just kind of shaking all the time, and you can't relax.
- 50:25So GTD, I got this book at work seven years ago.
- 50:31Somebody gave me a copy and it sat on the shelf for seven years, and I picked it up,
- 50:34and it has all these little helpful practices for getting rid of that guilt
- 50:37and making sure you're always working on the most important thing at any one given time.
- 50:42And you know what?
- 50:43It's really changed my life.
- 50:44I no longer have the guilt to such a degree.
- 50:46Hardly at all, really.
- 50:48My response time has gone way down.
- 50:50My email box has been at zero.
- 50:51I mean, my work one and my home one were 5,000 before.
- 50:55Now they've been zero for months.
- 50:57And it's been easy.
- 50:58It's a crazy thing.
- 51:00That sounds delightful.
- 51:01Yeah.
- 51:02Yeah.
- 51:02I've read that book, and I've lived the GTD lifestyle.
- 51:06And I found it didn't quite work for me, but I gained a huge value from doing it.
- 51:13And so if you can find a few techniques to help tame the world, whether it's so you have
- 51:20better response time on your open source project, or you're not stressed all the time, or you
- 51:23can go home and see the family and not have the weight of 5,000 unread emails on you, these
- 51:31are all good.
- 51:31The biggest thing that helps me these days is Google Inbox with its ability to snooze items
- 51:38for two weeks until that item comes back right when I'm supposed to deal with it and things
- 51:42like that, that's actually been sort of where I've evolved to.
- 51:45But GTD is great.
- 51:47Yeah.
- 51:47For real.
- 51:48And nobody, you know, you say you don't use GTD per se because it didn't work out for you.
- 51:53Well, nobody uses vanilla GTD.
- 51:55It's, you know, it's made to be customized.
- 51:57It's a grab bag of tricks.
- 51:58And some of them are, you know, more important than others.
- 52:00Some of them are, you know, kind of vital, and some of them are optional.
- 52:03Yeah, absolutely.
- 52:03And you ran into something with that inbox that really rings true to me.
- 52:07I had been trying for years to use my email inbox as a sort of quasi-touching.
- 52:12To-do list.
- 52:13I'll leave this in my box because I'm going to need it in three days.
- 52:17And so for some reason I thought it's expensive to do a find.
- 52:20I don't know why I thought that, but that's what I thought apparently.
- 52:23Or, you know, oh, I need to respond to this mail, so it's going to stay in there.
- 52:27And it ended up just being this mixture of chronologically sorted things, some of which were reference material, some of which were things to do, some of which I couldn't do for a certain period, like you said, and needed to be snoozed for two weeks.
- 52:38And yet the only way it would present them to me is as this linear kind of last-touched first list of things.
- 52:46It's not a useful presentation.
- 52:47And I have been unable to make any email client really bend to my will as a to-do list.
- 52:54And so the reason my boxes are empty these days is any time there's an actionable email item that takes me more than two minutes to do, because otherwise I would do it immediately as part of GTD, it goes into my to-do system.
- 53:05And it pops up, like you say, when you're able to take action on it.
- 53:09It's really a wonderful thing.
- 53:11I do agree with that.
- 53:12So I would be remiss not asking which to-do system you use for this.
- 53:16So I went shopping.
- 53:17I wanted something that – so I'm kind of weird.
- 53:19I wanted something that was expressly not cross-platform, because I think that the platform-specific stuff usually ends up with a better UI, and I'm kind of a UI enthusiast.
- 53:28So I looked at OmniFocus.
- 53:29I love all of Omni's stuff.
- 53:31I love OmniGraffle and OmniOutliner.
- 53:33I read all my talks on OmniOutliner.
- 53:34And I really wanted to like OmniFocus.
- 53:36But there were a couple things that it was just grating against me, and it wouldn't do what I wanted.
- 53:41I couldn't reorder tasks except within projects.
- 53:44And I kind of like to plan my day out.
- 53:45And so I ended up with something called Things by a little German company called Cultured Code.
- 53:51And it's a Mac and iPhone-only gadget.
- 53:54It uses their own little cloud sync service.
- 53:56And the UI has been thought out in great detail.
- 54:00Development goes glacially slowly.
- 54:03That's the downside.
- 54:05These people seem very, very intent on getting things exactly right and not releasing until then.
- 54:09So that's the downside.
- 54:10But Things is great.
- 54:11Things lets you schedule things out ahead of time and not bother you until then.
- 54:15It lets you express due dates like, well, this drop dead has to happen now.
- 54:19And it does all the D2D-style contexts.
- 54:22Let me know about this when I'm at home or at work or in the car or what have you.
- 54:26It's nothing particularly, you know, whizzy from a technical point of view.
- 54:31But it has those kind of three core features of contexts and due dates and hide until that any large-scale to-do system needs.
- 54:40Oh, yeah.
- 54:41It looks really, really cool.
- 54:42All right.
- 54:42Well, thanks for sharing your research results there.
- 54:44That's cool.
- 54:45Great.
- 54:46Okay.
- 54:46So it looks like we're just about out of time.
- 54:49We've covered all the horrible things.
- 54:50Now let's talk about some cool things.
- 54:52How about your favorite PyPI package?
- 54:54Well, I mean, there's a lot of good ones out there.
- 54:57I enjoy Flask.
- 54:58I've used that to power DXR.
- 55:00It's a nice little lightweight web framework by Armin Roniker.
- 55:05Yeah.
- 55:05I can't remember exactly who it is.
- 55:06Yeah.
- 55:06I hit him on one of the early shows.
- 55:08Yeah.
- 55:08All of Armin's stuff is fantastic.
- 55:09It is.
- 55:10Likewise, Click is a fantastic one by Armin.
- 55:12It's, I think he kind of, did he pull it out of Flask?
- 55:16No, he's pulling it into Flask, in fact.
- 55:18Click is a kit for making command line tools.
- 55:22And I pulled it into DXR as well because it makes it so easy to do nested subcommands.
- 55:27Like if you use homebrew or something, homebrew install, brew this, brew that.
- 55:31It helps you brew up commands like that.
- 55:34And like all of Armin's stuff, it's sort of a decorator soup that I like very much.
- 55:39Absolutely.
- 55:39And then one of my own things that I always pull off the shelf when I start a new project
- 55:44is more iter tools.
- 55:46And it is, as the name says, more iter tools.
- 55:49The ones that got left behind.
- 55:50Collations and such that come in handy in almost every project.
- 55:54Yeah.
- 55:54Okay.
- 55:55Excellent.
- 55:55I'll be sure to link to all of those.
- 55:57That's great.
- 55:57And how about the editor?
- 55:59Favorite editor?
- 56:00Are you going to write some Python code?
- 56:01What do you pull up?
- 56:01I pull up a little Mac app called BBEdit.
- 56:04It's been around for, must be 40 years or something.
- 56:07Yeah.
- 56:08They're on BBEdit 11.
- 56:09I like their little subtitle.
- 56:12I don't know.
- 56:12It doesn't suck.
- 56:14All rights reserved.
- 56:14Yeah.
- 56:15Bare-bones software.
- 56:15It doesn't suck.
- 56:16And they typically make software that looks like nothing.
- 56:18You pull it up and their mailer looks like a big empty window of white.
- 56:22And their text editor looks like a big empty window full of white.
- 56:25Not a lot of toolbars.
- 56:26Not a lot of fluff.
- 56:27But under the hood, they do a really nice job.
- 56:31The text editor uses what must be ropes because I can edit very large, you know, multi-tens
- 56:37of megabyte files without a lot of lag.
- 56:39It's incredibly stable.
- 56:41It just doesn't lose data.
- 56:42On the off chance that it maybe crashes every couple of weeks, its magical little implicit
- 56:50auto-save thing will bring up your windows in exactly the state that they were.
- 56:53Even your untitled documents, it won't save and plow over your stuff.
- 56:57It'll save it in its own little buffer and just make sure nothing is unduly lost.
- 57:00Yeah.
- 57:01That sounds really cool.
- 57:02All right.
- 57:02Awesome.
- 57:02So check that out, people.
- 57:04That's cool.
- 57:04And final call to action.
- 57:06Well, if you're parsing in Python, give parsimonies a try and send feedback and complaints and
- 57:12patches my way.
- 57:12Yeah, definitely.
- 57:13It's on GitHub.
- 57:14I'll put the links to it in the show notes so people can find it there.
- 57:17Thank you.
- 57:17And second, be safe out there.
- 57:19If you're running a web server, get a certificate.
- 57:22Use Let's Encrypt or something else.
- 57:24And if you're deploying Python, again, be safe.
- 57:26Use pip hashing.
- 57:28I really appreciate this look inside of the whole parsing world and how we can move beyond
- 57:33regular expressions to do something way cooler.
- 57:36So thanks for your project and your talk and being on the show.
- 57:38It was a pleasure to speak with you, Michael.
- 57:40Yeah.
- 57:40Bye, Eric.
- 57:41This has been another episode of Talk Python To Me.
- 57:45Today's guest has been Eric Rose, and this episode has been sponsored by GoCD and Hired.
- 57:51Thank you both for supporting the show.
- 57:53GoCD is the on-premise, open-source, continuous delivery server.
- 57:58Want to improve your deployment workflow but keep your code and builds in-house?
- 58:02Check out GoCD at talkpython.fm/gocd and take control over your process.
- 58:08Hired wants to help you find your next big thing.
- 58:11Visit hired.com slash talkpythontome to get five or more offers with salary and equity presented
- 58:16right up front and a special listener signing bonus of $2,000.
- 58:20Are you or a colleague trying to learn Python?
- 58:23Have you tried books and videos that just left you bored by covering topics point by point?
- 58:28Well, check out my online course, Python Jumpstart, by building 10 apps at talkpython.fm/course
- 58:34to experience a more engaging way to learn Python.
- 58:37And if you're looking for something a little more advanced, try my WritePythonic code course at talkpython.fm/pythonic.
- 58:43Be sure to subscribe to the show.
- 58:46Open your favorite podcatcher and search for Python.
- 58:48We should be right at the top.
- 58:49You can also find the iTunes feed at /itunes, Google Play feed at /play, and direct RSS feed at /rss on talkpython.fm.
- 58:59Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
- 59:04Corey just recently started selling his tracks on iTunes, so I recommend you check it out at talkpython.fm/music.
- 59:10You can browse his tracks he has for sale on iTunes and listen to the full-length version of the theme song.
- 59:16This is your host, Michael Kennedy.
- 59:18Thanks so much for listening.
- 59:19I really appreciate it.
- 59:20Smix, let's get out of here.
- 59:22I'll see you next time.
- 59:44Don't believe.
- 59:45Thank you.