5

The Real Reason To ‘Learn To Code’? Automating Your Life

 2 years ago
source link: https://debugger.medium.com/the-real-reason-to-learn-to-code-automating-your-life-d8730796d168
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

The Real Reason To ‘Learn To Code’? Automating Your Life

On the joys of writing scripts that do scut work

1*FktCcTeiX1wikEVWz_FqMg.jpeg
“Robotic arm” by Dan Ruscoe

Last night I automated the tip of my index finger.

I was getting super annoyed by an infinite-scrolling site. I generally hate those: I’m a journalist, and every so often I’m a) doing research that b) requires me to go back several weeks, months or years on c) an infinite-scrolling site. So I have to sit there hitting “page down” or “end” over and over again.

Last night I had to do that at a couple of sites, and after a few minutes I got bored and decided: Screw it, I’m gonna automate this.

So I wrote a quick, tiny script using the programming language Python. The script does one simple thing: It hits the “end” button on my keyboard, waits two seconds, then hits it again. Here’s what it looks like …

Utterly simple! But it did the job. I started it running, flipped over to the site I was reading, and let the script hit “end” over and over, paging downwards and downwards, while I, like, mixed myself a cocktail. When I came back fifteen minutes later, the script had finally arrived at the bottom of the website.

“Don’t learn to code — Learn to automate”

1*_wRL2vgOwXmj3ILvA_XyHg.jpeg
The obligatory screenshot of coding, via Pixabay

I’m a very hazy, low-skill hobbyist programmer. I never studied any computer science.

I just learned stuff from online guides. I’d learn just enough to build simple web thingies for myself, or little twitter bots, or automated tools. My code projects are all quite rudimentary, but they help me accomplish some task — something in my job, or my personal life — more easily.

Which brings me to my point here:

Since I write about technology, every so often a friend will ask me — “Hey, should I learn to code?” Or: “Should I try and convince my kid to learn programming?”

My answer is twofold.

If you’re thinking you want to learn to program because you want to do it full-time — to change your career, and work as a developer — then sure, you could. But learning to develop software at that level isn’t easy. You have to reallywant to. I wouldn’t tell someone “no” outright, but if their goal is to shift full-time into software development, they should prepare for a really long period of transition. They’d ideally want to do some formal education, or at least block aside a year or two to make a serious transition.

So, it’s not something you’d do lightly.

But there’s a whole other possibility — which is to learn just a bit of coding.

This can have a surprisingly delightful impact on your life. Because while it’s hard to become a hard-core professional programmer, it’s quite easy to — like me — learn juusssssst enough to do something quite valuable:

To automate incredibly tedious, boring tasks in life.

One’s job, and one’s personal life, are frequently filled with boring and repetitive tasks that one does at a keyboard. And whenever you’re doing some that is both i) repetitive and ii) keyboard-based, it’s a task that some teensy scrap of computer code could probably do for you. Automate that task, and it’ll leave you more free time to do something fun, like mix yourself a drink.

The real joy of learning to code, it turns out, is in automating dull parts of your life.

The programmer Eric Dietrich put this beautifully a few years ago in a blog post, where he wrote

Don’t learn to code — learn to automate.

Automating my kids’ homework reminders, or checking my book’s ranking

1*KI7sC9jCdCuumGqUNYrUhQ.jpeg
via Pixabay

I’ve lost count of the number of weird little things I’ve automated.

When he was in grade 5, for example, my youngest son would get home from school, and he’d want to do his homework right away, so he could get it out of the way. But his teacher was quite slow in posting the homework to the class web site. So my son would sit there at his laptop, refreshing the page every so often, waiting to see when the homework would be posted. It wasted a lot of his time.

So I quickly cobbled together a little web-scraper program that would — at the end of each school day — check the class web site every two minutes, to see if the homework had posted. Once it saw the posted homework, it’d fire off a text message to my son. That way my son could read or play a game until ping, he got the alert saying the homework assignment was uploaded. (“I love this bot!!” he texted to me, the first day I started it running.)

I’ve written similar web-scraping tools for my own use. When my book Coders came out in 2019, I spent the first few days at my browser neurotically refreshing my Amazon page to see my sales ranking. (Most authors do this. It’s totally unhealthy, and it’s probably meaningless data; we do it anyway.)

Eventually I realized I was wasting entire workdays staring at Amazon. So instead I wrote a script that checked my sales rank twice a day — morning and evening — and texted it to me.

I automated my own neuroses! (It worked: I stopped staring at the page.)

