Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book


Transcript #4: Python 3 is just fine for beginners thank you, q is awesome for debugging, and more

Return to episode page view on github
Recorded on Monday, Nov 28, 2016.

00:00 This is Python Bytes. Python headlines and news delivered directly to your earbuds.

00:04 Episode 4 recorded November 28th, 2016. This episode is brought to you by Rollbar.

00:10 They help you take the pain out of errors. Hey, Brian, how's it going?

00:13 It's going really good.

00:14 Yeah, we had a Thanksgiving break, which meant kind of a shakeup in a lot of the news and the

00:21 topics and whatnot. But that does not mean it was not interesting or controversial.

00:25 It was a very controversial week last week.

00:28 In fact, it might be one of the most Pythonically controversial Thanksgivings ever.

00:32 If I had to guess, I don't know.

00:33 Trying to intersect those two things.

00:35 Yeah, so let's jump right into that as the first item that we're going to cover.

00:40 And we'll sort of lay this out for you.

00:42 So you may have heard that a guy named Zed Shah has written a very famous book teaching

00:48 people to write programming, basically teaching people to become Python developers.

00:53 He wrote this article called The Case Against Python 3 or something to this effect.

00:59 And it turned out this article, which is a huge, long, in-depth, highly charged criticism of

01:08 Python 3.

01:09 It's like 15 pages long.

01:11 And it basically, let me just read you a short excerpt straight from the article.

01:15 And remember, this is coming from the person who is the author of the primary book for learning

01:21 Python.

01:22 It's referring to Python 3.

01:24 It's as simple as that.

01:25 If you learn Python 2, you can still work with a legacy Python 2 code in existence until Python

01:31 dies, or hopefully you move on.

01:34 But if you learn Python 3, your future is very uncertain.

01:37 You could really be learning a dead language and end up having to learn Python 2 anyway.

01:41 Quote Zed Shah.

01:42 Now, if this was just some guy on the internet, like who cares, right?

01:46 But the fact that this guy is our greeting person, this guy greets the new developers and welcomes

01:52 them to Python and says, gee, Python is great.

01:54 And you can even use it until it dies or hopefully you move on.

01:57 Like this is actually a really big problem.

02:00 How did this whole experience strike you?

02:02 It was hard to have coherent words come out when I was trying to express how angry I was

02:08 about this article.

02:09 I'm just shocked by it, actually.

02:11 Yeah, I think shock and awe is really quite an appropriate summation of a lot of people's

02:17 feelings.

02:17 I got people writing me on Twitter going, what is this?

02:21 Oh my God, this doesn't even like, like they couldn't even like cognitively put it together

02:25 with Zed Shah being the author of that book.

02:28 So let me like, like I said, it's a 15 page article.

02:31 Let me give you a few of the key points.

02:33 In fact, I was able to condense it down pretty tightly, I believe.

02:36 And everyone out there listening can decide sort of what this means to them.

02:41 So there's a couple of key points.

02:43 First of all, Zed says it's learning Python 3 or Python 3's existence is not in your best

02:48 interest.

02:49 And so this is a quote.

02:51 The Python project's effort to convince you to start with Python 3 are not in your interest,

02:57 but rather are in the best interest of the Python project.

03:00 That's a case or point one against Python 3.

03:04 Number two is you should be able to run Python 2 in the same process as Python 3.

03:11 Like, so they should be able to coexist in the same process as an execution engine.

03:16 And the fact that no one has written a Python 3 interpreter that does this shows that Python

03:22 3 is not Turing complete.

03:24 It's one of the reasons that newcomers to the language can't use Python 3.

03:28 I don't really understand that, but that was one of the major arguments that Turing completeness,

03:32 because Python 3 has not been made to host Python 2, which I think is actually not even

03:38 correct, but also not making a lot of sense to me.

03:41 It also doesn't make sense that a newcomer would want to try to write a Python 2 interpreter

03:45 in Python 3.

03:46 It doesn't seem like a beginner task to me.

03:49 Yeah, absolutely.

03:49 And so I actually had an exchange with Zed on Twitter.

03:53 He was busy.

03:55 He was talking to many people, because a lot of people had the feeling that you and I did,

03:58 like, well, we'll get to that in the end.

04:01 But we had this feeling that made us want to reach out.

04:03 And so it really comes down, actually, to his, even though it took 15 pages in Turing completeness

04:08 and computer science and all sorts of stuff, the actual complaint is the way the strings

04:12 changed in Python 3 are hard.

04:15 And so here's a quote, again, from the article.

04:16 The strings in Python 3 are very difficult to use for beginners.

04:19 And in an attempt to make strings more, quote, international, unquote, they turn themselves

