Transcript #177: Coding is 90% Google searching or is it?
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 177, recorded April 8th, 2020.
00:10 I'm Michael Kennedy.
00:11 And I'm Brian Ecken.
00:12 And this episode is brought to you by Datadog.
00:13 Check them out at pythonbytes.fm/datadog.
00:16 More on that later.
00:17 Brian, can you believe that it's April?
00:19 I really can't.
00:20 It doesn't feel like it.
00:22 I know.
00:22 I feel like we're still kind of in the winter mode and yet it's warm and sunny.
00:25 For the first time in seven months, I've been told.
00:27 Yeah, well, I'm doing yard work, but it was just sort of feel like we're going to skip Easter.
00:32 I don't know what's going on there.
00:33 Yeah, it's crazy times, but at least it's warming up out there and that's lovely.
00:37 So before we get into our main items, I have a very exciting announcement that we were just working on to let everyone know about.
00:44 So we're trying to find other ways for people to learn about or consume the podcast, other ways that you can interact with us, you dear listener.
00:54 And so we are launching a YouTube project, a YouTube channel.
00:58 So right now, if you can and you're up for it, go over to pythonbytes.fm/YouTube.
01:03 Click subscribe.
01:04 I honestly don't know if there's going to be any content there yet.
01:07 Probably, probably maybe.
01:09 We're not 100% sure because there's none now.
01:11 But by the time this episode comes out, I think we'll have some.
01:14 And the idea is each segment that we're covering, we're going to have a dedicated little video of Brian and me talking.
01:21 And if there's another guest, that'll probably involve them as well.
01:24 And so it'll be really nice to have that for everyone, I think, to just be able to quickly dive in and watch a video, see the two of us talking here as we see each other, but also be able to just focus in on one topic.
01:39 I'm not quite sure how it's going to service, but we'll put it on the YouTube channel, probably put on social media and feedback would be very welcome there.
01:45 I'm super excited for this.
01:47 It's going to be great.
01:47 Yeah, absolutely.
01:48 So am I.
01:49 I'm also a little excited for pip and the whole packaging thing around Python.
01:53 Yeah, well, I am too.
01:54 One of the things I'm looking forward to, I think we covered this a couple episodes ago, is the dependency resolver coming in in changes in PIP, which is exciting.
02:05 But one of the reasons why we're having, I mean, there's been a lot of packaging changes lately.
02:10 We've had relaunch of PyPI in 2018.
02:12 Some security features went in in 2019.
02:16 One of the things I didn't know about was more support for users with disabilities and multiple locales were added in 2019.
02:24 And there's been more security features and pip and the dependency resolver being updated for 2020.
02:31 And a lot of this has to do with some money that came in through some sponsorships and through a gift from the, I think it was the Facebook Foundation or something like that.
02:41 But anyway, some money came in, but they were one-time things.
02:44 And the Python Working Group and the Python Software Foundation wanted to keep this going.
02:49 So they're launching an all-new sponsorship program to help sustain and improve the Python's packaging ecosystem.
02:55 And funds raised through this program will go directly towards improving the tools that all of us and your company uses every day to sustain the continued operation of the Python Package Index.
03:08 And so I wanted to highlight this because I think it's really important.
03:13 And I depend on PyPI and packaging.
03:15 And I know my company does even more and more and more.
03:18 More people are moving towards more Python tools.
03:21 We're linking to this page.
03:22 One of the things on there is there's a prospectus for what you get as a sponsor.
03:28 And you can apply to be a sponsor there.
03:31 And there's a link to ask questions as well.
03:33 And then a note there that even if your company doesn't want to sponsor you, individuals can donate money, either sustaining or one-time thing, too.
03:42 Yeah, I think the changes they've made lately have been in the right direction, and I want to have it keep going.
03:48 Yeah, let's keep it going.
03:49 The changes, the major changes, like the big rewrite of PyPI.org happened because there was a grant.
03:56 I think that one was from Mozilla at the time.
03:58 But it was, we actually have some money and some folks can put their full energy for several months onto that project.
04:05 And guess what?
04:06 When you do that, you make a ton of progress and stuff gets better.
04:09 There are so many companies out there whose primary technology stack is running on Python.
04:17 They have billions of dollars of revenue, and they contribute zero back to Python to keep that base that they are built on strong.
04:27 So this is definitely a chance to encourage your employer to make a yearly sponsorship donation or something like that to the PSF.
04:36 They definitely need it now that PyCon got canceled.
04:38 That means less revenue for them as well.
04:41 So it's more important than even usual.
04:43 Yeah, and I think it would be even neat.
04:45 I mean, a lot of people think about these.
04:47 We have the news.
04:48 There's news of these huge grants and stuff, and those are super nice.
04:52 But if all the companies that use Python, and you know they're hitting PyPI all the time, even just pitched in like a couple thousand dollars a year, even.
05:01 Yeah, it would be game-changing.
05:03 That'd be great.
05:04 Yeah, so that'd be cool.
05:05 Absolutely.
05:05 So on to another good cause.
05:08 As listeners probably know, I'm very passionate about making sure that we address climate change and move to renewable energy.
05:15 things like that at all of our infrastructure and our content delivered carbon-free.
05:20 We have a broader initiative to make sure that we offset any of the resources we might be using and so on.
05:27 So this next project is sort of in that vein, and it's called energy usage.
05:32 So the idea is it's a Python package that will allow you to measure the environmental impact of computation.
05:39 So, you know, we've had profilers like Cprofile, and we've had TimeIt, right?
05:44 Yeah.
05:44 So that's basically the idea of this thing, right?
05:48 But instead of asking how much time does it take, you can ask how much energy does it use.
05:54 And what you do is you give it a function, you give it the arguments, and you just say, run this function and figure out how much energy it uses.
06:02 So it sounds silly, but it can measure how much CPU resources, say, versus disk versus network it's doing and actually figure out how much computation that's taking, right?
06:13 Because at the time, it just tells you how long it took.
06:15 It doesn't say, well, actually, 18% was CPU and it was this high and so on.
06:21 And it takes all sorts of things into account, like the loss of energy across the wires, how far you are away, the location that you're in.
06:28 And so it'll actually, the report you get is like, this computation took 1.86 watts of energy.
06:35 And using geolocation, we saw you're in Pennsylvania.
06:38 So that means you've got 25% coal, 0.17% oil, 30% natural gas, 42% renewable.
06:45 And that's how the energy was broken down for this particular run of that function.
06:50 And it's equivalent to, say, you know, like a certain amount of TV watching or driving so far or U.S. household consumption and so on.
06:58 Interesting.
06:59 Interesting, right?
06:59 Yeah.
07:00 So it's just a nice little package that you can point at some code that you're trying to profile and saying, how much energy does this use?
07:07 Should I worry about it?
07:08 Should I optimize it?
07:09 I mean, profiling is pretty close to giving you where you should focus your energy.
07:14 But if you want to know, okay, this is most of the computation, but how much does that actually cost in terms of carbon?
07:19 Or just more specifically, it's measuring energy consumption, which is also just something you have to pay for if you have a data center.
07:26 Then it's pretty interesting, I think.
07:28 Yeah, we could get like maybe a flaky package that would fail your code if it...
07:33 If it uses too much or something, yeah.
07:35 Yeah, yeah.
07:36 It's pretty interesting.
07:36 It'll output PDFs.
07:39 You can run it where it doesn't put anything on the screen, but then it will, you know, save a report to a file or something like that.
07:45 Does it include the running of the...
07:47 I mean, how much energy does it take to run the usage, energy usage?
07:51 That's very meta, yeah.
07:53 I don't know if it...
07:55 How much it actually is computationally intensive.
07:58 But it is worth pointing out sort of because of that.
08:01 It only runs on Linux because of the system CPU inspection parts of it aren't built out to support other operating systems.
08:08 So you have to be on Linux to do this test on your code.
08:11 So anyway, energy usage, people can check that out.
08:14 It's a cool little package.
08:15 Now, before we move on to the next one, let me tell you about Datadog because this episode of Python Bytes is brought to you by Datadog.
08:21 And let me ask you a question.
08:23 Do you have an app in production that is slower than you like?
08:26 Using too much energy, maybe?
08:27 Its performance is all over the place.
08:30 Sometimes it's fast or slow.
08:31 But the most important question is, do you know why it's slow?
08:34 With Datadog, you will.
08:36 You can troubleshoot your app's performance with Datadog's end-to-end tracing.
08:39 Use detailed flame graphs to identify bottlenecks and latency in that finicky app of yours.
08:44 So be the hero that got the app back on track at your company.
08:47 Get started today with a free trial at pythonbytes.fm.
08:50 Slash Datadog.
08:51 Cool Datadog t-shirt included.
08:54 So, Brian, this next one that you put on here, I almost covered it a few weeks ago as well.
09:00 And I was like, yes, this is really interesting.
09:02 But then, I don't know, something else, like there was a shiny object and it pulled my attention away.
09:07 So, yeah, this is a bit of a philosophical one.
09:10 Yeah.
09:10 So this is a, we're linking to just a short little article, but I wanted to talk about the topic.
09:15 The article is called Coding is 90% Google Searching.
09:19 A brief note to beginners.
09:20 And there's really not much here other than saying that, like, I mean, there's, I guess there's three points in trying to learning how to program.
09:28 And a couple of them are good in that just pick one language to start with when you're learning in a program.
09:35 And, of course, pick Python.
09:36 And then start or do a project, like try to do a project.
09:39 Those are great ideas.
09:40 And then the third point is anytime you get stuck, Google it.
09:44 And the point of the article really is I think that coding is 90% Google Searching anyway.
09:50 So, and people don't usually tell beginners that.
09:53 And I don't think I agree with this.
09:57 I was wondering what you think of this.
09:59 I don't think I agree with it either.
10:00 But I'm not sure I agree with you yet either.
10:02 So, let's talk about it because it is interesting.
10:05 And we probably do agree, honestly.
10:07 I think programming, developer career evolution goes through phases and seasons and whatnot.
10:16 I think in the beginning, you're just super lost.
10:18 You just are trying to figure out syntax and whatever.
10:20 And then you feel really good because, oh, I really got the syntax figured out.
10:24 And it turns out, like, that's a minor part of programming.
10:26 Now you've got tracking down bugs and using libraries.
10:29 And you're like, I got to learn what SQLAlchemy is.
10:31 Oh, my gosh.
10:32 What is a migration?
10:33 Okay, Google migration.
10:34 How do I do migrations?
10:35 Well, this isn't working.
10:36 Let me, like, Google and up at Stack Overflow.
10:38 And in that sort of stage where you've crossed over, like, I'm kind of a competent language user of the language.
10:47 But I'm not really, like, the world is actually open.
10:50 And all these libraries and packages are out there.
10:52 And I have no idea what I'm doing.
10:54 Like, I don't even know what third normal form is.
10:56 So I better figure that out.
10:57 Because it says I need it in my design for my SQLAlchemy classes or whatever.
11:00 I think in that season of your career, I kind of agree with this.
11:04 Like, you're just Googling like crazy.
11:06 And it's okay.
11:08 Because Google is really good.
11:10 And the resources out there are really good.
11:11 But when I saw this article, I thought, okay, that's a pretty good message to people who are kind of new.
11:16 Like, you hear how horrible it is to do copy and paste coding.
11:20 And yet, this person is saying, like, they were, I think, a couple of years into their career.
11:26 They're like, look, I do this a lot.
11:28 And I don't feel like I'm cheating or whatever.
11:30 And yet, I don't feel like, if I had to put a number on it, I would say coding is 5% Google searching for me these days.
11:38 5 to 10.
11:39 Depending on what, if it's like something new I'm doing, it's probably 10% to 15.
11:44 But most day-to-day work, it's 5% or less.
11:48 I don't know.
11:49 How do you feel about that?
11:50 I definitely agree.
11:50 Like, for instance, picking up a new framework or something, I'm going to be looking it up a lot.
11:56 Right.
11:56 There's little spikes as you adopt a new thing.
11:58 But then it really goes back down, right?
12:00 But I was paying attention.
12:02 So I was thinking about this the last couple of weeks and paying attention to my coding style.
12:05 And I do.
12:07 There's probably at least a handful of times during the day where I'm Googling something.
12:12 But it isn't like everything.
12:14 It's definitely more of a 5% thing or less.
12:17 And then I realized that a lot of the things I'm Googling is stuff that I've just decided to not memorize.
12:22 Right.
12:23 Like the syntax of weird things.
12:26 Like, I'm pretty sure that I can have like a step size in range, the range function, but I don't use it very often.
12:33 What's that again?
12:34 You know, things like that.
12:35 Like extra stuff.
12:37 And a lot of this, actually, a lot of this stuff, editor support really helps.
12:41 Anyway, if I already know kind of what I'm doing, the editor can pop up what the syntax is.
12:46 That's a really good point.
12:47 Because if I was using just pure Emacs or something that had zero autocomplete, I'd be Googling more for sure.
12:55 But in PyCharm, you hit dot and like, well, there's three choices.
12:59 Then it tells you the parameters.
13:00 Like, you don't need to Google for that stuff anymore because you've got the better tooling.
13:03 Yeah.
13:04 And there's different stuff.
13:05 Like, so the syntax I leave to the IDE a lot.
13:08 There's definitely a skill.
13:10 So one of the things that kind of missed out of this article is it's not that Google searching is 90% of coding.
13:17 It's a big chunk of your skill set is to learn how to Google something effectively.
13:24 So in coding, like, instead of trying to summarize what the error message is and then Googling that, oh, just paste the entire error message in.
13:34 That's like one trick to do.
13:35 And so there's a whole bunch of coding Google tricks to find the information fast because I don't want it to be 90% of the time.
13:42 I want something that I kind of think I remember to be able to look that up in just seconds and then go back to coding again.
13:50 So, yeah, I hope it's not 90%.
13:52 That would be a very slow way to code.
13:54 It would be.
13:55 But I remember that being the case back in the day.
13:58 And for me, it wasn't Googling because I think we had, when I was first doing programming, you'll have to see if you can remember yours.
14:05 But I was using AltaVista, I'm pretty sure.
14:08 Right?
14:10 Like, people who are listening who don't know what that is.
14:12 That was a search engine that was nowhere near as good as Google that existed before Google.
14:16 But the things you would end up, there was not Stack Overflow to search from and all those sorts of things.
14:21 And so, it was a lot of books and a lot of user groups.
14:25 Not user groups.
14:25 Like, Usenet groups, whatever those were called.
14:28 So, there was a lot of, like, reference research stuff in the early days for me as well.
14:34 And I wish there was Google.
14:35 I could have done a lot more effective Google searching.
14:38 But certainly, I think that that is a just past stage one of your career.
14:42 This is a reasonable way to see the world.
14:44 But you're right.
14:45 It's absolutely a skill.
14:46 And the more effective you can be at narrowing in, the better.
14:51 But then I think it actually is, if people are living that life now, like, I'm Googling all the time.
14:56 This just must be, like, the rest of my life, I'm going to just do this.
14:59 That won't be the way it is.
15:00 Yeah.
15:01 I'm thinking back in my memory.
15:02 When I learned to program, there was no internet.
15:05 So, there was, or if there was, I didn't have access to it.
15:10 So, early 90s, late 80s, it was books.
15:14 So, I had references.
15:15 And still, even through my career, early career, I had a couple books that I would rely on because I knew how to look things up quickly.
15:24 So, I had, like, for instance, I had, like, a sticky note right where the, like, the printf translator thing.
15:31 So, if I knew how to printf and scanf, what those little percent signs were and all that stuff.
15:37 Yeah.
15:37 That's a really good point.
15:38 Yeah.
15:39 So, I remember my, I had a C++ primer or something like that.
15:44 And, boy, that thing was all tattered.
15:46 And I used that a lot as well.
15:48 Yeah.
15:48 Yeah.
15:48 But it's not that way either.
15:50 It doesn't matter whether it's a book or Google or whatever.
15:52 It's a phase, but it's not all of coding for the rest of your career.
15:57 Right.
15:58 And then there's stuff that you just end up remembering that you, like, I'm never going to remember this.
16:02 I know I'm going to always have to look this up.
16:04 Right.
16:04 Because there's some block, like printf decoders and stuff like that.
16:08 Yeah, exactly.
16:08 Yeah.
16:09 Like, the stuff for parsing strings and to dates, like, that is not, that is always a Google search for me.
16:14 Because I'm just, I'm not going to remember all the details there.
16:17 Yeah.
16:17 This next one, if I were to set this up, this would definitely be a Google search for me as well.
16:21 So, I'm considering setting it.
16:23 But luckily, I don't have to Google search it because we're covering the show.
16:26 And Chris Moffitt is covering it.
16:28 He wrote it all up for us.
16:29 So, Chris Moffitt wrote an article.
16:31 He's been on Talk Python before.
16:34 And he wrote an article called Using WSL to Build a Python Development Environment on Windows.
16:39 So, WSL is Windows Subsystem for Linux.
16:42 Okay.
16:43 And this is interesting to me because I just recently had this experience where I finally broke down and I decided I've been using Parallels on my Mac.
16:52 And I have a super fast Mac, like a i9 with six cores.
16:56 So, it should be able to run virtual machines just fine.
16:59 And yet, still, when you're working in Windows, you're working in any of the virtual machines, like even a virtualized macOS, it's still like the scrolling's a little bit off.
17:07 Like the keyboard's just tiny bits of late.
17:10 There's just a little bit where it just doesn't feel good to work there, right?
17:15 You can totally do it, but it's kind of, you can tell it's not a perfect experience.
17:20 So, I finally broke down and installed Windows and Boot Camp so I can boot into Windows and have a true native experience or just keep booting into my macOS and have that.
17:29 And that is a lot nicer.
17:31 But one of the reasons I don't want to go to Windows is I really love the terminal in macOS way more than even on Linux.
17:37 It's just super nice.
17:40 And some of the tools you have there are like in deployment on Linux machines.
17:45 So, you have this sort of closer to production world, but you have a nice OS with like GUI tools and little widgets and whatnot with macOS.
17:54 And I was thinking, you know, it's not really fair to Windows to like stick it into this little crummy system.
17:58 So, it's nice to have this other option, but I don't want to go there and do development because I don't have this Linux type system, right?
18:06 It's a nice terminal.
18:07 So, what Chris talked about is basically how to set up Windows subsystem for Linux.
18:12 And there's a new version that came out mid last year called WSL2 that is a lot better, especially around file performance and IO and sharing and like crossing over between Windows and Ubuntu or whatever you choose to run.
18:26 Oh, cool.
18:27 Do you do this any?
18:27 So, I tried it really early on and I haven't tried it since WSL2 is out.
18:32 Yeah, it sounds like it might be worthwhile.
18:34 So, if you look at this thing Chris wrote, he talks about, you know, there's like a little motivation of how it runs and whatnot.
18:41 It'll give people the lowdown.
18:42 But mostly, it's like a step to a guide of how to set up the various things you want.
18:48 So, for example, if you want to be able to have a nice terminal on the Windows side, but then that can talk to the Windows subsystem.
18:57 It talks about installing the new Windows terminal, which we already covered it recently.
19:01 It talks about getting Ubuntu from the store, how to upgrade old WSL installations to like the version 2.
19:08 Also, how you can set it up to use Visual Studio code in Windows that is actually like working on the Windows subsystem for Linux.
19:18 So, like you fire up VS Code and you're doing your work and then one of the environments you could choose is like a WSL environment that's actually running on an ultra lightweight version of Linux.
19:29 So, you know, when you get the little terminal and VS Code and you type over there, right?
19:33 It's running Linux commands, but on your machine still.
19:36 Without a VM.
19:37 I mean, sort of a VM, but not really.
19:39 It's like halfway between Docker and full VMs.
19:42 This looks nice.
19:42 So, what I am usually doing is, I'll have to try this out again.
19:47 But I agree with you that I like to pretend I don't have Windows.
19:52 But I do.
19:53 I mean, my day job, I work on a Windows machine.
19:55 So, maybe this is extra helpful for you because you're going to be there anyway, right?
19:58 Yeah.
19:59 But I mean, so I've already worked around most of it.
20:01 So, I use Git.
20:03 So, Git for Windows comes with Git Bash command, which is kind of have both of them.
20:10 You can do Windows stuff and work around in Bash.
20:12 And it sort of feels like Unix environment.
20:14 Nice.
20:15 Well, I'm very excited about the possibility of just having native feeling OhMyZ shell on Windows.
20:22 Oh, yeah.
20:22 That's going to be nice.
20:23 Yeah.
20:24 Well, and I hope this is a direction.
20:25 I think it is that this WSL stuff is just more and more integrated with the rest of Windows.
20:32 Yeah, the integration is pretty sweet.
20:33 So, if you're in WSL, which is effectively like you're in Ubuntu, right?
20:37 You can type Explorer on the terminal and it will open up the Windows Explorer in that folder, in the Linux folder.
20:45 But it will open up the Windows Explorer, the native file stuff, right?
20:50 On Windows and things like that.
20:52 So, the integration is pretty sweet now, which is what I was thinking is worthwhile.
20:56 Also, to start up this WSL, it's like one second.
20:59 So, it basically feels like starting a sluggish terminal.
21:03 Oh.
21:04 Yeah, it's not bad.
21:06 Right?
21:06 Then it's up and running, right?
21:07 Yeah.
21:07 Anyway, so this is a really cool breakdown of how Chris is working and the various tools, like the various plugins for VS Code and how he configured them to make them all work together and stuff.
21:17 So, if this workflow sounds interesting and useful to you, check out the article.
21:22 It's got a bunch of details and screenshots on how to do it.
21:24 And it's not really worth going into those.
21:26 But I think it's a cool idea.
21:28 And I just want to give a shout out to WSL2 and doing Python on it.
21:32 Yeah, very neat.
21:33 You got a solid one for us, huh?
21:34 We've kind of kicked this can down the road a few times, but I thought we'd take a crack at it.
21:39 There was an article written by Derek D called A Pythonic Guide to Solid Design Principles.
21:47 Are you familiar with what the solid principles are?
21:50 Single responsibility, open-closed, Liskov substitution in something, and dependency injection.
21:57 I forgot what the I is.
22:02 I is Interface Segregation Principle.
22:04 There you go.
22:04 Okay.
22:04 I had to look on that one.
22:06 I cheated.
22:06 I always have to look it up.
22:08 But I was curious.
22:10 So, the article is interesting.
22:12 It's an interesting article.
22:13 So, the idea is taking all these principles.
22:16 And I'm going to have to go through and spell check these.
22:20 But anyway, I don't even know where these came from.
22:23 But this idea that if you're doing object-oriented design, you should have solid object-oriented design.
22:29 I don't know if I completely buy it.
22:31 Actually, I'm pretty sure that I don't.
22:34 But this article goes in and also talks about, kind of relates each one to the Zen of Python as well.
22:41 And sometimes it's a little bit of a stretch.
22:43 And then also just really how to apply these principles in programming and coding in Python.
22:51 I guess I'll just say, my take on solid design principles are, there are things that are good to know about.
22:58 And there's lots of different design principles to know about.
23:01 And these are some of them.
23:02 And in developing object systems with objects, and all Python uses objects, whether you think it does or not.
23:10 If you look at some code and it's hard to maintain, or it already is hard to maintain, maybe some of these principles might help refactor so that it's in a better state.
23:21 But blindly following these rules, actually, I think could possibly make your code even worse, is my take on it.
23:30 Yeah.
23:30 Well, I'm a big fan of design patterns, actually.
23:32 I really love the concept of design patterns.
23:35 And one of the things I love about them is, once you start to think of code in design patterns, you can think of trade-offs in higher-level building blocks than just functions.
23:46 Or here's a class.
23:47 You can think, oh, this is going to be an interface.
23:50 And so what that means is, here's a benefit, and here's a drawback.
23:53 And do we want to go down that path, right?
23:55 Or I like that it lets you think in bigger abstractions than just lines of code or functions.
24:01 So I'm a huge fan of that.
24:03 But one problem that I've seen a lot when people adopt design, first, when they learn design patterns, they become super passionate.
24:09 Like, oh, my gosh, this is so awesome.
24:11 It could be so easy to go, all right, well, these are going into everything.
24:15 Like, every chance I can get to use the visitor pattern, it's going in.
24:19 And you're like, wait, wait, wait, wait.
24:20 The visitor pattern is super complicated.
24:22 And it solves a cool problem, but it is really not obvious or easy to maintain.
24:28 The problem it solves had better be glaring and massive, or you're just making it worse.
24:33 And so I see this kind of stuff as salt and pepper and paprika.
24:37 It's code is better with it.
24:40 But that doesn't mean it should be ultra doused at it.
24:44 You know what I mean?
24:44 Because then it's not better anymore.
24:46 It's all of a sudden, like, this is a really cool study and design patterns.
24:50 I have no idea what's going on.
24:52 Like, for example, dependency injection.
24:53 Like, there's a few places where dependency injection, like, at certain layers might be cool, and you could apply it.
24:59 And it's really neat.
25:00 But if you do it everywhere, you're like, I have no idea what anything is or how any of them get to each other.
25:04 I just know that this is a complete mess.
25:06 And I need a debugger to even figure out what's happening all the time.
25:10 And, like, that's kind of my feeling about solid, especially in Python.
25:14 It's definitely my feeling about design patterns.
25:15 What do you think?
25:16 I definitely have to agree.
25:17 And one of the things that, well, I think I agree.
25:21 Both design patterns and the idea around solid are, they were really developed for other languages.
25:29 I don't think, they're definitely not the first tools that I reach for for making Python more maintainable and design better.
25:37 Like, for instance, the, like you mentioned, dependency injection.
25:41 This is, as far as I can tell, dependency injection should be used very sparingly in Python.
25:47 And there are great, great ways to examples.
25:51 Like, for instance, in an application where you don't want to depend on a particular database style or database, you can set up the database configuration early on and then pass that to the system.
26:04 But the problems with looking up, if you want to know more about solid and more about design patterns, almost all the examples are going to be not appropriate for Python because they're going to be like, you know, Java examples or C# examples or something.
26:19 Right.
26:19 Static language examples.
26:21 Yeah.
26:22 Yeah.
26:22 I also think that they get, the way they get used, they get used in this like overly general, overcomplicated way.
26:28 So, for example, dependency injection.
26:30 I've got something that I can maybe have a data access layer and I want to be able to configure the type of database access it uses.
26:37 And I want to be able to configure the logging messages that it can send or whether or not it logs to a file or at all.
26:43 Right.
26:43 You could take that and require everyone to always pass a database core instance to it and always pass a logger thing to it.
26:51 Or you could just have the data access layer have defaults and then you override them only if you need to, usually in testing.
26:58 So you can set them up so you always have to feel the pain of this structure or you can set them up so you only even know that it exists if you need to look into it and change it.
27:08 And I find a lot of times it gets used in the hard way only.
27:11 But the problem is there's like a little bit of hard here and a little bit of hard there.
27:16 Then you compose it.
27:16 It's a little bit more hard.
27:17 And at the top, you're like, we need 20 things to like create this class and get it started.
27:21 And I don't even know what they're for.
27:23 They've got to be passed way down.
27:24 And like, now we need IOC.
27:26 Now I can't figure out where stuff is coming.
27:28 There's just a lot of like layers that it adds on.
27:31 So, I don't know.
27:31 Salt, I think, is my best, like spice.
27:34 Yeah.
27:34 And sometimes simple is good.
27:36 Sometimes just a cookie is good.
27:37 Yeah.
27:38 Well, you're right.
27:39 And you can always.
27:39 Sorry, cookie is good.
27:41 You can always start with just write it the simple way and then add the stuff if you need it.
27:46 Right.
27:46 Are you really feeling the pain that these kind of patterns would solve?
27:51 Okay.
27:51 Bring it in.
27:52 Right.
27:52 Got refactoring tools.
27:53 Got tests.
27:54 Right.
27:54 Yeah.
27:55 And the other thing with the I mean, solid includes things like the list of substitutability principle.
28:01 How arrogant does that sound?
28:03 I mean, it's one of the things that just I have a problem with is it just it reeks of I'm smarter than you because I know about this stuff.
28:11 Yeah.
28:12 I just don't like that.
28:13 But yeah.
28:14 Yeah.
28:14 Yeah.
28:14 Yeah.
28:15 Yeah.
28:15 It's cool article, though.
28:16 And the solid principles are good to know.
28:18 Even if you're not using them everywhere, it's good to know, like, these are some design principles and I'm choosing to use them here and I'm choosing not to use them there.
28:26 Yeah.
28:26 Because, right?
28:27 Yeah.
28:27 Do it consciously, right?
28:28 Definitely.
28:29 Speaking of making choices and tradeoffs, Instagram wrote a cool article recently that I thought would be fun to cover because it's a look inside how they're running their Django app.
28:40 They want to basically take typed Python, like type annotations, which they're loving, right?
28:46 They actually did a PyCon presentation or I don't know if it's officially under Instagram, but Lucas Lenga covered basically how they're using types to add Instagram when he was there.
28:58 And that was really, really interesting.
29:00 But they're like, look, we have a few HTTP endpoints.
29:04 They've talked about how they're not doing microservices.
29:07 They have a single Django app and it has a few thousand HTTP endpoints in the one app on top of other stuff.
29:14 Wow.
29:15 That is a lot of API endpoints.
29:17 Yeah.
29:18 And they all exchange like rich types with validation.
29:21 And so they asked the question, you know, are methods in code have type annotations?
29:30 We can check that with mypy and stuff like that.
29:34 But how do we have developers know whether their APIs are still matching what they should be?
29:42 Because everything returns a JSON result or JSON response.
29:45 Everything takes an HTTP post or a JSON object.
29:49 And like, what are you going to do with that?
29:50 Right.
29:50 So they went on this mission to try to add this typing to their API.
29:55 So they came up with this decorator that they can put on a regular typed method that converts it to an HTTP endpoint in Django.
30:03 Okay.
30:04 Right.
30:04 So I've got a regular function.
30:05 It just, it declares its variables.
30:07 It declares they're of this certain type.
30:09 It returns them of another type.
30:10 And you just decorate this thing.
30:12 And boom, it becomes an HTTP endpoint that returns JSON based on what it exchanges JSON based on what comes in and what goes out, which is pretty cool.
30:20 So that's a start.
30:21 So that's a start.
30:21 And it says, well, you're still just returning JSON responses.
30:24 So how do you get better validation than that?
30:26 So they decided to start using data classes or data exchange because data classes have a type.
30:33 They can be immutable because you can set the frozen decorator on them.
30:37 Yeah.
30:37 They have a type validation through things like mypy and whatnot, which is all really cool.
30:42 But remember, they have millions of lines of code and thousands of endpoints in a single Django app.
30:49 And they're not going to go, well, you know what?
30:50 We're going to upgrade every single interaction to these data classes, right?
30:53 There's a bunch of dictionaries still going around.
30:55 So have you heard about typed dict?
30:58 Yeah, it's neat.
30:59 Yeah, it's really cool.
31:00 So that comes out as one of the mypy extensions.
31:02 And it lets you create a dictionary, but then also express the types.
31:06 Like this key is supposed to be an integer and this key is supposed to be a date.
31:09 And so for the older code that couldn't be written with data classes, what was just dictionaries,
31:15 they added in typed dicks to help give validation to that and type explicit type definitions.
31:22 Instead of saying this thing returns a dict, it can return a type that is a type dict,
31:26 but still is compatible with the API.
31:27 So that's pretty cool, right?
31:28 Yeah, this is interesting.
31:30 Yeah, it's super interesting.
31:31 And so they also talked about how do we dot.
31:32 So once we have these APIs and they have types and they have type validation,
31:37 how do we communicate that back to people?
31:39 So they leverage open API to come up with very nice documentation.
31:45 If you got the article open, Brian, you could scroll down and you can see like a very beautiful
31:48 like API reference that was just automatically generated out of the API methods.
31:53 Yeah, open API is really nice.
31:55 Yeah, so that's really cool.
31:56 Now, what's also interesting is they go through this whole process of what they've done and
32:01 how they've done it.
32:02 And this is on Medium implicitly.
32:05 It's on their blog, but their blog is running on Medium.
32:07 So you can go and see the comments in there.
32:10 And a lot of people are like, hey, this is cool.
32:12 Why don't you use Pydantic?
32:13 Which we've covered Pydantic before.
32:15 It solves many of these problems for data exchange and validation.
32:19 Another person like, you should use FastAPI because FastAPI has this typed API methods
32:24 natively at the boundary.
32:26 You don't have to like have this decorator that'll transform them into Django.
32:30 That's really cool.
32:32 But all of these are like, hey, I know you have a couple million lines of code
32:36 for like a huge, huge project in production.
32:39 Why don't you rewrite that in FastAPI?
32:41 No, right?
32:42 That's just not going to happen.
32:43 They're already in Django.
32:44 I mean, yeah.
32:45 I was thinking, oh, it's kind of like FastAPI, except for they're in Django.
32:48 So it's different.
32:49 Yeah, exactly.
32:50 I mean, who wants to take on the job of rewriting the entire millions of lines of code when they've
32:55 just gone through the process of going, upgrading Django and upgrading from Python 2 to 3 and
33:00 so on.
33:01 So there's a bunch of interesting comments about alternative ways to solve this problem
33:05 if you were starting from scratch.
33:07 Yeah.
33:07 But I think it's also interesting to think about that.
33:10 Now, one thing that did come out that they could use, somebody said, this is cool.
33:14 And if you have typed APIs and nice documentation and you're already using OpenAPI, why don't
33:20 you check out Schema Thesis?
33:23 Schema Thesis.
33:24 Schema Thesis.
33:25 Schema Thesis.
33:25 Schema Thesis.
33:26 So it's a tool for testing your web apps based on their API definition.
33:32 So it goes in reverse.
33:34 It looks at the documentation and it says, okay, we're going to call your endpoint according
33:39 to the documentation and see if it really matches that or not.
33:42 Yeah, it's really cool, actually.
33:44 Yeah.
33:44 So I think that that's actually pretty neat.
33:46 I've never used this.
33:47 Can't necessarily recommend it, but it seems pretty interesting if you've already got the
33:51 OpenAPI stuff in place.
33:52 So I like that.
33:53 Yeah, Alexander Holtner brought it up, the Schema Thesis project up when I talked to him
33:59 on testing code 107.
34:00 And it sounds pretty neat.
34:02 Yeah, yeah.
34:02 Very cool.
34:03 All right.
34:03 Well, that's it for our main items.
34:05 Brian, you got anything else you want to share with folks?
34:07 One of the things we've done for the past couple of episodes is talk about the current COVID-19
34:13 stuff and working from home.
34:15 We didn't mention that at the beginning, but I've got like, actually, I wanted to just take
34:20 this section to bring up some things that I'm running into.
34:23 And I'm curious if any of our listeners have some comments, but I'm curious about you as
34:28 well, if you have any suggestions.
34:30 So you don't normally switch between Windows and Mac.
34:33 Is that correct?
34:34 No, not usually.
34:35 And if I'm actually, if I told you, I just built, got bootcamp booting into it.
34:40 And it's driving me crazy because even when I was using parallels, I remapped control
34:45 C to be command C. So even in Windows, I could do command C, command V.
34:50 And in Windows, I could do command W to close a window.
34:53 But now I got to do alt F4.
34:55 But oh yeah, the crazy touch bar thing doesn't have function key.
35:00 So now how to do alt F4 with no function key?
35:02 Like there's just a bunch of like, yeah, it's, it's a challenge if I'm not running in a VM.
35:07 So yes.
35:08 Okay. So I've got two laptops for one of them runs Windows.
35:11 One of them's running Mac. It's a Mac.
35:13 And so I've got my setup with my, like my monitor and my keyboard and everything.
35:18 And I can switch between them.
35:20 I would love to have just a magic switch, but apparently USB switches don't happen.
35:26 So I just plug in the USB-C from one to the other.
35:30 So if anybody's got a switch that they know about, great.
35:33 But I don't want to pay like a thousand dollars.
35:35 I was thinking like 50.
35:37 Anyway, what I'm noticing is this whole, the control C thing.
35:40 So on Mac, it's command C, command V, all that stuff.
35:44 It's great.
35:45 And then it's control.
35:46 That's the thing I'm messing up is the copy and paste and all that stuff is different on the two.
35:52 So any idea?
35:53 Is it easier to, can you remap on a Mac?
35:57 Can you make it do control C and control V also?
36:00 I think so.
36:00 I'm pretty sure you can.
36:01 You can go.
36:02 One thing that I do all the time on the Mac is if you go to the keyboard preferences.
36:06 Okay.
36:06 And then you can go in there, you can go to shortcuts.
36:08 And so I'll like go to that, like app shortcuts.
36:11 So if you go to app shortcuts, you could add a new one.
36:14 You could pick all apps or just one.
36:17 So you could go and say edit means, you know, paste means this, copy means that.
36:22 And it might not always work.
36:23 You might have to add it for different apps because it has to match the menu item exactly.
36:28 So if one is like, I don't know, copy and paste or I don't know, like paste with a capital P or lower P or a dot, dot, dot, or not a dot, dot, dot.
36:36 Those would not be compatible, but you could go in there and add the shortcuts and just say control, control V means paste or paste dot, dot, dot, or capital P paste or whatever you got to do for a few of them.
36:47 And then I bet you could map it over like that.
36:50 But the other thing that you could do that I used for a little while is I had a Windows machine and a Mac at the same time on two different computers.
36:59 And I set up a, like a network KVM, which is kind of what you're talking about.
37:04 And it lets you actually just have two monitors on two computers side by side.
37:08 And the mouse will just move straight across from one to the other computer, like without changing stuff.
37:13 So there's a place called share mouse.com.
37:16 I cannot recommend it.
37:17 I've never used it.
37:17 I can't seem to find the one that I used to search for and use back like five years ago, but like a network KVM switch is what you want or something like that.
37:27 So check that out.
37:27 That might let you like actually have both at the same time.
37:30 Maybe you can remap command to control across that as well.
37:34 Okay.
37:35 The other thing is, so we're on episode 177, right?
37:38 We've done all these, most of these episodes where I'm using a laptop and now I'm using a monitor.
37:45 Is it distracting to do, and it's nicer to me to look at you while I'm talking, but is it distracting to see somebody looking sideways while you're talking?
37:57 Right, right.
37:57 Because your camera's on your laptop.
37:59 Yeah.
37:59 But your main high risk monitor is in front of you without it.
38:03 Right.
38:03 It's not distracting to me because I'm used to it.
38:05 There's so many video calls that I'm in these days where it's some sort of setup like that.
38:11 Okay.
38:11 I think I'm just overtaking it personally.
38:13 The person never looks at me.
38:14 Or you just don't really like the way I look and you're always like, oh, geez.
38:18 No, I'm just kidding.
38:20 Okay.
38:20 No, I think it's okay.
38:21 I do have a Logitech.
38:23 I have my MacBook and it would be off to the side as well where the camera is, but I got a little USB camera to go at the top.
38:29 Okay.
38:30 Maybe I'll get a USB camera.
38:31 Yeah.
38:32 Who knows?
38:32 But okay.
38:33 Anyway, that was it.
38:34 And also, for some reason, I've got an hour and a half extra with no commute time, but I don't know where it goes.
38:40 I don't seem to have more time in the day.
38:42 I seem to have less time.
38:44 Yeah.
38:45 Anyway.
38:46 Maybe you're more accessible.
38:47 I mean, you used to be kind of accessible to the people who were near you.
38:51 Now the entire company has equal access to you and your time, right?
38:56 Yeah.
38:57 I booked it on your Outlook calendar.
38:59 Oh no, not my Outlook calendar.
39:00 I don't even look at that.
39:01 Yeah.
39:03 Anyway.
39:03 Okay.
39:03 So enough about me.
39:04 I don't know where my time goes either, but yeah.
39:07 Although I don't have more.
39:08 I've lost getting used to that.
39:10 Although I did have to drive my daughter to school and sometimes, and that time is back.
39:15 So yeah, I guess I have some time as well.
39:16 I have a quick follow-up really, really quick.
39:19 So we talked about SuperString and their benchmarks last week.
39:22 The benchmark showing that SuperString is much faster on Python and lower memory usage on Python
39:28 for a bunch of operations and whatnot.
39:31 And I convinced Matt Harrison to cover it and whatnot.
39:35 But on Twitter, a couple of people were like, hey, I looked at the code and I don't really
39:39 know where the memory improvements are coming from.
39:42 If you look at the benchmark stuff, honestly, I don't know how much better it is or isn't.
39:47 I haven't dug super deep into it.
39:49 But it looks like a lot of the improvements in speed are around slices and new string creation
39:55 is not necessarily that much better.
39:57 Anyway, I just wanted to link to a conversation with Anthony Sotili and a few other folks who
40:03 are chatting about that.
40:04 So might want to jump in if you really care about SuperString.
40:07 Yeah.
40:08 And also, I'm glad you brought it up because I really love that people are calling us on
40:12 stuff.
40:12 People will pay attention and go, hey, wait a second.
40:16 You covered something.
40:17 And I don't think that it's as cool as you think it is.
40:20 That's why we have awesome listeners.
40:23 Usually, the feedback is, you covered this one thing.
40:26 Did you know there are seven others like it that you've never heard of?
40:29 We're like, no.
40:30 Or why did you cover this other thing you don't know about?
40:32 Well, because I didn't know about it until now.
40:33 Yeah.
40:34 Are you ready for a joke?
40:35 I am so ready.
40:36 All right.
40:36 This one is a little bit, we've covered this before, but like 75 episodes ago or something
40:42 like that.
40:43 So I feel like it's okay to cover it again because I've talked a lot about Windows, Windows
40:47 Subsystem for Linux.
40:48 You just talked about the sharing keyboard around it.
40:52 So, you know, in all good nature joking at Windows, here's a joke.
40:56 So do you know how many programmers it takes to kill a cockroach?
40:59 No.
41:00 How many?
41:00 Two.
41:01 One holds, the other installs Windows on it.
41:05 That's funny.
41:05 It takes way more than one person to install Windows.
41:08 That's right.
41:09 Oh, fun.
41:13 All right.
41:13 Well.
41:13 That's good.
41:14 Good topics this week, Brian.
41:15 Thanks for sharing them and with everyone.
41:17 Thank you.
41:18 You bet.
41:18 Bye.
41:18 Bye.
41:19 Thank you for listening to Python Bytes.
41:21 Follow the show on Twitter via at Python Bytes.
41:23 That's Python Bytes as in B-Y-T-E-S.
41:26 And get the full show notes at pythonbytes.fm.
41:29 If you have a news item you want featured, just visit pythonbytes.fm and send it our way.
41:33 We're always on the lookout for sharing something cool.
41:36 On behalf of myself and Brian Okken, this is Michael Kennedy.
41:39 Thank you for listening and sharing this podcast with your friends and colleagues.