Programmers Thesaurus

I need a "Programmer's Thesaurus". I know what an object or method should do, but I can't for the life of me figure out what to call it. Anybody else out there have this same problem, or is it just me? -- CurtisBartley

Yes, all the time. I pick the first name that comes to mind and get productive. After a while - usually after a few implementation iterations - better names occur to me (or someone else). And then things are happier.

Speaking with my technical writing hat on, this behaviour drives me up the wall. But better names makes writing manuals easier.

-- EricUlevik

This is funny. I often start off with methods named "foo". After I've written most of the method body a better (but not necessarily good) name will leap to mind. -- CB

There is a site for this purpose. http://programmasaurus.org/ I think the concept quite interesting, and see the potential. --JuneKim


Is an ordinary thesaurus not generally good enough (or better!)?

An ordinary thesaurus just won't cut it for this application. One problem I find is that I need to make very fine distinctions, much more so than in ordinary speech or writing. And then, I've never found thesauri to be very helpful for speech or writing either. Maybe what I need is more of a ReverseDictionary than a Thesaurus. Something along the lines of I have this cylindrical wooden object with a core of carbon that's used for making marks on paper. What should I call it?

But even a ReverseDictionary doesn't deal with the fact that my job requires me to essentially make up new words all the time. -- CB

A couple of Web sites I use to explore in multiple dimensions the relations between words in the english language (with infrequent non-english terms): http://www.lexfn.com/ Lexical FreeNet. Enter a word and see all kinds of related words, not just synonyms. http://www.cogsci.princeton.edu/cgi-bin/webwn1.7.1 WordNet. A more structured view of language, with hypernym, hyponyms, and coordinate terms.

Now a question: Working on a program where the domain is restaurant ordering, the natural object to have to represent the selection of available dishes is menu. Problem: In computer applications, the term menu has a specific, related, but different meaning: a graphical UI element. What's another word for the restaurant meaning of menu that still manages to mean something to domain experts, as opposed to propeller-headed nerds?

-- StevenNewton


Ask your co-workers. When you describe the object/method to someone else, the name kind of just falls out... -- SunirShah

If a co-worker isn't available, try RubberDucking.


Having one or more SystemMetaphor(s) also helps with this. -- PhilGoodwin


This might not be your problem, but applying ComposedMethod to make sure that your method is only doing a single identifiable thing often helps.


I think it can help to make words up. I was working on SNMP code once, where I had many occurrences of an (unsigned *) and an int, to represent an object identifier (OID). I put the two together into a data structure which I called an oidle, and gradually modified my code to take oidle args rather than two args. The effect was amazing - pieces of code I never understood before made sense, substantial methods vanished, and rose petals were cast before me by nubile maidens. Simply taking the plunge and giving a half-sensical name to this thing I had made the code *so* much more readable, despite the silly name. -- JohnFarrell

I love this! I have created and used object identifiers before, and considered doing something like this, and I can really appreciate the impact that having a name (even a nonsense name) would have. Many times, that name is all you need to make sense out of a real mess. Thanks for the encouragement to JustDoIt. -- RobWilliams


Here's a case in point. Just the other day I wrote a class that subclasses Thread (I'm speaking Java here). I called this class WorkerThread because I couldn't think of anything better. The class provides one interesting public method: addWorkItem(WorkItem workItem). The idea is that multiple threads can add work items and the Thread will execute them serially in the order they were added.

Clearly WorkerThread is a poor name. Any suggestions for better names? What I really want, of course, is a system for concocting good names, not just a solution to this one problem, although that would be cool too.

Any suggestions? -- CB

Why not call this class WorkQueue? It represents a queue of items of work in FIFO order.

As I said above, you asked your "co-workers," Wiki in this case. From the description comes the name:

The idea is that multiple threads can add work items and the Thread will execute them serially in the order they were added.

"Work items" and "serially" are the two keywords here. WorkItemSerializer would be a good name. I prefer one word to two, so I'd consider "work items" to be "actions." ActionSerializer. Or maybe just Serializer, or SerialThread, or SerialActionThread.