04:24 into difficult to use types with poor error messages.

04:28 And so that was straight from the article as well.

04:30 So in my final analysis, I would say this.

04:32 There's a huge uproar on Twitter and various other things like on Reddit.

04:37 I think you got like 500 upvotes across a couple of people who reposted this saying, basically,

04:41 look, I'm going to absolutely scare newcomers to Python away from Python 3.

04:48 And here's why.

04:49 You can't add the byte string hello to the Unicode string hello in Python 3.

04:55 That will crash.

04:55 There's too many string formatting choices.

04:57 And bytes aren't decoded to strings automatically.

05:00 You have to pick the encoding and explicitly do that.

05:03 Therefore, all newbies should avoid Python 3 like the plague.

05:06 It'll curse your career and cloud your judgment.

05:08 So that was Thanksgiving in the Python world, basically.

05:12 Yeah, that's just weird.

05:14 I really have a hard time imagining that a newcomer to Python would need byte strings

05:19 or byte arrays right away.

05:21 Just not sure about that.

05:23 Yeah, I mean, surely after a while, like if you were the person writing a network layer,

05:27 like if you're writing requests, you're writing flask, you're writing pyramid,

05:29 you got to deal with this stuff.

05:31 But beginners don't like do that the first day.

05:34 They just work with strings and they might get something from a framework

05:37 that's already done that decoding for you.

05:39 It's crazy.

05:39 Yeah, and I mean, I learned in Python 2 and the conversion to Python 3 was very painless.

05:45 I mean, the only thing, I mean, I remember, gosh, the only thing I was waiting for

05:50 was one of the libraries that I depended on.

05:52 The interactions with DLLs was a little different.

05:55 So some of the, because of the string things, but let's face it, Python 2 used basically C strings and they aren't normal, just arrays of characters.

06:05 And that's not good enough.

06:07 It's not real.

06:09 And it's actually, the argument's a lot contradictory to itself because the many formatting choices

06:15 for strings are because we've came up with lots of better ways to format strings and kept

06:19 the old ones for backwards compatibility, which is exactly what Zed wants us to do to keep backwards

06:25 compatibility.

06:26 And yet there was this, one of the things that caused the break between two and three and make them not backward

06:32 compatible is this decision about strings.

06:35 And I just, at first I disagreed with it, but I'm after working for with it for a while, I totally understand the choice and it makes sense.

06:42 Yeah.

06:42 I think, I don't know what the alternative is.

06:44 Sporadic runtime errors.

06:45 Great.

06:46 You know, I mean, come on.

06:48 So, and it's one thing to say strings in Python 3 suck.

06:52 Like that's a reasonable contention.

06:55 I don't make that myself, but you could.

06:56 But to then make that immediately to be the case that you should absolutely stay away from Python 3 and even Python 2 is kind of a bad choice for you,

07:06 but you can kind of stick with it for a while.

07:07 Like that is, one does not follow from the other.

07:10 So, I got worked up and I was going to write up something about this, but this guy, girl, I don't even know the gender, Eve, E-E-V-E-E,

07:17 wrote a fabulous point by point logical rebuttal of this and then sort of a personal comment as well.

07:24 And so, we're going to link to that, which has the original article's quotes as well as comments about it in our show notes.

07:30 Yeah.

07:30 And I'd like to just say for anybody that's actually freaked out about this at all, don't be freaked out.

07:36 It isn't a big deal.

07:37 And for history reasons or just a little background, Zed does like to jump up and down and make a lot of noise every once in a while.

07:44 Yeah.

07:45 Yeah.

07:45 He even said on Twitter that he was looking to move on from Python.

07:48 So, that's fine.

07:49 I mean, I totally respect that.

07:50 I've moved on from other technologies to Python, actually.

07:52 But don't, you know, poison the well on your way out the door as your last act, right?

07:57 Like that's...

07:57 Yeah.

07:58 So, personally, I'm not going to recommend Zed's book anymore just as a point of...

08:03 I just don't think this is the person that should be representing the first touch with people coming into Python.

08:09 So, everyone else can do whatever they like.

08:11 All right.

08:11 I agree.

08:12 Right on.

08:13 So, let's talk about something newer, something in Python 3, actually.

08:17 Okay.

08:17 Well, one of the things that has come up in Python 3 as our second article is the asyncio has changed quite a bit.

08:25 And in Python 3, it's sort of gone through several iterations.

08:29 And I'm not really an expert on it.

08:32 But there was a Reddit discussion talking about an article.

08:35 The article is actually from February.

08:37 But the Reddit discussion is about the asyncio for the working Python developer.

