Searching for awesome
February 23, 2015 at 8:10 PM by Dr. Drang
Last week, after seeing the word awesome used several times for things that weren’t close to awesome, I started thinking about how much its profligate use annoys me.1 Then I wondered if I’d been using it here. It’s not such a terrible word, but it is kind of young for me. I’m too old for certain clothes, certain hairstyles, and certain words. Awesome is one of those words.
So the next time I sat down at a computer, I searched the ANIAT archives for awesome.
Was a little disturbed to find that the word “awesome” appears in 8 of my blog posts.
— Dr. Drang (@drdrang) Feb 20 2015 4:45 PM
In my defense, in four of those eight posts I was quoting someone, and in the other four I was using it in a joking way. Still, it pays to be vigilant. It’s only a short step from awesome to awesomesauce.
The Markdown source of all my posts is in a set of year/month subdirectories in Dropbox, so it was easy to find all my awesomes. I navigated to the ANIAT folder and issued this command:
grep -ir awesome source/
One of the things I really like about grep
is how it allows both -r
and -R
switches for recursive searching. If only cp
were as forgiving. The -i
switch makes the search case-insensitive.
Grep has a long, long history in Unix. The original version was written by Ken Thompson, extracting a common command from his ed
text editor and making it available for command line use. For many, grep is a synonym for regular expression searching.
Several years ago, a new search tool, ack
, started getting attention. It was written in Perl and was supposed to be very fast, especially when searching through complex source code directories, because it didn’t bother searching files you were unlikely to care about, like binaries and version control files. It became popular among TextMate users, mainly because there was a nicely done TM plugin that used it.
I never got into ack
, even when I was using TextMate, mainly because the type of searching it was really good at wasn’t the type of searching I normally did. I don’t manage large software projects, so its efficiencies didn’t mean much to me.
Somewhat later came The Silver Searcher, which goes by the name ag
on the command line.2 It’s supposed to be fast both because it ignores the same sort of files ack
does and because its search algorithms are speedy on the files it doesn’t ignore.
How much faster? Well, let’s look. Here’s my grep
search for awesome on a 2010 MacBook Air:
$ time grep -ri awesome source/ > /dev/null
real 0m0.658s
user 0m0.600s
sys 0m0.053s
And here is is with ag
:
$ time ag -i awesome source/ > /dev/null
real 0m0.110s
user 0m0.060s
sys 0m0.065s
Pretty decent speedup, especially when you consider that the source
directory has nothing but Markdown files in it—no files are being ignored.
So why did I use grep
instead of ag
last week? Old habits are hard to break. The word grep is so engrained in my head as a synonym for search—even when I’m not using regular expressions—that I start typing it before I think.
But there are good reasons for switching. Apart from the speed, if I happen to be searching a git repository (and my ANIAT files really should be under source control, shouldn’t they?), results that don’t correspond to the source code itself get in the way, even when there are only a few of them.
With luck, writing this post will inspire me to make ag
my new habit. That would be awesome.