Actually, we have a thing in our system called a Sequencer whose job is to ensure things happen in sequence (hence the name) which is what you are doing above. But this solution to your query didn't come from a repeatable, dependable process. But then again, maybe your co-workers can construct a good name just like that. -- SunirShah

So let's see, we have so far:

Any votes or other suggestions? One of the reasons I rejected using "Serialize" or some variation thereof is because the term already has a well known meaning in Java (it might still be the best choice, though). I've never found co-workers a good resource for this kind of problem in the past, which is why I'm asking here.

For a start, you shouldn't be subclassing Thread, you should be implementing Runnable; the problem is then slightly different, because your thing is no longer a thread, it's a task. Worker seems like a good name - it does work. It does one thing at a time, and it does the things its asked to do in order, but that does not need to be reflected in the name. Perhaps you should then factor out the WorkQueue, so bosses can put WorkItems (or Jobs) onto the WorkQueue, and the Worker (or a pool of Workers) then pops them off.


"Each waiterThread passes all mealRequests to the chefThread. The chefThread executes each item in the queue and can autonomously invoke specializedChefThreads as necessary to deliver each mealResult in sequential order. The chefThread raises a flag to indicate that a mealResult is ready." -- ThePeanutGallery?


I've never found co-workers a good resource for this kind of problem in the past

It isn't really your co-workers, although they can help, it's the act of having to articulate a description of the variable/method/class that forces you to come up with names. Naturally, if you are a bad communicator and use words like "thingy" when communicating, or if you a really good communicator and use 'psychic powers' (as most of us can with a few close friends/colleagues), this won't work. But, if you have to articulate a real description to someone unfamiliar with the problem, so that they understand, naming becomes easy. I suspect this technique has a lower success rate the more you use PairProgramming because your psychic powers escalate, or the pair will be on the same brainwave and miss a good name, or pairing can give the illusion of a comprehensive review. See BinarySearchCommentary for a brick-wielding duo who suffered from the inability to clearly express their intent so the other person could understand (due to ego, in this case). -- SunirShah


Here's a naming problem that's stumped me in the past:

-- CurtisBartley

I do care about such problems, see LanguageOrientedProgramming and ThelopLanguage. You may also go to ThelopLanguageOracle? and ask such questions there. -- HelmutLeitner


What's wrong with INode?

It's an implementation detail and a UNIXism at that.


Perhaps the reason that this has stumped you in the past is that your hierarchy can be improved. This is what I always assume is the case. If I can't think of a name easily it means I'm forcing the meaning of the object, and objects should happily give up their meaning. Otherwise something is wrong. Compositely speaking, I would just make "File" the node class and "Regular_File" the leaf and "Directory_File" the folder. -- RodneyRyan?

Not to be cruel, but I don't think you could have a worse name than Regular_File. -- anonymous

The term I used in the past was FolderItem, i.e. an item that could belong in a "folder". The previous writer might find this name even worse than Regular_File. -- CurtisBartley

You could make File the base class, Directory a subclass and FileStream? the file I/O class. Alternatively, FileName? (or PathName?) can be used, although I'm not sure I like that. Path might work. Path is the generic term for either a filename or a directory name. -- SunirShah

What's wrong with something simple like:

 FileComponent <----------+
^  |
|  |
       /|\  |
 +------+-------+  |
 ||  |
 FileObjectFileFolder <>---+

There are variations like renaming FileComponent to AbstractFile or renaming FileFolder to FileNode or even FileComposite. My problem with something like Regular_File is that it begs the question "What is an irregular file object?" So, if you are really using the CompositePattern, I would use names that indicate that fact. -- RobertDiFalco

For what it's worth, JohnVlissides uses the term "Node" in PatternHatching.

"Directory_File"? Yuch! This one bugs me as well. I have made a couple of attempts to build a decent file system utility component, and I have struggled with the naming. Path has multiple meanings (absolute reference to a file versus list of search directories). I have used Entry (as in file system entry) for the parent of File and Directory, but Entry is rather generic. To further complicate things, there is the perceived need to distinguish between a file as a pointer in the file system, as a container of content, and as the content itself. These fine distinctions beg for a programmer's thesaurus to help with the naming. -- RobWilliams