08:43 And actually, the article that we'll link to is, I think, a pretty okay tutorial on understanding some of the different terms.

08:52 Like, now I'm even going to blank on them.

08:55 But, like, futures and threads and tasks.

08:59 And I think it does a pretty good job.

09:02 There's a couple downsides.

09:03 It does use Python 3.4 syntax.

09:06 And the syntax has changed.

09:08 It still works in 3.5.

09:10 But there is a newer async await syntax in 3.5.

09:14 And...

09:16 Yeah.

09:16 And that makes it much more approachable, I think.

09:18 It makes the code change significantly less coming from a synchronous model to an asynchronous model.

09:24 Let the implementation and runtime deal with that for you.

09:27 Yeah.

09:27 But in that regard, I'd actually like this sort of...

09:32 So, this is one of the reasons why I included it.

09:34 I'd like somebody to take this type of an article and write it with the new async await keywords.

09:40 And it would also be great if they could come up with an example that didn't include just, like, sleep statements.

09:45 Yeah.

09:46 A real-world example would be great.

09:48 Yeah.

09:48 So, anyway.

09:50 That's my second article.

09:53 Yeah.

09:53 And if you're looking to get into async stuff in Python, check this one out.

09:57 It's cool.

09:57 We'll have another thing later in the show as well about async.

10:01 All right.

10:02 So, my second choice here was Piston, P-Y-S-T-O-N, which is an alternate implementation of Python as opposed to, say, CPython.

10:10 And this actually is maybe most notable because it's coming from Dropbox, where Guido Van Ralsam and crew work.

10:19 And Dropbox is one of the biggest sort of users of Python in the commercial space.

10:24 And so, it's really a center of the Python universe.

10:28 So, they're working on a JIT version, a just-in-time compiled version of Python that is different than CPython.

10:36 So, that's pretty cool.

10:37 This release is the .6 release.

10:39 The main goal was to reduce the overall memory footprint.

10:42 So, they actually – there's a couple of interesting comparisons.

10:45 It's 50% better than it was before.

10:48 And let me look at the graph.

10:50 Yes, in every single case, the memory usage is actually better in Piston now.

10:55 It wasn't before.

10:56 Now, it is compared to PyPy, P-Y-P-Y, which is the other major active JIT implementation for Python.

11:04 So, they also picked up some of the Python 3.6 features like order dict and so on.

11:08 Okay.

11:09 I guess I'm misunderstanding the graph.

11:12 It is – it's still larger memory footprint than CPython.

11:17 It is still more memory than CPython because I believe it's a reference counting garbage collector.

11:23 I don't know that for sure.

11:24 But it's – I think it's a GC-based language.

11:27 Okay.

11:27 Possibly, which generally means more memory usage.

11:30 Oh, okay.

11:30 Certainly, PyPy is GC, which means more memory usage.

11:34 So, it's interesting.

11:35 It's – I don't think it's really there yet.

11:37 I'm not totally sure.

11:38 They focused a lot on NumPy implementation and some of the scientific stuff.

11:43 But it's nice to know there are many implementations of Python.

11:46 And here's yet another.

11:47 Yeah, it would be cool.

11:48 And I think it'd be kind of neat if we could get somebody from the Piston project to maybe go on your show.

11:55 Yeah.

11:55 I would love to have them on Talk Python.

11:56 I actually talked to them a little bit when the project was announced like a year ago.

12:01 And they were like, maybe.

12:02 I don't believe anybody ever agreed to come on the show.

12:05 So, I might have to follow up with that.

12:07 You're right.

12:07 That would be cool.

12:07 I've had the Pidgin guys on, which is the Microsoft's version of that, which is actually really cool.

12:13 Some of the Python core developers are working on it, Brett Cannon and groups.

12:16 I had them on my show.

12:17 And that was a super interesting topic.

12:20 Yeah, it is interesting.

12:20 I'd be interested to hear some of the motivation because, I mean, Dropbox has thrown money at it.

12:25 There must be a reason around there.

12:27 It's not just they're curious.

12:30 No, there's something.

12:31 They actually are not using it in production yet, but maybe they're looking to.

12:35 We'll see.

12:35 Yeah.

12:36 Okay.

12:36 Before we get to the next one, I'd kind of like to tell you about our sponsor.

12:39 How cool is it that we have a sponsor already?

12:40 That's great, right?

12:41 Yeah.

12:42 I'm very grateful to these guys.

12:43 Yeah.

12:43 Rollbar is awesome.

12:44 So, I actually use Rollbar.

12:45 I use Rollbar before they sponsored the show.

12:47 So, let me just tell you about them.

12:48 So, on the Talk Python websites, those across three sites there, they handle almost 2 million dynamic

12:53 ACP requests a month and transfer upwards of 5 terabytes of data.

12:57 But I deploy to them several times a week.

13:00 I'm not even worried about pushing them out.

13:01 Because in addition to continuous integration, if something goes wrong, my Slack, my email,

13:06 my phone, everything will be blowing up with notifications from Rollbar saying, something

13:11 broke, click, quick, quick, check the server.

13:13 And you'll get detailed error reports whenever something's wrong.

13:16 If there is an error, you usually don't even have to debug it because all the info is right

13:20 there.

13:20 So, you Python Bytes listeners, you can have the same peace of mind.

13:24 Just visit rollbar.com slash pythonbytes, which is also in the show notes, and sign up

13:28 for the free tier.

13:28 So, thanks, Rollbar.

13:29 Thank you, Rollbar.

13:30 And also, while you're there, there's a really fun demo you can play with.

13:33 All right.

13:33 Let's talk about docs.

13:34 Okay.

13:35 I just heard about this last week.

13:37 I'm not sure when they announced it.

13:39 But there's a website called pydoc.io.

13:43 And we're actually going to link to the announcement.

13:46 It's on the Read the Docs site.

13:50 I forgot who's behind this, but the idea is similar to a lot of API documentation generators.

13:57 But it looks like they're going to try to automatically generate documentation about the APIs for at

14:06 least a whole bunch of PyPI repositories.

14:08 Yeah.

14:09 They said they're starting with the popular ones, but they said eventually their plan is to

14:12 auto-generate API references for every package on PyPI.

14:15 So, that's over 90,000 packages.

14:17 That's pretty awesome.

14:18 That's kind of incredible.

14:20 Yeah.

14:21 It may surpass all of the rest of the stuff on the Read the Docs right now, but I'm not sure.

14:25 Yeah.

14:25 So, it's really interesting.

14:26 And, you know, I'm not really sure quite how it works.

14:28 Maybe it looks at the actual documentation in your Python code or whatever.

14:31 But, yeah, have a look.

14:33 If you have a package out there and you want to make sure it shows up well here, you know,

14:37 be sure to check that out.

14:37 Yeah.

14:38 What they, a few of the packages they've got so far, I looked around and it looks pretty neat.

14:41 Yeah, absolutely.

14:42 I was cruising through requests.

14:43 It's up there, of course.

14:44 So, we talked about things that maybe advanced people care about, you know, like converting

14:51 bytes to byte strings and whatnot to regular strings or whatever.

14:55 But I found an interesting article, really a conversation that I wanted to highlight.

15:00 And the question was, what's the one thing or the primary thing that took your Python experience

15:05 to the next level?

15:06 And this is asked by a guy who's had like three months of Python and trying to get into it.

15:09 And so, I picked out five that I thought were pretty cool.

15:12 So, the first one out there said that sort of changed their relationship with Python and

15:19 how they wrote code was mastering generators.

15:21 Another person said, how iteration really works.

15:25 Understanding how iteration really works opens up so many possibilities, like learning how to

15:31 do tuple unpacking, playing with zip, enumerate all, any, looking at iter tools.

15:35 I find it's interesting in Python.

15:37 You know, another person said, list comprehensions, how important iteration and sort of processing

15:43 streams of data is, right?

15:45 Yeah.

15:45 These are good.

15:46 Yeah, these are good.

15:47 One of them, I think, is going to be near and dear to your heart is unit testing and pytest

15:50 in particular.

15:51 Yeah.

15:52 I would probably say do system level tests first.

15:55 But yeah, I agree.

15:56 Well, it changed this guy's life.

15:58 So, another person said, for me, all of David Beasley's work, in particular, his work on

16:05 coroutines, which was sort of hinting at the AsyncIO stuff as well.

16:09 Maybe I should check that out.

16:10 Yeah, we should.

16:11 Yeah, we could check that out for sure.

16:12 One of the things I'd like to add to this is the, I see a lot of people that already know

16:16 several languages.

16:17 And then when they come to Python, there's a desire to just jump in the deep end and skip

16:23 over some of the basics.

16:24 And I think anybody that's in that boat should go back and make sure they understand all of

16:29 the basic data structures in Python because misusing data structures and things like for loops

16:35 and if else and all those things and some of the comparison operators that are different

16:42 than other languages can make your code a lot better right off the bat.

16:45 Yeah, absolutely.

16:46 I think it's one of the curses of Python's ability to be quickly and easily learned.

16:52 You don't have to trudge through all the details.

16:54 You can almost just jump in like right away.

