Tips for Optimizing Your Workflow

Aglensmith
BigCommerce Developer Blog
6 min readApr 8, 2020

The developer blogosphere is festooned with BuzzFeed-style posts listing environment-specific workflow tips for programmers. Rather than just re-hash all of that here, we’ll first examine how to get into a state of mind conducive to discovering efficient solutions, regardless of tech stack. We’ll also discuss how to think about optimization from a cost-benefit perspective so that you can be sure you’re not wasting more time than you’re saving when you spend precious work hours hacking on tools and automation.

So…how do you get into an efficiency mindset?

Be Dissatisfied

That’s right. The journey to optimization Nirvana begins with being dissatisfied.

Don’t take my word for it; here’s what notable mathematician and Father of Information theory, Claude Shannon, has to say on the power of dissatisfaction:

Then there’s the idea of dissatisfaction. By this I don’t mean a pessimistic dissatisfaction of the world — we don’t like the way things are — I mean a constructive dissatisfaction. The idea could be expressed in the words, “This is OK, but I think things could be done better. I think there is a neater way to do this. I think things could be improved a little.” In other words, there is continually a slight irritation when things don’t look quite right; and I think that dissatisfaction in present days is a key driving force in good scientists.
Claude Shannon

So how does one transform useless, everyday irritation into constructive dissatisfaction? Simple. Use the Efficiency Algorithm.

Use the Efficiency Algorithm

What is the Efficiency Algorithm? It’s a revolutionary process developed by notable Developer Documentation Specialist and Father of Efficiency Theory, A. G. Smith (read: its something I just made up):

  1. There’s a solution to your annoyance
  2. Someone probably already created that solution
  3. If so, use it (and build upon it)
  4. If not, create it

Okay, so what does that look like in practice? I’ll use something that irritates everyone as an example: spreadsheets.

When working on a spreadsheet, I often find myself thinking “there’s got to be a faster way to do this — it will take an hour to go through all these rows!”. You’ve probably had this thought, too, and hopefully, you did what all disciples of the Efficiency Algorithm would do: spend the next two hours researching spreadsheet formulas and scripts in order to find a way to do it faster. If you did, good job; you used the efficiency algorithm and you didn’t even know it.

But was that two hours spent tinkering with formulas and VBA scripts worth all that trouble in the end? To answer that, we need to do some cost-benefit analysis.

Do Cost Benefits Analysis

But was that two hours spent tinkering with formulas and VBA scripts worth all that trouble in the end? That’s a very valid question, and the answer is: it depends on how many times a day you perform the task being automated. Here’s a relevant XKCD:

Is it Worth the Time? by XKCD

According to XKCD’s crude but useful graph, spending an entire day making a task one second faster is time well spent if the task is performed fifty times a day (or more) over five years. Here’s the math:

Time Saved (1*50*365*5 = 9,1250 seconds) > Time Spent (86,400 seconds)

Additionally, the value provided by the effort of creating automation is not necessarily equal to the time saved on the specific task for which it was created. If the new tool is generic enough, it can be used to tackle other problems and save time elsewhere — don’t forget to include that value when doing your cost-benefit analysis.

Okay, that’s enough theory. Let’s get to some specifics.

Keep a Terminal at Your Finger Tips

Many tasks can be performed faster via command-line interface, so use it as much as possible. I find I’m more likely to choose the command line when I use a terminal emulator that outputs elegant, syntax highlighted text and is easily accessible via keyboard shortcuts (ctrol+` is my go-to)

To explore some popular options, search for “[YourOS] Terminal Emulators” using your preferred search engine. Some fun features to look for:

  • Quake Style Dropdown
  • Window Splitting
  • Background Transparency

Leverage Start-Up Scripts

When you open PowerShell or a terminal emulator (like cmder, Gnome Terminal, or iTerm2, for instance), special scripts run automatically to get things setup for you. These scripts are known as shell start-up scripts, and they can make life a whole lot easier.

In this section, I’ll show you some of my favorite start-up script entries. They’re super simple, and they can be added to your own start-up script in seconds.

There are lots more details we won’t be going over; however, if you’re interested in a deeper diver, here are some resources from around the interwebs:

Where to Find Them

Here’s the default locations for the most commonly used start-up scripts for each of the major operating systems:

Linux: ~/.bashrc
OSX: ~/.bash_profile
Win: ~/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1

Open the file in your favorite text code editor to add the examples provided below.

Aliases

Aliases are nicknames for long or hard to remember commands. Add as many as you like to your start-up script (just be sure not give an alias the same name as an existing command, like cd, for example).

Below are the bash aliases I don’t leave home without. Note how the first two make editing ~/.bashrc itself faster (if you’re on OSX and using the default logged-in shell, use ~/.bash_profile instead of ~/.bashrc):

################################
# ALIASES

################################
# Open bashrc in VS Code (swap with your preferred editor)
alias bashrc='code ~/.bashrc'
# Tell the shell to reload bashrc (do this after edits)
alias rfrc='source ~/.bashrc'
# Update all git repos in current dir, recursively
alias
gituar="ls | xargs -P10 -I{} git -C {} pull"
# CAUTION: delete all local branches in git repo
alias
gitda="git branch | grep -v 'master' | xargs git branch -D"

Functions

Functions can execute multiple commands on multiple lines and take arguments; other than that, they’re very similar to aliases. Here’s some that I find useful on occasion (hopefully these give you some inspiration):

################################
# Functions
################################
# List file names and recent commit in a git repo:
function ls-repo {
git ls-tree -r --name-only HEAD | while read filename; do
echo "$(git log -1 --format="%as,%an,%s," -- $filename) $filename"
done
}

Some pro-tips:

  • Never use any commands from the internet (or any untrustworthy source) that you don’t understand.
  • Version control a modified copy of your startup script (remove sensitive information like API keys) and host on GitHub or GitLab to easily transfer between machines.

Wrapping Up

Next time you find yourself annoyed by a repetitive task or frustrated by a seemingly unsolvable problem, remember the Efficiency Algorithm:

  1. There’s a solution to your annoyance
  2. Someone probably already created that solution
  3. If so, use it (and build upon it)
  4. If not, create it

If efficiency were a starship, dissatisfaction would be its anti-matter warp core — use it to optimize your workflow and boldly go where no person has gone before.

--

--