Efficiency and idiosyncrasy

Whenever I write a post with a bit of shell coding in it, as I did last night, I get feedback showing me different ways of doing the same thing. In some cases this is helpful (I like learning new tricks, even if I decide not to use them), in some cases it isn’t (I don’t care how much better you think zsh is, I don’t care how much better everyone else thinks zsh is, it’s not enough better for me to bother with).

But while it’s nice to learn new things, unless I have the opportunity to use them often, they’re unlikely to stick with me. With little one-offs like last night’s commands for creating a year’s worth of monthly folders, efficiency isn’t measured by how much processor time is used, nor—and this is key—by the amount of typing I do. It’s measured by the total time and cognitive load used in thinking up how to solve the problem and then executing that solution. Usually the first solution that comes to mind, no matter how much typing is required, is the one that’s the most efficient when measured this way.

And what first comes to mind is unique to everyone. It’s based on everything you’ve seen and done in the past, what you’ve been working on most recently, and, by exclusion, all those many many things you never learned at all.

So when I need to generate a sequence of numbers, I think of using jot. You might think the phrase “sequence of numbers” would lead me to think of seq, and I confess that makes a lot of sense. But sense doesn’t enter into it. I learned jot first, never really learned seq (other than that it exists), so that’s what my brain goes to.

Of course, after you’ve solved your problem and have moved on, it can be helpful to look back on it and rethink it. If you come up with a simpler way to have done it, that little nugget may come back to you the next time you run into a similar problem.

And it’s even better if you can blog about it and get the opinions of others. After last night’s post, I had a brief Twitter conversation with Ryan M. He had some ideas that I’d never use—his idiosyncrasies aren’t mine, and he’s using a later version of bash than I am—but he did remind me of the -p option to mkdir, which creates all the necessary intermediate directories to create the full path to the directory you want. With that, I realized that instead of

mkdir 2017
cd 2017
jot -w %02d 12 | xargs mkdir

I could have done it all with

jot -w 2017/%02d 12 | xargs mkdir -p

Come back next year to see if I still remember by then.