Transcript #36: Craft Your Python Like Poetry and Other Musings
Return to episode page view on github00:00 Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
00:05 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.
00:18 Before we get to it, just want to say Rollbar is sponsoring this episode.
00:22 They've got a really great offer for you at pythonbytes.fm/rollbar.
00:25 I'll tell you more about that later. Right now, Brian, I would like you to tell me some poetry.
00:30 Read me something beautiful.
00:31 So it's poetry hour at Python Bytes. No.
00:35 I started at a community college and then I switched to a university of Oregon to start the computer science program.
00:43 And one of the first classes I was in, before we got into like actually the technical stuff,
00:49 my professor said, you need to think about your code like poetry.
00:52 It should be pretty to look at.
00:55 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.
01:01 And it's called Craft Your Python Like Poetry.
01:04 Just some decent advice.
01:06 Your code shouldn't really look like prose from a novel.
01:10 It should look more like poetry.
01:12 And it's not just pretty for pretty's sake.
01:15 It's more readable when it's visually appealing, I think.
01:19 And he brings up line length is important.
01:22 Although shorter is more readable.
01:25 But man, he recommends 55 character line lengths.
01:28 And that's pretty short.
01:30 I think there's a real tension in this one.
01:33 Although I do agree that line length matters.
01:34 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.
01:47 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 them huge really quickly just by virtue of putting long function names alongside long variable names.
02:02 Yeah.
02:02 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 when you do have to continue a line to make it shorter, like do a line break, where you do it makes a big difference.
02:31 And he has some examples to make.
02:33 Making line break or broken comprehensions and more readable and function call parameters.
02:41 And then one of the things, maybe this is a functional programming thing, but chained function calls, I probably just don't do that very much.
02:48 But the dot alignment, he noted, looks pretty nice.
02:53 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.
03:00 So if you set up a dictionary that's kind of like an enum list, it's basically just a predefined dictionary literal.
03:10 Having one element per line makes it a lot more readable.
03:14 But then there's, you know, there's always trade-offs.
03:16 There's a, if you've got a really large one, there's vertical.
03:20 Vertical length is important as well.
03:22 And having a super long program might not be as easy to read as a shorter one.
03:27 I don't know.
03:28 Yeah, I'm with you on that.
03:29 Let me throw in one more that I don't think is covered in here.
03:32 Maybe I just missed it.
03:33 Is function length, right?
03:37 Just the idea of breaking your program into little tiny bits.
03:40 Little small, reasonable, easily understandable pieces.
03:44 You know, kind of like a haiku, I guess, rather than a long, flowing poem.
03:49 Right.
03:49 And also, I guess on that, it doesn't talk about white space too much.
03:53 But there's a white space, even 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.
04:05 Similar to how long poems are broken into little stanzas or something.
04:11 Yeah.
04:11 Yeah.
04:11 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.
04:20 It's a big sign of sort of professional developer versus somebody just learning, somebody just poking around who's not really a developer.
04:27 Like professional developer's code looks like these types of things.
04:31 It's clearly structured beyond just what the language requires.
04:34 And a lot of times people are new.
04:36 They just kind of mush it all together.
04:38 So if you're looking to come across better with your code, I guess, think about that as well.
04:44 Yeah.
04:44 Okay.
04:45 Yeah.
04:45 So I want to bring everyone's attention to this thing called Fedora Python Classroom Lab.
04:52 Okay.
04:53 So the idea is Fedora, it's a Linux distribution, really nice one.
04:57 And what they've built is basically Python and data science, Python-based data science in a box.
05:06 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.
05:24 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:44 So all sorts of stuff is just set up and ready to go.
05:48 So if you're going to teach Python and you're thinking of maybe using Linux to do it anyway,
05:52 here's a really nice thing you can hand out to the students and just say,
05:56 boot from this DVD or this image or create a virtual machine based off of it and you're ready to roll.
06:02 Oh, that's cool.
06:03 Yeah.
06:03 I originally thought this was a thing I downloaded inside Fedora and logged into Fedora.
06:08 I'm like, wait, where's all this stuff?
06:09 Oh, it's actually its own copy of Fedora.
06:12 So this is its own Linux plus pre-configured Python stuff.
06:17 Wow.
06:17 Yeah, that's pretty cool, right?
06:19 Yeah, everything.
06:19 Yeah.
06:19 Including talks in there.
06:21 Nice.
06:21 Yeah.
06:22 It's already rolled.
06:23 Multiple versions of Python, everything.
06:25 So you have some less than amazing news for what's up next.
06:29 So we previously talked about this really cool concept called Kite, which it would take your code
06:34 and it would take a lot of stuff you would do as a developer on your system and it would
06:40 add smart, right?
06:42 It would add auto-completion even where there wasn't and these types of things.
06:46 But it turns out there was a few drawbacks just conceptually around it.
06:50 But there's also a bit of a toss-up about actually their behavior.
06:55 What's up with this?
06:55 Yeah.
06:56 So I was, especially because we had covered it, my reluctance to this product to start
07:02 with was that they would, it's all cloud-based stuff.
07:05 So they would send your code in order to give you hints and stuff.
07:10 It would send your code to their company.
07:13 And then, and you just kind of have to trust that they're not going to do anything evil
07:17 with it.
07:17 Yeah.
07:18 I was a little reluctant at that as well.
07:20 Like if, when I was playing with it, I put it on a section and you can say this subset
07:24 of your hard drive, it can like interact with.
07:27 And I gave it a section where I didn't have like things that had, you know, API keys and
07:32 stuff.
07:32 It was just like me playing around, but still it is a bit of a hesitation, but that's not
07:35 really what we're talking about, is it?
07:37 No.
07:37 What we're talking about, there's a article that came out on, I'd never seen this site before
07:42 the outline.com, which is a article called how a VC funded company is undermining the open
07:49 source community.
07:50 And it's, it's about some underhanded or at least some accusations of underhanded tactics
07:56 by kite.
07:57 So here's the story is it's about two add ons to Adam, the text editor, Adam.
08:04 And one of them is a mini map, which is I'm supposedly downloaded over three and a half million
08:11 times.
08:12 So it's well used and it's developed by one person.
08:15 And I'm guessing mini map is similar to the, like the map feature and sublime or something.
08:19 But the one developer, Abe 33 was hired by kite.
08:24 And then after being hired by kite inserted a, or updated the plugin with, with a kite promotion
08:32 feature.
08:33 That was actually the, the, the, the, the get law, the get commit log was added kite promotion
08:37 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
08:47 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:01 But the users were rightfully kind of ticked about this and said, this isn't a feature.
09:07 This is just blatant advertising.
09:08 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, right?
09:17 So that's not great.
09:19 If, if some other random person had come along and inserted this promo stuff into someone else's
09:25 open source project, that would have been flat out terrible.
09:27 This is, let's say a little shady, I would say in, in the spectrum, in my mind, this is
09:34 like, it's not, there's, there's no point.
09:37 Well, there's very small points where this is actually going to benefit the users other
09:41 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
09:49 different websites, it still would be weird.
09:51 It's a, it's a completely unrelated thing feature of it.
09:56 I don't know.
09:57 Yeah.
09:57 The, the next one is a, it's, I had to look it up, but it's another Adam add-on,
10:03 which is a autocomplete Python.
10:06 So that definitely relates to Python, but it, it didn't insert advertising, but what
10:11 it did do was it had the autocomplete was done using a local engine on the user's computer
10:18 called Jedi.
10:19 And it got switched at one point to default to the kite engine, which is a cloud-based
10:27 engine.
10:27 So it would send all your code to kite.
10:31 Kind of, if somebody updated that plugin, wouldn't they would, I don't think they would
10:35 know that that was going on.
10:36 Yeah.
10:37 How would you even know?
10:38 Right.
10:38 I mean, look, the autocomplete still working.
10:40 Oh, wait.
10:40 It's because my code's no longer on my machine.
10:43 How strange.
10:44 And apparently this wasn't done by, I'm not sure who put that feature in, but the article
10:50 suggests that instead of a purchase of the, or a hire by kite, it was just a bunch of kite
10:57 people were working on the plugin also and added this.
10:59 Again, users aren't, a lot of users weren't exactly supportive of that change.
11:04 And it is a bit weird.
11:05 And basically that's, I think the point of this article is to point out that we've got
11:11 a lot of, a lot of open source projects that are used by a lot of people, like a whole lot
11:16 of people.
11:17 And it only takes maybe one person, a core person to be corrupted or influenced to basically
11:27 make the package benefit a single company instead of the rest of the world, which yeah, it's
11:32 problematic and interesting.
11:34 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
11:46 using your product, especially if those changes are invisible, if that means like privacy changes,
11:50 like your code is now going and being analyzed outside of your control rather than when you thought
11:56 it wasn't, things like that.
11:57 Yeah, like that autocomplete thing.
11:59 What I guess I would have expected as an open source user is I don't care really if
12:04 a company has a, has a open source projects that, that they're maintaining that benefit their
12:10 company.
12:11 We're kind of used to that and, and that's not terrible, but it's very out in the open.
12:16 So I would kind of would have expected them to like fork that project and have a different
12:22 autocomplete project that would go to the kite instead of using Jedi.
12:25 That would have made more sense to me.
12:27 Right.
12:27 Then you opt in.
12:28 Yeah.
12:28 If you opt into it, you get better autocomplete.
12:30 You might make that trade off.
12:31 Right.
12:32 Yeah.
12:32 But anyway.
12:34 Yeah.
12:34 Anyway.
12:35 All right.
12:36 Well, there it is.
12:37 Everyone else, everyone can read it for themselves.
12:39 It's a pretty interesting article there.
12:40 So something I am much more comfortable with using on my projects is rollbar.
12:47 So you guys probably heard us talk about rollbar before.
12:50 It's super easy to integrate into your system.
12:53 You just pip install rollbar and plug in your account key and you're basically ready to go.
12:58 The idea is it will look at your code, especially your web apps while it's running.
13:01 And if there are any errors, it will capture all the details about the errors, send it up
13:06 to the cloud, send you notifications like the Slack, or you can get like emails and things
13:11 like that.
13:11 And usually don't even have to debug your code.
13:14 You can just log in, see all the variables passed, the whole call, you know, call stack,
13:20 things like that, and just go and fix it.
13:23 So half the time, it's really important to be notified right away when an error is happening
13:28 rather than letting it go on for hours.
13:30 And finally, somebody will vaguely send you a message like this button doesn't work anymore.
13:33 What do you mean it doesn't work?
13:35 So 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 So thanks, rollbar.
13:46 Thank you, rollbar.
13:47 You know, the news has been, journalism in general has been more interesting in the last,
13:53 six months, I would say, than it traditionally has.
13:56 Yes.
13:57 And the thing that I want to talk about is like, let's say it may be a specialized screen
14:04 scraping type of library called newspaper.
14:06 So this is a Python package, 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
14:19 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:27 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
14:33 steps.
14:33 You're 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:53 You can ask it when it was published.
14:55 You can do NLP, natural language processing on it.
14:58 Just that's a function.
14:59 Call that.
14:59 And then you can ask, what are the keywords?
15:02 Give me the summary of this article.
15:04 What is the cover image of this article?
15:06 All sorts of stuff like that.
15:07 This is really cool if you work with like a news type data.
15:10 Yeah, this is great.
15:12 Isn't that cool?
15:12 I mean, if you, yeah, especially if you, I guess you tie it to other ways, you're going
15:16 to get different news articles to be able to parse some of this as a kind of little service.
15:22 It'd be cool.
15:23 Yeah.
15:23 And I don't remember where you pointed to to get started, but you can also say, what are
15:27 all of the articles on this new site?
15:30 And then go ask these questions about each article and things like that.
15:33 So it's, it's, it's pretty slick.
15:35 I like it.
15:35 Yeah.
15:35 It's a little bit of that import anti-gravity type thing.
15:38 That's right.
15:38 Definitely.
15:39 I typed a few lines and it's rolling.
15:42 And speaking of that, that might be.
15:43 But before we move on, the, the, the code example you talked about, you, you put it
15:48 up on our show notes and it really is just like 17 lines of code.
15:52 It's pretty short.
15:53 So.
15:53 Yeah.
15:54 And like half of that is like showing you what's printed out.
15:56 Yeah.
15:56 Yeah.
15:57 Maybe not half, but some of that.
15:59 So this sort of really, this, this ability to grab these packages and do amazing stuff
16:04 in a few lines of code.
16:05 Maybe that's why Python's popular.
16:07 What do you think?
16:07 Yeah.
16:07 I think so.
16:08 And, we've gotten, there's an article from I triple E spectrum called the top programming
16:15 languages of 2017.
16:17 And big surprise.
16:18 We're number one.
16:19 Yay.
16:20 We're number one.
16:21 Woo.
16:21 Yeah.
16:22 It's, it's really cool.
16:23 And it's number one in a lot of interesting ways.
16:26 There's actually five measures for which mean anything to me.
16:29 One, one measure is the I triple E spectrum rate, ranking.
16:34 One is trending.
16:36 One is jobs and one is open.
16:38 And so it's kind of, you can go over to this like an interactive thing.
16:42 The I triple E spectrum rating is all around.
16:44 Trending is languages that are growing rapidly.
16:48 Jobs are languages that are in demand by employers and open is popular on open source hubs.
16:54 Yeah.
16:54 You can also dig into it by embedded devices and things like that.
16:58 And it even, this is an interactive thing.
16:59 You can even like customize your ranking if to, for what's important for you, which is kind
17:05 of fun.
17:06 Right.
17:06 Like I care about enterprise development and jobs or something like this.
17:10 And you can like narrow that down.
17:11 It's definitely interactive.
17:12 So let me give you the, let me give you the numbers, Brian.
17:14 So for trending, number one is Python close behind a C and C++ and then Java.
17:20 So, and Swift is there as well.
17:22 And then for jobs, actually Python is number three, but just like by 0.7%.
17:28 So it goes Java C and then Python.
17:31 And then for openness, Python is way back on top and then custom that, whatever that means.
17:35 You gotta let's make your own.
17:37 Yeah.
17:37 Yeah.
17:38 And I, my comment, I think that the reason why there's more Java jobs is because there's
17:42 a whole bunch of Java programmers shifting to Python.
17:45 Right.
17:45 Like there used to be a lot of COBOL jobs, but not COBOL's growing.
17:50 It's because people got to keep that stuff going.
17:51 It's COBOL's still on the list.
17:53 Wow.
17:54 It's 24th in jobs.
17:55 Yeah, man.
17:57 That puppy's hanging in there.
17:58 Oh, poor people.
18:00 Yeah.
18:00 But assembly is like 11th.
18:02 Wow.
18:02 Okay.
18:03 Anyway.
18:04 Interesting.
18:05 Yeah.
18:05 So there's all these different, all these different measures and rankings and they all
18:10 take different things into account.
18:11 So you got to 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 on the list
18:19 and is growing more popular or higher up on the list.
18:21 So that's a great thing for betting your career, your next bit of career and your energy on focusing
18:27 on Python, I think.
18:28 Yep.
18:28 And also, I, I, I, E is respected by a lot of people, but they also right here open,
18:35 openly show you what, what they used for their methodology of how they rank things.
18:39 And, and it's a, it's not nothing surprising combination of Stack Overflow and trans and
18:45 Twitter and, and including articles in their IEEE explore digital library.
18:50 So that's a nice, not surprising, but it's cool that they just show you what all those
18:54 are.
18:54 Right.
18:54 So when they say it's popular in jobs, that means cause they're crawling Stack Overflow
18:58 jobs, probably career builder dice, those types.
19:01 Yeah.
19:01 I didn't know dice was still around, but no offense to all the dice.
19:05 My space is still around.
19:08 My space.
19:09 AOL is still around.
19:12 Okay.
19:13 So last thing I want to share with you guys is recently the SciPy 2017 conference happened
19:20 in Seattle here in the U S and like many of these conferences, the videos and tutorials were
19:26 recorded, put on YouTube and you can go check them out.
19:30 So there's a ton of tutorials.
19:32 If you want to get into data science, the keynote was something I haven't had a chance to watch
19:38 it yet, but it sounds really interesting.
19:39 Coding for science and innovation.
19:41 Like who wouldn't want to do that?
19:42 That sounds awesome.
19:43 Yeah.
19:43 Then we've got dash, which we've talked about.
19:45 You've talked about before a new framework for building yours, a user interface and technical
19:51 computing stuff.
19:51 And then a similar spelling, totally different thing is DASC for like parallelized processing
19:58 data pipelines.
19:59 We've got scientific analysis at scale, a comparison of five systems with Jake Vanderplass and academic
20:07 open source, which I think is pretty cool for groups, people in that area.
20:10 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.
20:15 That was in Seattle.
20:16 Yeah.
20:17 I wish I would have gone.
20:17 Yeah.
20:18 I know I was planning on going, but I couldn't quite make it.
20:21 Yeah.
20:22 I'm glad that you 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.
20:26 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
20:38 in North America, it's time to submit the proposals.
20:41 Do you know which Canada it is?
20:42 The left Canada or the right Canada?
20:44 I think it's the right Canada.
20:46 It's in Montreal.
20:47 Okay.
20:48 Yeah.
20:49 Yeah.
20:50 Yeah.
20:50 All right.
20:53 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
21:05 I'm super excited to get the Python testing book out to everybody.
21:09 Yeah.
21:10 And that's been a big success.
21:12 People are responding well to it.
21:14 So congratulations.
21:14 Thanks.
21:15 Yeah.
21:15 How about you?
21:16 Nothing too new.
21:17 Just cranking along.
21:18 Yeah.
21:19 Bunch of stuff's going on.
21:21 Enjoying summer.
21:22 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:28 I have a semi-work travel vacation, more vacation-ish stuff.
21:33 So I'm going to be out for four weeks, probably not next week, but the week after.
21:37 So we're going to see what we can do about lining up some guest co-hosts.
21:41 Keep the show rolling.
21:41 No concrete details there, but there may be.
21:46 Yeah.
21:47 At the very least, we'll have one more episode and there may be a gap, but we're going to
21:51 try to not have a gap.
21:52 We're going to try not to have a gap.
21:53 That's right.
21:53 We'll see what we can do about recording either on the road or wrangling some people
21:59 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:04 All right.
22:04 Well, thanks, Brian.
22:05 Thank you.
22:05 Thanks, everyone, for listening.
22:06 Yep.
22:07 Bye.
22:07 Thank you for listening to Python Bytes.
22:11 Follow the show on Twitter via at Python Bytes.
22:13 That's Python Bytes as in B-Y-T-E-S.
22:16 And get the full show notes at pythonbytes.fm.
22:19 If you have a news item you want featured, just visit pythonbytes.fm and send it our way.
22:24 We're always on the lookout for sharing something cool.
22:26 On behalf of myself and Brian Okken, this is Michael Kennedy.
22:30 Thank you for listening and sharing this podcast with your friends and colleagues.