How Unix programs save me time
In the last six months or so, I’ve been delving into minimalist programs provided in my distributions default packages. By minimalist programs, I mean that they do one task well, and interact with other programs, just as the Unix Philosophy dictates. They are extensible, and become more useful when interacting with other programs. By doing so, they never need to duplicate features of other programs.
I’m going to exemplify how utilizing Unix based programs saved me countless development hours in just one project.
The Project Requirements
I had to write a program that used puppeteer to load in websites, take screenshots, and present them to the end user. The end user would then sift through these screenshots, opting to save ones that contained useful information.
Where software development generally begins
For most teams I’ve worked with, the project would usually be broken into the following steps:
- Make an interface that allows the user to start a job of screenshots
- Control puppeteer to navigate to relevant pages of sites to take screenshots
- Make an interface that presents the screenshots to the user as thumbnails, and allows them to select images they need
This can be completed a few different ways, and it’s common to see a team take on the responsibility of producing both interfaces for the project and the internal program required to run puppeteer, and packaging it all into one final program.
Finish in half the time with Unix
We can do better than this monolithic approach. To start, the Unix Philosophy will tell us: image viewers should be image viewers. Why take the time to build an image viewing application, however small, if one already exists?
By utilizing existing applications we can reduce redundant code, and keep end users in a consistent workflow. If end users only have to learn one image viewer their onboarding process is faster too!
Take sxiv for a spin
For this project, sxiv solves all requirements.
This image viewer works well as a standalone program, but gets extra mileage from how it interacts with other programs. One of its best features comes from its integration with standard input and standard output. If you are familiar with writing POSIX scripts, you already know why this is helpful.
In sxiv, users can also select images from what is opened, and upon exit, sxiv will send all their paths to standard out.
We can write our program to screenshot images from the web, save them to
/tmp on the file system, and open the files in sxiv for the user to cull. Finally, sxiv outputs the selected image filenames to stdout, perhaps giving them to
mv so they are saved in a permanent directory.
Why is this “minimal” and not just “faster development”
By using an image viewer that is extensible with other programs, we saved all the time it would have required to develop an application that supports image viewing, and selection.
The reason that this is minimal has less to do with the fact that we saved development time, and more so to do with the fact that we did so by utilizing a program that every modern computer would likely need anyway. This is how it differs from say, downloading a NodeJS library that has the functionality required. In that case, we would be duplicating features on the target machine, when we could instead have one program that is dedicated to interacting with images.
Next: Error Handling in Rust and Go
Previous: Code Formatting in Neovim for Beginners