« Return to show page
Transcript for Episode #36:
Craft Your Python Like Poetry and Other Musings
00:00 KENNEDY: Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds. This is Episode #36, recorded July 26, 2017. I’m Michael Kennedy.
00:00 OKKEN: And I’m Brian Okken.
00:00 We’ve got some great stuff lined up for you, very cool news in the Python space, but before we get to it, I just want to say Rollbar is sponsoring this episode. They’ve got a really great offer for you at pythonbytes.fm/rollbar. I’ll tell you more about that later.
00:00 now, Brian, I would like you to tell me some poetry. Read me something beautiful.
00:00 So, it’s Poetry Hour at Python Bytes. (Laughs) No.
00:00 started at a community college and I switched to the University of Oregon to start the computer science program and one of the first classes I was in, before we got into 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. I like that lesson.
00:00 an article by Trey Hunner and it’s called, “Craft Your Python Like Poetry”. Just some decent advice. Your code shouldn’t really look like prose from a novel it should look more like poetry. And it’s not just pretty for pretty’s sake, it’s more readable when it’s visually appealing, I think. He brings up line length is important, although shorter is more readable. Man, he recommends 55-character line lengths and that’s pretty short.
00:00 I think there’s a real tension in this one, although I do agree that line length matters and I prefer shorter is better in some ways. However, one of the real tensions I find here is another good practice is to have descriptive variable names. Sometimes that means longer than X, Y and Z for your variable names. 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.
00:00 Yeah, there is some tension there. And also, in working with data and tables and stuff, I do find that tables that look like tables instead of looking crammed all the way to the left-hand side are more visually readable.
00:00 getting over the line length thing, he does have a lot of good comments about when you do have to continue on line to make it shorter, like do a line break, where you do it makes a big difference. He has some examples to make. ‘Making broken comprehensions more readable’ and ‘function call parameters.’
00:00 of the things, maybe this is a functional programming thing, but ‘chained function calls’, I probably just don’t do that very much. The dot alignment, he noted, looks pretty nice.
00:00 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’. If you set up a dictionary that’s kind of like an enum list, it’s basically just a predefined dictionary literal. Having one element per line makes it more readable. But then there’s always trade-offs. If you’ve got a really large one, vertical length is important as well, and having a super long program might not be as easy to read as a shorter one.
00:00 I’m with you on that. Let me throw in another one that I don’t think is covered here or maybe I just missed it, is function length. The idea of breaking your program into little tiny bits, little small, readable, easily understandable pieces. Kind of like a haiku I guess, rather than a long, flowing poem.
00:00 Also, he doesn’t talk about white space too much, but there’s white space even within a function and breaking up the different parts of when you’re working with setting up the data, versus other things to break up by white space. Similar to how long poems are broken into little stanzas or something.
00:00 Yeah, you know, thinking about this, one of the things that strikes me… The way that your code looks and breaking it down like this, thinking about it this way, it’s a big sign of professional developer versus somebody just learning, somebody just poking around who’s not really a developer. Professional developers code looks like these types of things. It’s clearly structured beyond just what the language requires. A lot of times, people who are new, they just kind of mush it together.
00:00 you’re looking to come across better with your code, I guess think about that as well.
00:00 So, I want to bring everyone’s attention to this thing called, “The Fedora Python Classroom Lab”. The idea is Fedora, it’s a Linux distribution, a really nice one. What they’ve built is basically Python and data science, Python-based data science, in a box. Or rather, in an ISO. What you can do is you can get just the ISO DVD image of this Fedora Python Classroom. You can mount it and literally boot straight to this thing. It fires up Fedora and you can login without even installing it. You login and you have access to Numpy, IPy, CyPython, Matplotlib, Requests. All the various most common packages and it’s just up and ready to go. That’s really sweet. You have the GUI GNOME-based version, or you have Docker or Vagrant node UI variant. All sorts of stuff is set up and ready to go, so if you’re going to teach Python and your thinking of using Linux to do it anyway, here’s a nice thing that you can hand out to the students and say, ‘Boot from this DVD or this image and create a virtual machine based off of it and you’re ready to roll.’
00:00 That’s cool.
00:00 I originally thought this was a thing I downloaded inside Fedora. I logged into Fedora and I was like, ‘Wait, where’s all the stuff? Oh, it’s actually its own copy of Fedora.’ This is its own Linux plus reconfigured Python stuff.
00:00 Pretty cool, right?
00:00 Yeah, that’s everything, including Tox in there.
00:00 Yeah, it’s all ready to roll. Multiple versions of Python, everything.
00:00 you have some less than amazing news for what’s up next. We’ve 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 smarts, right? It would add autocompletion even where there wasn’t and these types of things. But it turns out, there was a few drawbacks conceptually around it, but there’s also a bit of a toss-up about actually bitter behavior. What’s up with this?
00:00 So, especially because we had covered it, my reluctance to this product to start with was that they would – it’s all cloud-based stuff – in order to give you hints and stuff, they would send your code to their company and then you’re just going to have to trust that they’re not going to do anything evil with it.
00:00 I was a little reluctant at that as well. When I was playing with it, I put it on a section. You can save this subset of your hard drive it can interact with. I gave it a section where it didn’t have things that had API keys and things, 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?
00:00 No, what we’re talking about is an article that came out. I’ve never seen this site before, theoutline.com and the article is called, “How a VC-Funded Company is Undermining the Open Source Community”. It’s about some accusations of some underhanded tactics by Kite.
00:00 story is, it’s about two add-ons to Atom, the text editor Atom. 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. I’m guessing Minimap is similar to the map feature on Sublime or something. But the one developer, @abe33, was hired by Kite and then after being hired by Kite, updated the plug-in with a Kite promotion feature.
00:00 Actually, the git commit log was, ‘Added Kite promotion feature’ or something like this, right?
00:00 Yeah, and the feature was to insert weblinks or links back to articles on the Kite website related to the content of a user’s code. It would read the code, figure out which article would be relevant and put links. I’m guessing the links go in the Minimap and aren’t actually inserted in your code, hopefully.
00:00 the users were rightfully kind of ticked about this and said, ‘This isn’t a feature, this is blatant advertising.’
00:00 I think there’s two levels here. On one hand, the person who added that feature was the creator of the product, so that’s not great. 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. This is, let’s say, a little shady, I would say, in the spectrum in my mind. There’s very small points where this is going to benefit the users, other than the one user who is Kite.
00:00 Yeah. Now if it was possibly suggesting lots of different articles from different websites it still would be weird. It’s a completely unrelated thing, feature, of it. I don’t know.
00:00 next one is a – I had to look it up but it’s another Atom add-on – which is an auto-complete Python, so that definitely relates to Python. It didn’t insert advertising, but what it did do was, the auto-complete 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. If somebody updated that plug-in, I don’t think they would know that that was going on.
00:00 Yeah, how would you even know, right? ‘Auto-complete is still working. Oh wait, it’s because my code is no longer on my machine. How strange.’
00:00 I’m not sure who put that feature in but the article suggests that instead of a hire by Kite, just a bunch of Kite people were working on the plug-in and added this. Again, users aren’t supportive of that change and it is a bit weird. Basically, 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 people, like a whole lot of people. And it only takes one person, core person to be corrupted or influenced to basically make the package benefit a single company instead of the rest of the world. Yeah, it’s problematic and interesting.
00:00 Yeah, it definitely raises some interesting moral issues around Open Source. 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 visible, if that means privacy changes and your code is now being analyzed outside of your control rather when you thought it wasn’t.
00:00 Yeah, like that auto-complete 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. I’m kind of used to that and it’s not terrible. It’s very out in the open. So, I kind of would have expected them to fork that project and have a different auto-complete project that would go to Kite instead of using Jedi. That would have made more sense to me.
00:00 Yeah, if you opt into it you get better auto-complete, you might make that trade-off, right?
00:00 Yeah, but anyway.
00:00 Anyway, everyone can read it for themselves. It’s a pretty interesting article.
00:00 something I am much more comfortable with – I use it on my projects – is Rollbar. So, you guys have 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 emails, things like that. You usually don’t even have to debug your code, you can just login and see all the variables pass, the whole call stack, things like that, and just go and fix it. 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 vaguely send you a message like, ‘This button doesn’t work anymore.’ ‘What do you mean it doesn’t work?’
00:00 pip install Rollbar and you’ll be ready to roll. Check them out at pythonbytes.fm/rollbar. I use it on pythonbytes.fm and other sites. It’s great. Thanks, Rollbar.
00:00 Thank you, Rollbar.
00:00 You know, journalism in general has been more interesting in the last six months, I would say than it traditionally has. The next thing I want to talk about is maybe a specialized green scraping-type of library called Newspaper. So, this is a Python package, pip install Newspaper-type of thing. The idea is you can point this at a URL or say, CNN or MSNBC or New York Times or something like that, and it will give you very detailed information that you might care about for news articles. Have you heard about this, Brian?
00:00 I haven’t.
00:00 This is really slick. So, I’ll give you a little sense of the code because there’s just a few steps. You’re like, ‘Wow, that’s sweet.’ You create this article, object, and you pass the URL to some news item, You can download it and it will give you the content. You can parse it and then you can ask it things like, ‘Who were the authors?’ and it will just give you a list of the names of the authors already discovered. You can ask it when it was published. You can do NLP, Natural Language Processing, on it. Then you can ask, ‘What are the keys words? Give me a summary of this article. What is the cover image of this article?’ All sorts of stuff like that. This is really cool if you work in news type-data.
00:00 This is great. Especially if you tie it to other ways that you’re going to get news articles to be able to parse some of this as a little service. That’d be cool.
00:00 Yeah, and I don’t remember where you point it 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. It’s pretty slick.
00:00 I like it.
00:00 It’s a little bit of that import anti-gravity-type thing. ‘I typed a few lines and it’s rolling.’
00:00 Before we move on, the code example that you talked about, you put it up on our show notes, and it really is just like 17 lines of code. It’s pretty short.
00:00 Yeah, and like half of that is showing you what’s printed out. (Laughs) Maybe not half, but something like that.
00:00 this ability to grab these packages and do amazing stuff in a few lines of code, maybe that’s why Python is popular. What do you think?
00:00 Yeah, I think so. And there’s an article from IEEE Spectrum called, “The Top Programming Languages of 2017” and big surprise, we’re number one! Yay!
00:00 We’re #1! Woohoo! Yeah, it’s really cool and it’s one in a lot of interesting ways. There’s actually five measures which mean anything to me. One measure is the IEEE Spectrum ranking, one is trending, one is jobs and one is open. So, you can go over to this interactive thing IEEE Spectrum rating is all-around. Trending is languages that are growing rapidly. Jobs are languages that are in demand by employers and open is popular on Open Source hubs. You can also dig into it by embedded devices and things like that.
00:00 This is an interactive thing. You can even customize your ranking if for what’s important for you, which is kind of fun.
00:00 Right. Like, ‘I care about enterprise development and jobs’ or something like this. And you can narrow that down. It’s definitely interactive.
00:00 me give you the numbers, Brian. So, for trending, number one is Python. Close behind is C and C++ and Java and Swift is there as well. Then for jobs, actually, Python is number three but just like .7%. So, it goes Java, C and then Python. For openness, Python is way back on top. And then custom, whatever that means, that’s make your own.
00:00 Yeah, my comment, I think the reason why there’s more Java jobs is because there’s a bunch of Java programmers shifting to Python.
00:00 Right, like there used to be a lot of COBOL jobs. (Laughs) It’s not because COBOL is growing, people have got to keep that stuff going.
00:00 COBOL is still on the list. Wow, it’s 24th in jobs.
00:00 Yeah. Man, that puppy is hanging in there.
00:00 Poor people. But Assembly is like 11th.
00:00 Interesting. There’s all these different measures and rankings and they all take different things into account. You’ve got to take that with a bit of a grain of salt.
00:00 one trend that seems to appear across all of these, Python is very high on the list and is growing more popular and higher up on the list. So, that’s a great thing for betting your career, focusing your career and energy on Python.
00:00 Yeah, and IEEE is respected by a lot of people but they also openly show you what they used for their methodology and how they rank things. It’s nothing surprising. A combination of Stack Overflow and Trans and Twitter, including articles in their IEEE Xplore Digital Library. Not surprising, but it’s cool that they just show you what all those are.
00:00 Right, when they say it’s popular in jobs it’s because they’re crawling Stack Overflow jobs, probably CareerBuilder, Dice.
00:00 Yeah. I didn’t even know Dice was still around. (Laughs) No offense to all the Dice people.
00:00 MySpace is still around. AOL is still around.
00:00 last thing I want to share with you guys is SciPy 2017 Conference happened in Seattle, here in the U.S. Like many of these conferences, the videos and tutorials are imported, put on YouTube and you can go check them out. There’s a ton of tutorials if you want to get into Data Science. The keynote – I haven’t had a chance to watch it but it sounds really interesting – is “Coding for Science and Innovation”. Who wouldn’t want to do that? That sounds awesome.
00:00 got “Dash”, which you’ve talked about before, “A New Framework for Building User Interfaces for Technical Computing”. A similar spelling but totally different thing is “Dask”, for parallelize data processing data pipelines. We’ve got “Scientific Analysis at Scale, a Comparison of Five Systems” with Jake VanderPlas. And “Academic Open Source” which I think it pretty cool for groups of people in that area. So, tons of videos. These are just a few I grabbed to give you a flavor of what’s out there.
00:00 I was in Seattle. Man, I wish I would have gone.
00:00 Yeah, I know. I was planning on going but I couldn’t quite make it.
00:00 I’m glad the videos are out there. I’ll check some of those out.
00:00 And I just got a notice that PyCon Canada call for proposals opened today or yesterday, speaking of conferences. If you want to speak at the other major Python conference in North America, it’s time to submit the proposals.
00:00 Do you know which Canada it is? The left Canada or the right Canada?
00:00 I think it’s the right Canada. It’s in Montreal. (Laughter)
00:00 well that’s it for our news, Brian. Anything else you want to share with everyone?
00:00 I am closing-ly done, I’m almost done with the book. I wanted to try to get it down last night at midnight but I’ve got a few hours left. I’m super excited to get the Python testing book out to everybody.
00:00 Yeah. It’s been a big success; people are responding well to it. Congratulations.
00:00 Thanks. How about you?
00:00 Nothing too new, just cranking along. Enjoying summer, enjoying working on Python stuff but nothing specific.
00:00 Speaking of summer, you’ve got a vacation coming up.
00:00 I do, I have a semi-work, travel vacation, more vacation-ish stuff. So, I’m going to be out for four weeks. Probably not next week but the week after. We’re going to see what we can do about lining up some guest hosts and keep the show rolling. No concrete details there yet.
00:00 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.
00:00 That’s right. We’ll see what we can do about either recording on the road or wrangling some people into being a co-host. We’ll see. We’ll keep it rolling as best we can.
00:00 Alright. Thanks, Brian and thanks everyone for listening. Bye.
00:00 you for listening to Python Bytes. Follow the show on Twitter via @pythonbytes and get the full show notes at pythonbytes.fm. If you have a news item you want featured, just visit pythonbyes.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.