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


Transcript #36: Craft Your Python Like Poetry and Other Musings

Return to episode page view on github
Recorded on Wednesday, Jul 26, 2017.

00:00 Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.

00:06 This is episode 36, recorded July 26, 2017. I'm Michael Kennedy.

00:13 And I'm Brian Okken.

00:14 And we got some great stuff lined up for you. Very cool news in the Python space. Before we get to it, just want to say Rollbar is sponsoring this episode. They've got a really great offer for you at pythonbytes.fm/rollbar. Tell you more about that later. Right now, Brian, I would like you to tell me some poetry. Read me something beautiful.

00:31 - So it's poetry hour at Python Bytes. No, I started at a community college and then I switched to a University of Oregon to start the computer science program. And one of the first classes I was in, before we got into like actually the technical stuff, my professor said, "You need to think about your code like poetry. It should be pretty to look at." And it's kind of stuck with me.

00:57 I like that lesson.

00:58 This article, there's an article by Trey Hunter and it's called "Craft your Python like poetry." Just some decent advice.

01:06 Your code shouldn't really look like prose from a novel.

01:11 It should look more like poetry and it's not just pretty for pretty's sake.

01:16 It's more readable when it's visually appealing, I think.

01:20 And he brings up line length is important, although shorter is more readable.

01:25 But man, he recommends 55 character line lengths and that's pretty short.

01:30 I think there's a real tension in this one, although I do agree that line length matters and I prefer to have shorter is better in some ways.

01:39 However, one of the real tensions I find here is another good practice is to have descriptive variable names and sometimes that means longer than x, y and z for your variable names.

01:51 And if you start doing expressions involving those, like this times that past this, that can get huge really quickly just by virtue of putting long function names alongside long variable names.

02:02 Yeah.

02:03 There is some tension there.

02:04 And also, in working with data and tables and stuff, I do find tables that look like tables instead of looking crammed all the way to the left-hand side are more visually readable.

02:18 Anyway, getting over the line length thing, He does have a lot of good comments about like when you do have to continue a line to make it shorter like do a line break Where you do it is makes a big difference and yet he has some examples to make making a line break or broken Comprehensions and more readable and function call parameters and then one of the things I think maybe this is a functional programming thing But chained function calls. I probably just don't do that very much But the dot alignment he noted looks pretty nice The last one that I saw which I kind of do anyway, I didn't realize that some people don't do this is Dictionary literals, so if you set up a dictionary that's kind of like an enum list it's a Basically just a predefined dictionary literal having one element per line makes it a lot more readable But then there's you know, there's always trade-offs There's a if you've got a really large one There's vertical vertical length is important as well and having a super long program might not be as easy to read as a shorter One I don't know. Yeah, I'm with you on that. Let me throw in one more that I don't think it's covered here maybe I just missed it is function function length Right, just the idea of breaking your program into little tiny bits a little small reasonable easily understandable pieces you know, kind of like a haiku I guess rather than a long flowing poem. Right and also I guess on that it doesn't tell you doesn't talk about white space too much but there's a white space even within within a function breaking up the different parts of when you're working with setting up the data versus other things to break it up by white space similar to how long poems break their break are broken into little stanzas or something. Yeah you know thinking about this, one of the things that strikes me is the way that your code looks and breaking it down like this and kind of thinking about it this way, it's a big sign of sort of professional developer versus somebody just learning somebody just poking around is not really a developer like professional developers code looks like these types of things. It's clearly structured beyond just what the language requires. And a lot of times people are new, they just kind of mush it all together. So If you're looking to come across better with your code, I guess, think about that as well.

04:44 Yeah. Okay.

04:45 Yeah. So I want to bring something, bring everyone's attention to this thing called Fedora Python Classroom Lab.

04:53 Okay. So the idea is Fedora, it's a Linux distribution, really nice one.

04:58 And what they've built is basically Python and data science, Python-based data science in a box.

05:07 So, or rather in an ISO.

