DEV Community

Connor Gladwin
Connor Gladwin

Posted on

Python and the Art of Laziness

I'd read somewhere that developers are lazy. It's an old joke passed around, most likely stemming from a quote often miscredited to Bill Gates: "I will always choose a lazy person to do a difficult job because a lazy person will find an easy way to do it."

Now this may be true for some, but when I rediscovered my love for coding I dismissed this, I wasn't going to be lazy, I was going to be a productive dev, a 10x. I'm now just over a year into my journey, having learned python through a bootcamp, and I'm currently teaching myself JavaScript. I have been on this journey for a whole year, rarely taking a day off, and all I can say is that it makes you lazy. And thus was the impetus for this piece.

The real catalyst for the subject was when I found myself opening the four apps I use most when writing code, namely VS Code, GitHub Desktop, Chrome Canary and Hyper Terminal.

Now I understand that it's just four apps, it's really not that difficult, yet I still huffed and rolled my eyes whenever I had to do it. The thought had then occurred to me: "There must be an easier way to do this", and this was the seed. It was small, I could've shrugged it off and continued the way I had for the past months, but I gave it a bit of heed and thus the result was what I've called my DevStart.

The more I thought about it, the more excited I got, I could finally put what I'd learned to good use, to build something that I could use to solve a problem I was having in my daily routine.

When starting I knew I would have to access the os using python, with import os first step was done. Next I knew that there was a way to open files using python, but I didn't know how to open a program, and after a bit of digging I found some rather verbose and overcomplicated ways of doing it, importing a whole host of modules to get this done. I did try one or two, but they never worked, throwing error after error. This lead me to what I do whenever I run into an issue with my JS, and something that I've taken to be something like a mantra... "Just go look at the docs".

After a lot of searching and punching keywords that were relevant to my goal into the search bar I came across the function os.startFile(), into which you plug the path to your apps exe. The code ended up looking like this (paths removed):

import os

os.startFile(path to VS Code)
os.startFile(path to Hyper Terminal)
os.startFile(path to GitHub Desktop)
os.startFile(path to Chrome Canary)
Enter fullscreen mode Exit fullscreen mode

I typed all this out, and upon running the file it worked smoothly. Great! Job done! Not quite. I didn't want to have to open one program, only to have it open another three, my aim was to make this as easy as possible. And making it as easy as possible meant making my new little script work like an executable.

To do this I created a batch file, which looks like this:

Enter fullscreen mode Exit fullscreen mode

Creating the batch file was relatively easy, create a new file in your editor and save it as a .bat file. Now what this does is starts IDLE, which then runs the python script and presto, we have four apps open.

I do understand that I spent probably ten times the amount of time automating a process that takes me about 30 seconds, but I'm not going lie and say I wasn't impressed with myself. It was shortly after I had gotten it to work, while I was showing it off to a friend, that the quote drifted into my mind, I now understood the core of it. It's less about being lazy, and more about being efficient, finding a way to remove the small tasks that aren't helping you be productive, or minimizing unproductive behavior. I've tried to implement this into the way I work, "how do I get the job done, to the best of my ability, using minimal effort". What this has done is develop a better problem solving mindset.

I hope you enjoyed my delve into "laziness", you might even find that you're able to use my script to your own advantage.

Thanks for reading!

Top comments (0)