How I automate repetitive work

What I did to make a boring repetitive task fun.

Most of us have probably had colleagues that seem astronomically good at coding and solving issues. Their workflows just seem optimized.

Well, it often comes down to how they manage what is fun and and what is not fun, then streamlining it by eliminating repetitive or boring tasks.

A couple of months back, a codebase I was working with, had restructured the main files to follow a “feature-by-folder” approach. One issue I noticed, was that not all of the tests matched the main file structure.

I thought about the two ways to solve it…

  1. Manually finding and moving the files
  2. Writing a script

Then I thought, will I be doing this in the future and will it be fun? Well, no it won’t.

So I decided to go with the second approach and automate it.

The problem

Let me first give you an example so you can better understand the problem.

Let’s say you have a file in the following path with a test in the same mirrored structure.

lib/features/home/home_page.dart

test/features/home/home_page_test.dart

You later end up changing the location of the main file. lib/home/home_page.dart

But you forgot to move the test file and it remains in the old folder structure. test/features/home/home_page_test.dart

After a year in a codebase you realize you have 40 or more of these same issues.

Let me show you how I solved it, and why it mattered.

Course thumbnail

Want to learn Flutter?

We teach you all you need to confidently build apps at hungrimind.com/learn/flutter

The story

As I said, the codebase had been refactored to have new file paths, due to a legacy part of the codebase being updated to a “folder-by-feature” structure.

Well this caused the previously mentioned issues of main files and test files not being in sync in relation to the folder structure.

So I started to work on a script

After around 20 minutes of work I had something functional. It was still a bit buggy. Some of the files would not correctly move to the new file path.

Another 15 minutes and it’s working.

example gif

Here I have a fully mirrored file with it’s corresponding test file. If I move the file and keep the test file location they will now be out of sync.

Now, going to the terminal and executing sync_test it will look for all matching test files with the real implementation file and mirror all the test files to have the new structure.

Now I have a working solution that fixes my current problem and I can reuse it whenever in the future.

Is it perfect?

No.

Does it reduce 80% of the overall work?

Yes.

Now what?

So just the act of doing something like this, you will start to see over-time that you will have quite a few solutions for your own workflow that makes certain boring tasks fun and efficient.

If you want to try it out on your codebase, you can clone it with the github link and run make install

Bottom line, optimize for fun and efficiency

Get articles right in your inbox

No spam, unsubscribe anytime. We treat your inbox with respect.