Then last year I noticed I wasn’t reading international news often enough, because I’m lazy and self-centered, like most everyone else. So I wrote a little script on Glitch that grabs the foreign-news headlines from The New York Times, along with the précis of each piece, and emails it to me at 10 a.m. each morning. It worked; I started opening the email and clicking through to read more international pieces. I automated a bot to nag me.

These are little bits of code I run every day, but there are oodles more I write just to quickly solve some weird problem — bits of code I run once, then never again. For example, with my last book manuscript I worried I was using too many italics. (I really overuse them.) So I wrote a quick script to count them. (I think there were 1.5 per page. “You’re fine,” my editor said; phew.)

And then there are the whimsical little weird things I’ve created — like a text-only pomodoro timer (because I hate graphical ones), a twitter poetry bot, and a web app that strips out the words from a piece of your writing and shows you just the punctuation. Why? Hey, why not!

Programmers write personal scripts all the time

1*TwTPQboLkTlWIczclr0kAQ.jpeg
Anonymous hacker in a hoodie with 1s and 0s, total classic graphic, 12/10 would use again. Via pixabay

I’m not alone in my lust for micro-automation. All programmers do this.

I interviewed over 200 software developers for my book Coders, and they all told about the strange little scripts they’d written to automated odd, repeated tasks. Some had scripts that checked for their favorite TV shows on torrent sites every day and then auto-downloaded them. Some ran scripts to check daily for mentions of their company on Twitter or Reddit and copy them to a spreadsheet. One had a script that checked on a solar panel’s output and texted it to him every day. (“It just made me feel good.”)

They all took enormous joy in writing these little daily optimizers. Computers are deathless obedient robots; they’re more precise than we are, don’t get bored as we do, and can work to precise schedules (while we space out and forget). Getting them to do the scut work, whenever possible, lets you become the best kind of cyborg.

I often suspect this sort of scut-work scripting is actually a large chunk of all software that gets written.

People often think of “coding” as “making apps”. But programmers spend a tonof time writing little scripts like this. Maybe it’s a script for work, to clean up a bunch of data and format it into laid-out PDFs. Maybe it’s a script to daily reboot the server that mysteriously crashes if it isn’t preemptively rebooted once a day. Either way, a lot of “coding” is precisely this sort of thing: a couple of lines here, a couple of lines there.

Code for an audience of one

Three other observations about this part of the coding ecosystem …

One thing is that it’s often software written for an audience of one.

Again, we tend to think of “software development” as “making an app that a billion people use!!” But this automate-my-life code is often written to solve one person’s particular problem.

It’s also often disposable: a script that you run once, and once only, and then toss aside afterwards.

Code that’s often incredibly simple, easy for hobbyists

This ocean of scripting code? It’s often not very complex or hard to write.

I mean, when I dashed off that little script to figure out how many italics were in my book manuscript, it was only 13 lines of code (super baggy; someone else could do this in probably a single line, lol, but I was in a rush) …

Some of the most incredibly useful code often isn’t rocket science. It’s drop-dead simple scripts like these.

This is why it’s low-hanging fruit for dabblers and hobbyist coders. Again, I’m the type of hacker who learns just enough — and no more — to solve a problem I’ve got.

But that turns out to be more than sufficient to automate a lot of boring things!

Easier to do with no-code and low-code tools

0*NMLpROdazD8RabIX.jpg

You don’t even need to know how to write code to do this.

These days, there are lots of low-code and no-code tools that let you script away all sorts of dull, repetitive tasks. One of the most venerable is If This Then That, but these days there are tons more — like Zapier, or Workflows on iOS, or bits of JavaScript and filtering in Gmail, or Power Automate on Windows and Automator on macOS.

If you wanted to learn a little bit of coding, a super powerful and comparatively easy language is Python — and there’s even a terrific for-beginners book called Automate the Boring Stuff With Python, by Al Sweigart. It’s free to read online, though you can buy a print copy if you want.

Why learn programming? To avoid doing boring, repetitive tasks

So this, ultimately, is the reason to learn a bit of programming.

It’s not necessarily to suddenly change your career and become a software developer.

It’s to acquire fun and useful superpowers. Maybe part of your job requires you, once a week, to take every dollar figure from a Word doc your boss sends you about weekly sales, and put those figures into a spreadsheet? Maybe that takes you 15 minutes a week? You could write a little Python script that would do it in about half a second, every time. Or say you need to keep on top of price changes of something you want to buy online? You could use a no-code web-scraping tool to automate it too.

Eric Dietrich nailed it: “Don’t learn to code — learn to automate.”


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK