Hello all;
In this series of posts, we shall take a look at some unconventional tools that help solving various programming (and other) problems that often come up. For this first article, I want to tackle a problem that actually made the list of the two hardest problems in computers science. Here’s that list:
- Selecting meaningful names.
- Cache coherency and invalidation.
- One off errors.
Ignoring the one-off error in the list, the first issue is selecting meaningful names. Way back in the bad old days, it was considered acceptable to have a program full of entities like i, j, k, and pmz21. Variable names that were meaningless, supported by a mountain of comments that were often completely out of data and/or misleading.
Slowly, computers improved and space was no longer so violently cramping the writers style anymore. This however lead to the opposite problem of names like:
if (index_selection > the_number_of_selections_available_in_the_menu) display_a_pop_up_error_mesage("Oops");
Names so verbose that they obscure the intent of the code.
What we really need is names that are meaningful and not verbose. It boils down to a matter of selecting the right words. Regardless of what programming language I use, I program in the english language. There are over a million words defined for that language and I can assure you the I do NOT know them all. For those where english is not their native tongue, the problem is even worse.
What to do? Use a tool to help navigate the possible words for the job: Thesaurus.com!
Let’s try a real example I encountered just this morning. I was looking to update the description of my mini_readline ruby gem. I wanted to describe the fact that it came with four sample auto-completing thing-a-ma-bobs. The only word that came to mind was “engine” that sort of worked but sounded to mechanical. I wanted a word that would express the idea of work done on the user’s behalf. So of to the thesaurus web site and punched in engine… A large page of results including the word I sought for: agent!
So the next time you struggle with one of the most difficult tasks in programming (and writing too) consider using a free tool to ease the burden of picking that one in a million perfect word for the job!
Best regards;
Peter Camilleri (aka Squidly Jones)