05:09 What you can do is you can get just the ISO DVD image of this Fedora Python classroom.

05:16 You can mount it and literally just boot straight to this thing.

05:20 It fires up Fedora and you can log in without even installing it.

05:24 Log in, you have access to NumPy, SciPy, IPython, Matplotlib, requests, all the various most common packages.

05:33 And it's just up and ready to go.

05:35 So that's really sweet.

05:36 You have the GUI GNOME based version or you have a Docker or Vagrant, no UI variant.

05:45 All sorts of stuff is just set up and ready to go.

05:48 If you're going to teach Python and you're thinking of maybe using Linux to do it anyway, here's a really nice thing you can hand out to the students and just say, "Boot from this CD or this DVD or this image or create a virtual machine based off of it and you're ready to roll." That's cool.

06:04 a thing I downloaded inside Fedora and we logged into for Fedora and like wait where's all this stuff oh it's actually its own copy of Fedora so this is its own like Linux plus pre-configured Python stuff. Wow yeah that's pretty cool right yeah everything including talks in there nice yeah it's already multiple versions of Python everything so you have some less than amazing news for what's up next so we previously talked about this really cool concept called kite which it would take your code and it would take a lot of stuff you would do as a developer on your system and it would add smart, right? It would add auto-completion even where there wasn't and these types of things.

06:46 But there it turns out there was a few drawbacks just conceptually around it but there's also a bit of a toss-up about actually their behavior. What's up with this? Yeah, so I was, especially because we had covered it. My reluctance to this product to start with was that they would, it's all cloud-based stuff, so they would send your code in order to give you hints and stuff. It would send your code to their company and then and you just kind of have to trust that they're not going to do anything evil with it.

07:17 Yeah, I was a little reluctant at that as well. Like if when I was playing with it, I put it on a section you can say this subset of your hard drive it can like interact with and I gave it a section where I didn't have like things that had you know API keys and stuff it was just like me playing around but still it is a bit of a hesitation but that's not really what we're talking about is it? No what we're talking about there's a article that came out on I'd never seen this site before the outline.com which is an article called how a VC funded company is undermining the open source community and it's about some underhanded, or at least some accusations of underhanded tactics by Kite so the story is it's about two add-ons to Atom, the text editor Atom and one of them is Minimap, which is supposedly downloaded over 3.5 million times so it's well used and it's developed by one person, and I'm guessing Minimap is similar to the map feature in Sublime or something But the one developer, Abe33, was hired by Kite, and then after being hired by Kite, inserted a-- or updated the plugin with a Kite promotion feature.

08:33 That was actually the Git commit log was added Kite promotion feature or something like this, right?

08:38 Yeah.

08:39 And the feature was to insert web links or links back to articles on the Kite website related to the content of a user's code.

08:52 So read the code, figure out which article would be relevant, and put links.

08:57 I'm guessing the links go in the mini-map and not actually inserted in your code, hopefully.

09:02 But the users were rightfully kind of ticked about this and said, "This isn't a feature, this is just blatant advertising." Well, I think there's two levels here.

09:10 On one hand, the person who added that feature was the creator of the product.

09:18 That's not great.

09:19 If some other random person had come along and inserted this promo stuff into someone else's open source project, that would have been flat out terrible.

09:28 This is, let's say, a little shady, I would say, in the spectrum in my mind.

09:36 There's no point, well, there's very small points where this is actually going to benefit the users other than the one user who is kite.

09:42 Yeah.

09:43 Now if it was possibly suggesting, like lots of different articles from different, like different websites, it still would be weird.

09:52 It's a completely unrelated thing, feature of it.

09:56 I don't know.

09:57 Yeah.

09:58 The next one is, I had to look it up, but it's another atom add on, which is a autocomplete Python so that definitely relates to Python but it it didn't insert advertising but what it did do was it had the autocomplete was done using a local engine on the user's computer called Jedi and it got switched at one point to default to the kite engine which is a cloud-based engine so it would send all your code to kite kind of if somebody updated that plug-in wouldn't I don't think they would know that that was going on.