16:56 But you do actually overlook some of its really beautiful nuanced aspects of it if you just have

17:03 the same mindset as they come in from like C or whatever.

17:05 Yeah, like I still find people that are surprised that have actually written Python for a long

17:10 time that don't know that you can do two comparisons in an if statement.

17:14 You can say like if one is less than X is less than 12 or something like that.

17:19 Yeah, I tried pipe pipe and it didn't work.

17:21 So it must not be in there.

17:22 So when you write code like that, you probably want to debug it easily, right?

17:26 And the best place to learn how to quickly and easily debug your code is from my dinosaur.

17:31 What?

17:31 The guy who gave the talk was wearing a dinosaur suit.

17:33 Oh, yeah, yeah.

17:35 So I'm talking about Q.

17:37 Our friend Luciano Romano gave us.

17:40 Oh, yeah, totally.

17:42 You like set it up for me and laid it up and I just dropped the ball.

17:46 I was playing baseball over in the corner.

17:48 Dinosaurs.

17:49 So Luciano Romano tweeted out something really cool and we both picked up on it.

17:53 Yeah, Luciano Romano, by the way, way cool name.

17:57 There's a product, a project on PyPI called Q and it's a quick and dirty debugging output for tired programmers.

18:06 And there's a link to a five minute lightning talk by now I'm going to forget this guy's name.

18:13 It was something cool.

18:14 I think.

18:14 Yeah.

18:15 And the gist of it is just a way to add logging that saves to a file and in very little code.

18:24 And this is something you can add even to a running like a web service or something that you have no idea where standard out and standard error going.

18:33 And you could still add some logging to find out what's going on.

18:36 Yeah, it's really cool.

18:37 What I really like about it is you basically say the guy hates typing.

18:40 So everything's like one letter, which we could debate the merits of that.

18:43 But you go instead of log something or print something, you say Q dot Q and you give it an expression.

18:47 It can be as complicated as you want.

18:49 And it will actually figure out the expression, the method it's in, as well as the value and like give you a little summary.

18:56 It's really cool.

18:57 There's also a tracing thing.

18:58 So if one function is being called with the wrong parameters and you're like, why is this happening?

19:03 You can put like a decorator Q dot T on that function and it will trace the entire call stack with the name of the function,

19:09 all the local parameters that are passed and so on.

19:11 Yeah.

19:11 And just watching him in this talk to add like fairly complete logging onto a module in like, I don't know, 20 characters, the added to the file.

19:21 It's pretty cool.

19:23 So definitely check it out.

19:25 And a bonus because he's in a dinosaur suit.

19:26 Yeah, he's also in a dinosaur suit.

19:28 One of the things I liked about it is because I'm one of those quick and dirty debuggers that I will not reach for the debugger first.

19:35 I will reach for logging.

19:36 And so this is good.

19:38 Yeah, it was really cool.

19:39 And it's a five minute lightning talk at a PyCon, but it's like 25 minutes in.

19:44 And so the link I put in there actually has the timestamp in it.

19:48 So it should jump right to his talk.

19:49 One of the things I liked is just it's a decent example for giving a good lightning talk as well.

19:54 Oh, yeah.

19:55 It was really compelling.

19:55 People loved it.

19:56 Yeah.

19:57 All right.

19:57 That's it for the news.

19:58 You might have thought Thanksgiving was going to be dull, but no, it was not.

20:01 Brian, what else is up with you?

20:04 Thanksgiving has put me behind schedule on my book.

20:06 And so I'm going to have to take a little bit of a pause from some of the podcasts.

20:11 Other than this, I'm going to keep up with this, of course, and catch up on my book.

20:16 I do have some interesting interviews coming up, and I'll definitely keep those flowing as soon as whenever they come in.

20:21 But that's up for me.

20:22 What do you got going, Michael?

20:23 Excellent.

20:24 You know, not too much.

20:25 I tried to catch up on a bunch of things over the downtime on break.

20:29 But also, I just have a quick follow-up from last week.

20:32 We talked about how cool Python 3.6 is and that the release is coming that was in beta.

20:36 I think I forgot to mention the expected release date of Python 3.6, according to the official page there, is December 16th, 2016.

20:47 So that's actually coming up, you know, in a couple weeks, right?

20:50 We're going to be having a shiny new Python 3.6.

20:53 It's going to be great.

20:54 Yeah, we'll definitely have to include that in that week's Python Bytes.

20:58 There's no way to avoid that.

20:59 That's going to be awesome.

20:59 Looking forward to it.

21:00 It was great to chat with you, and thanks for sharing all the news you found with everyone.

21:04 Thanks for talking with me, Michael.

21:06 You bet.

Back to show page