The fact that this problem is hard is a clue: the metaphor here is muddled. Firstly, in real life, you can't really put folders inside other folders, unless they are a smaller size or are hanging files, in which case you can nest them a bit (but are not supposed to); let's accept folder nesting for now, though. Secondly, the term 'file' usually refers to not one document but several: WebstersDictionary? defines 'file' as:

"An orderly collection of papers, arranged in sequence or classified for preservation and reference; as, files of letters or of newspapers"

So, perhaps we should use File as the generic name, and call what we currently call a File a Document. In an ideal world, perhaps all files would be able to contain other files, so we wouldn't need separate items; obviously, our present model of files as streams of bytes would go out of the window, but that's a nasty physical model anyway :).

''What about FileSystemNode? -- TomRossen


I find that its often simplest to just use a sentence or phrase. If the thing is rarely used, then its easy to understand and the extra typing is irrelevant. If its frequently used then eventually you'll refactor it. For example:

This is basically a mindless approach to working round the problem. Equivalent to the "name everything 'foo'" approach, but with a slightly longer life before it must be improved. If an identifier is 100 characters long, then why worry? Accept it and move on. -- DaveWhipp

Yepper, doodle. I made the same argument in UnderscoreVersusCapitalAndLowerCaseVariableNaming, just in case you want to look at my drivel. However, I also made an appeal to limit variable name length by applying some smarts. -- MartySchrader


In one of my favorite books, ThinkingForth: A Language and Philosophy for Solving Problems, LeoBrodie discusses the art of choosing good names. He provides several pertinent quotes, such as (I am not advocating the ForthLanguage hereby):

"Besides a mathematical inclination, an exceptionally good mastery of one's native tongue is the most vital asset of a competent programmer." -- Prof. EwDijkstra

"A powerful agent is the right word.
Whenever we come upon one of those intensely right words in a book or a newspaper
the resulting effect is physical as well as spiritual, and electrically prompt."
-- MarkTwain

"The difference between the right word and the almost-right word is like the difference between lightning and the lightning bug." -- MarkTwain

"Suit the action to the word, and the word to the action." -- WilliamShakespeare, Hamlet, Act III

He also references a peer who suggests that the most important development tool is a good thesaurus. I would agree.

Our biggest challenge is not algorithms or performance or other technical issues; rather, it is communication. The ability to identify, and then effectively share, fine distinctions of meaning is very useful in human activity. When that human activity involves the precision of machine computation, it becomes absolutely crucial.

I have looked into various dictionaries and thesauri products, both technology-based and not, without real satisfaction (though I have not been remotely comprehensive). I suspect that building one, such as in the form of a WikiWeb, might be appropriate.

-- RobWilliams


I'm writing a method that looks for an object in a structure, but if that object hasn't been created, creates it with certain default arguments, and then returns the appropriate reference. I don't know what verb I should use. I want to use something like "get" or "fetch", but with the added meaning of "create a new one if one doesn't already exist." I can't possibly be the first programmer who's had to describe this sort of functionality. What's the verb I should use?

Obtain?

Is it really necessary that users of this method be explicitly aware of the creation semantics? This sounds to me like the old LazyInitialization pattern in which case get would be perfectly acceptable.


In cases it is, yes. There are cases where code says, "Give me a Thing, and I don't care if it's been here for hours, or if you have to build it fresh." In other cases, code says, "Give me a Thing, if it's here already, otherwise I need to do something else." I can need both sorts of "gimme", in addition to the standard "Give me a brand-new Thing" of a generic constructor. LazyInitialization is an optimization built to look like a generic new Thing() call.

An analogous need exists in terms of storing information, e.g. in databases: Update if it already exists, else insert it fresh. This need exists in every project I work on, and yet I have to code it from scratch. Am I missing something?


See SystemOfNames



EditText of this page (last edited November 25, 2014) or FindPage with title or text search