10:36 >> Yeah. How would you even know?

10:38 Look, the autocomplete is still working.

10:40 Oh, wait. It's because my code is no longer on my machine. How strange.

10:44 >> Apparently, this wasn't done by, I'm not sure who put that feature in, but the article suggests that instead of a purchase of the or a hire by Kite, it was just a bunch of Kite people were working on the plugin also and added this.

11:00 Again, a lot of users weren't exactly supportive of that change and it is a bit weird.

11:06 And basically that's I think the point of this article is to point out that we've got a lot of open source projects that are used by a lot of people, like a whole lot of people, and it only takes maybe one person, a core person, to be corrupted or influenced to basically make the package benefit a single company instead of the rest of the world, which it's problematic and interesting.

11:34 So, yeah, it's definitely raises some interesting moral issues around open source.

11:41 And what does it mean to make these types of changes when there's 3 million people already using your product, especially if those changes are invisible, if that means like privacy changes like your code is now going and being analyzed outside of your control rather than when you thought it wasn't, things like that.

11:58 Like that autocomplete thing, what I guess I would have expected as an open source user is, I don't care really if a company has open source projects that they're maintaining that benefit their company.

12:11 We're kind of used to that.

12:12 And that's not terrible.

12:14 But it's very out in the open.

12:16 So I kind of would have expected them to fork that project and have a different autocomplete project that would go to the kite instead of using Jedi. That would have made more sense to me.

12:27 Right, then you opt in. Yeah, if you opt into it you get better auto-complete. You might make that trade-off, right? Yeah, but anyway. Yeah, anyway. All right, well there it is. Everyone else, everyone could read it for themselves. It's a pretty interesting article there. So something I am much more comfortable with using on my projects is Rollbar. So you guys probably heard us talk about Rollbar before. It's super easy to integrate into your system. You just pip install rollbar and plug in your account key and you're basically ready to go. The idea is it will look at your code, especially your web apps while it's running. And if there are any errors, it will capture all the details about the errors, send it up to the cloud, send you notifications like to Slack, or you can get like emails and things like that. And usually don't even have to debug your code, you can just log in, see all the variables passed, the whole call stack, things like that, and just go and fix it.

13:23 Half the time, it's really important to be notified right away when an error is happening rather than letting it go on for hours and finally somebody will vaguely send you a message like this button doesn't work anymore.

13:34 What do you mean it doesn't work?

13:36 pip install rollbar and you'll be ready to roll.

13:39 Check them out at pythonbytes.fm/rollbar and use it on pythonbytes.fm and other sites.

13:45 It's great.

13:46 Thanks, Rollbar.

13:47 >> Thank you, Rollbar.

13:48 >> You know, the news has been, journalism in general has been more interesting in the last six months, I would say, than it traditionally has.

13:58 The thing that I want to talk about is, let's say, maybe a specialized screen scraping type of library called Newspaper.

14:07 This is a Python package.

14:08 pip install newspaper type of thing.

14:11 And the idea is you can point this at a URL for say like CNN or MSNBC or New York Times or something like that.

14:20 And it will give you very detailed information that you might care about for news articles.

14:26 Have you heard about this Brian?

14:27 I haven't.

14:28 Yeah, this is really slick.

14:29 So you create I'll just give you like a little sense of the code because there's just a few steps like wow, that's sweet.

14:34 So you create this article object and you pass it the URL to like some news item.

14:40 You can download it and it'll just give you the content.

14:43 You can parse it.

14:45 And then you can ask it things like, who were the authors?

14:48 And it will just give you a list that are just the names of the authors that already discovered.

14:54 You can ask it when it was published, you can do NLP natural language processing on it just that's a function call that.

15:00 And then you can ask what are the keywords?

15:02 Give me the summary of this article.

15:04 is the cover image of this article? All sorts of stuff like that. This is really cool if you work with like a news type data. Yeah, this is great. Isn't that cool? I mean if you... Yeah, especially if you, I guess you tie it to other ways you're gonna get different news articles to be able to parse some of this as a kind of little service. It'd be cool. Yeah, and I don't remember where you pointed to to get started, but you can also say what are all of the articles on this news site and then go ask these questions about each article and things like that. So So it's pretty slick.

15:35 - I like it.

15:36 - Yeah, it's a little bit of that import anti-gravity type thing, right?

15:39 - Definitely.

15:40 - I typed a few lines and it's rolling.

15:42 Speaking of that, that might be--

15:44 - But before we move on, the code example you talked about, you put it up on our show notes, and it really is just like 17 lines of code.

15:52 It's pretty short, so.

15:53 - Yeah, and like half of that is like showing you what's printed out, yeah.

15:57 - Yeah.

15:58 - Or maybe not half, but some of that.

15:59 So this sort of really, this ability to grab these packages do amazing stuff in a few lines of code.

16:06 Maybe that's why Python's popular.

16:07 What do you think?

16:08 Yeah, I think so.

16:09 And we've gotten, there's an article from IEEE Spectrum called the top programming languages of 2017.

16:17 And big surprise, we're number one.

16:19 Yay.

16:20 We're number one.

16:21 Woohoo.

16:22 Yeah, it's really cool.

16:23 And it's number one in a lot of interesting ways.

16:26 There's actually five measures, four of which mean anything to me.

16:31 measure is the IEEE spectrum rate ranking. One is trending, one is jobs, and one is open.

16:40 You can go over this like an interactive thing. The IEEE spectrum rating is all around. Trending is languages that are growing rapidly. Jobs are languages that are in demand by employers.

16:52 Open is popular on open source hubs. You can also dig into it by embedded devices and things like that.

16:58 This is an interactive thing.

16:59 You can even customize your ranking for what's important for you, which is kind of fun.

17:06 Right, like I care about enterprise development and jobs or something like this.

17:10 And you can narrow that down.

17:11 It's definitely interactive.

17:12 So let me give you the numbers, Brian.

17:14 So for trending, number one is Python.

17:17 Close behind is C and C++, and then Java.

17:21 And Swift is there as well.

17:23 And then for jobs, actually Python is number three, but just like by 0.7%.

17:29 So it goes Java, C, and then Python.

17:31 And then for openness, Python is way back on top.

17:34 And then custom, whatever that means.

17:35 You gotta, that's make your own.

17:37 - Yeah.

17:38 Yeah, and my comment, I think that the reason why there's more Java jobs is because there's a whole bunch of Java programmers shifting to Python.

17:45 - Right, like there used to be a lot of Cobalt jobs.

17:48 But now Cobalt's growing, it's 'cause people gotta keep that stuff going.

17:52 - Cobalt's still on the list.

17:54 Wow, it's 24th in jobs.

17:56 Yeah, man, that puppy's hanging in there.

17:58 - Huh, poor people.

18:00 - Yeah.

18:01 - But assembly is like 11th.

18:02 Wow, okay.

18:04 Anyway.

18:05 - Interesting.

18:05 Yeah, so there's all these different measures and rankings and they all take different things into account.

18:11 So you gotta take that with a bit of a grain of salt.

18:14 But the one trend that seems to appear across all of these is Python is very high in the list and is growing more popular higher up on the list.

18:21 So that's great thing for betting your career, your next bit of career and your energy on focusing on Python, I think.

18:28 Yep.

18:28 And also, IEEE is respected by a lot of people.

18:32 But they also, right here, openly show you what they used for their methodology of how they rank things.

18:39 And it's nothing surprising, combination of Stack Overflow and Trends and Twitter, and including articles in their IEEE Explore digital library.

18:50 So that's not surprising.

18:52 but it's cool that they just show you what all those are.

18:54 - Right, so when they say it's popular in jobs, that means 'cause they're crawling Stack Overflow jobs, probably Career Builder, Dice, those types.

