How I Make Algorithms

I’ve been reading Clive Thompson’s Coders book, and it’s caused me to reflect upon the process I use for coming up with algorithms. I’ve come to realize this is one of those things which I do, but is incredibly difficult to explain to others– so this post is my effort to encapsulate “my process.”

  1. Become intrigued/obsessed with something (e.g. anagrams)
  2. Discover an online anagram finder
  3. Ask myself, “How would I go about building my own anagram finder?”
  4. Realize I have no idea, and beat myself up for not knowing
  5. Forget about building my anagram finder project
  6. Weeks later, coincidentally stumble across:
    1. Fermat’s notes on anagram comparison using prime numbers trick
    2. A code challenge to create anagram tester function
  7. Turn Fermat’s concept into a quick & dirty JavaScript function, areAnagrams().
  8. Feel good about my areAnagrams() milestone/accomplishment
  9. Realize Fermat approach hits integer bit-limit with medium length words.
  10. Convert areAnagrams() from prime numbers to “wordDNA” approach (i.e. case-insensitive letter sorting)
  11. Feel good about resolving limit in areAnagrams() function.
  12. Days later, realize wordDNA approach can be used to create a “rainbow table” of dictionary list– and now you’ve got the basic building parts of an online anagram finder.

Happiness and Money

a package of Cascade Action Packs, a box of dimmable LED bulbs, and a package of Avery shipping labels.

I finished reading Gretchen Rubin’s “The Happiness Project” a few weeks ago, and have started gradually implementing her action items. I can’t say I’ve been 100% consistent, or tried them in the exact order and combination the author has done, but after trying a fourth action item today, I wanted to capture my thoughts while the impressions and feelings are still fresh in my mind.

The first two items I implemented were going to sleep earlier and doing the nagging task. I had my doubts about the going to sleep earlier suggestion, but I’ve got to admit when I’ve actually done it, I’ve felt better the following morning. I have this habit of staying up until I’m literally struggling to stay awake, and then going to bed and falling asleep almost immediately afterwards. I typically get 6-7 hours of sleep this way, and I’m sure I adapted to that amount as my “normal” (whatever that means) baseline.

When I go to sleep earlier, though, I’m finding I wake up earlier and get approximately the same amount of total sleep time– but I “feel better” (more rested, more recharged, more patient, whatever subjective terminology you want to use) for some reason.  I’m certainly not a sleep researcher, but this suggests to me the quantity of sleep time isn’t as important as the timing of when I sleep.  Maybe I’m getting a higher percentage of time in REM sleep by going to bed earlier, somehow?

The nagging task action item has been successful when I’ve actually followed through on it, in the sense that I have one fewer “open loop” to worry about once the task is completed– but I haven’t been applying it on a consistent, daily basis.  Definitely an area of improvement for me to focus on in the upcoming weeks.

Which brings me to the most recent action items I put into effect this weekend: buying needful things and indulging in a modest splurge.

While reading The Happiness Project, I learned I am an “underbuyer.” If you’d asked me before to describe my buying philosophy, I’d have described myself as frugal or a cheapskate, but lately I’ve come to realize that buying the least costly items on a just in time basis was essentially trading one kind of stress (i.e. worrying about money) for a different kind of stress (i.e. dealing with poor product quality and/or not having something on hand right when I need it). I decided to make a few small adjustments. For example, instead of buying the cheapest package of dishwasher detergent I can find, I buy the bulk package. Yes, it’s more expensive in the immediate sense, but it’s the lowest unit price and I won’t need to worry about running out or buying it again for three months. Or instead of replacing the recessed light bulbs in the kitchen with the typical floodlight bulbs, I opted for dimmable LED bulbs instead. Again, more expensive now, but they’ll last longer and use less energy then traditional light bulbs, so I won’t have to replace them as often.

I’m not saying buying LED bulbs will make a person happy– but eliminating a source of frustrating stress can reduce the chances of one being unhappy, and that’s a start, right?

“Make Me Feel Like A Wizard” Isn’t A Feature. Or Is It?

There’s something about typing in a trigger word into your code editor, hitting the Tab key, and seeing it suddenly transformed into a custom function, class, object, or whatever which you’ve created– it feels magical.

I know it’s not truly magical, obviously. But it feels like it.

For context, I’m mentioning this because I’m in the middle of migrating from the 32-bit version of my coding editor to the 64-bit version. The plugin I currently use to manage my reusable code snippets is only available in a 32-bit DLL, it hasn’t been updated in nearly 6 years, etc. There is a different code snippet plugin available for the 64-bit version, it’s actively developed and maintained, has great documentation, arguably better UX/UI, and does everything the previous plugin does . . . except for the trigger word/Tab key transformation.

The analytical part of my brain says this is a no-brainer: “Migrate your code snippets to the new plugin.”

The creative side of me, however, is like: “But it’s missing THE coolest feature! Can’t we download the plugin source from GitHub and re-compile it in Visual Studio as a 64-bit DLL, or make a wrapper or something?”

The silly part is, no one actually watches me write code. There’s no “wow factor” or whatever you want to call it. If you stop and think about it, the whole trigger word/Tab transformation scheme doesn’t even scale well– because every snippet you add requires you to remember a new trigger word. And if you try to export and share your snippets with someone else, they won’t have memorized your trigger words. It’s impractical.

But typing in “errorhandler”, hitting the Tab key, and suddenly seeing your text replaced with the method to invoke your organization’s error catching and logging object– that’s some Doctor Strange meets Jeffrey Zeldman in Area 51 kinda mojo right there. Using a category scheme with a dropdown UI to ultimately pick the “errorhandler” function from a displayed list of matching functions, just isn’t as satisfying.

I think the secret behind this feature’s irrational appeal is “It makes one feel like a wizard.”  You type in the secret word, press the magic button, and (voila!) something cool happens. It creates an empowering feeling, and that’s a big piece of “locking people in” to your product.  (Seriously, the fact that I’m even considering trying to recompile a plugin which hasn’t been updated in 6 years as a 64-bit DLL shows you how ridiculous this is.)

Your turn now. Tell me about your favorite “Makes me feel like a wizard” feature.