19:01 - Yeah, I didn't know Dice was still around.

19:03 But no offense to all the Dice people out there.

19:07 - MySpace is still around.

19:08 - MySpace.

19:09 - AOL is still around, okay.

19:13 So, last thing I wanna share with you guys is recently the SciPy 2017 conference happened in Seattle here in the US.

19:23 And like many of these conferences, the videos and tutorials were recorded, put on YouTube, and you can go check them out.

19:30 So there's a ton of tutorials if you want to get into data science.

19:34 The keynote was something I haven't had a chance to watch it yet, but it sounds really interesting coding for science and innovation.

19:41 Like who wouldn't want to do that?

19:42 That sounds awesome.

19:43 Yeah, then we've got dash, which we've talked about, you've talked about for a new framework for building user interface and technical computing stuff.

19:51 And then similar spelling, totally different thing, is Dask for like parallelized processing data pipelines.

19:59 We've got Scientific Analysis at Scale, a comparison of five systems with Jake VanderPlas.

20:05 And Academic Open Source, which I think is pretty cool for groups, people in that area.

20:11 So tons and tons of videos.

20:12 These are just a few I grabbed to give you guys a flavor of what's out there.

20:15 Yeah, that was in Seattle.

20:17 - Man, I wish I would have gone.

20:18 - Yeah, I know, I was planning on going, but I couldn't quite make it.

20:21 - Yeah, I'm glad-- - A little too hectic at the time.

20:23 - I'm glad the videos are out there.

20:24 I'll have to check some of those out.

20:25 - Yep, and I think I just got a notice that PyCon Canada call for proposals opened today or yesterday.

20:32 So, speaking of conferences, if you want to speak at the other major, major Python conference in North America, it's time to submit the proposals.

20:41 - Do you know which Canada it is?

20:43 The left Canada or the right Canada?

20:45 - I think it's the right Canada.

20:47 It's in Montreal.

20:48 - Okay.

20:48 (laughing)

20:51 - All right, well that's it for our news, Brian.

20:54 Anything else you want to share with everyone?

20:56 - I am closingly done, almost done with the book.

21:00 I wanted to try to get it done last night at midnight, but I've got a few hours left, but I'm super excited to get the Python testing book out to everybody.

21:10 - Yeah, and that's been a big success.

21:12 People are responding well to it, so congratulations.

21:15 - Thanks.

21:15 How about you?

21:16 Nothing too new, just cranking along.

21:19 Yeah, a bunch of stuff's going on.

21:21 Enjoying summer, enjoying working on Python stuff, but nothing specific.

21:25 Speaking of summer, you've got a vacation coming up.

21:28 I do.

21:29 I have a semi-work travel vacation, more vacation-ish stuff.

21:33 I'm going to be out for four weeks.

21:35 Probably not next week, but the week after.

21:37 We're going to see what we can do about lining up some guest co-hosts.

21:41 Keep the show rolling.

21:42 No concrete details there.

21:45 There may be.

21:46 Yeah, at the very least, we'll have one more episode and there may be a gap, but we're going to try to not have a gap.

21:52 We're going to try not to have a gap.

21:53 That's right.

21:54 Well, we'll see what we can do about recording either on the road or, or wrangling some people into being a co host.

22:01 So we'll see.

22:02 We'll keep it rolling as best we can.

22:04 All right.

22:05 All right.

22:06 Well, thanks, Brian.

22:07 Thanks, everyone for listening.

22:08 Yep.

22:09 Bye.

22:10 Thank you for listening to Python Bytes.

22:11 Follow the show on Twitter via @pythonbytes.

22:13 Python Bytes as in B-Y-T-E-S. And get the full show notes at pythonbytes.fm. If you have a news item you want featured, just visit pythonbytes.fm and send it our way. We're always on the lookout for sharing something cool. On behalf of myself and Brian Okken, this is Michael Kennedy. Thank you for listening and sharing this podcast with your friends and colleagues.

Back to show page