Programming: resources for naming classes?

So, it’s refactor time. As part of this, some classes which have vague or misleading names are to be renamed. But in some cases what the class does, while clearly-defined, is nonetheless quite abstract and a simple name isn’t obvious.

Now to fix this problem, obviously a dictionary, thesaurus and good long think about what the class is meant to do are important inputs.

But are there standard naming conventions I can refer to? From googling all I can find is lists of Don’ts.

There’s a whole chapter on naming variables in Code Complete. That might give you some ideas, but it’s more along the lines of Do This, Don’t Do This. This Is Better, here’s why.

It’s best to comment things that you can’t write self-documenting code for. Does that make sense or should I go into more detail?

If you have to use a book to name a class, then the guy who works on the code after you will have to use a book to figure out what it does, so that sort of approach is self defeating with regards to readability. If its hard to give the class a simple name, perhaps the class it too big and is doing more than it should.

This would be much easier with an example (though obviously you may not be able to give proprietary code away). Even giving us an example may help you name the class.

It’s going to depend on the application, but generally the class name wouldn’t reflect so much about it’s internals as how it fits into a larger organization of the classes. General purpose classes often end up with something like UTIL as part of their name, quite unhelpful at times. There is no solution to fit all circumstances. For development work you need to take advantage of diagramming and class browsing tools for the more dedicated classes. For general purpose and utility classes the solution is documentation that is based on the methods contained in them and not the class name itself. On top of that, ask yourself if the overall organization of classes makes sense. It’s easier to classify in some applications, for instance the classes may be organized based on the components of a user interface. Sometimes the overall structure is too complex to usefully organize by class name (although I consider that to be the actual problem), but the solution to that may just be meaningful comments in the code, and grep.

Thanks for the responses.

Probably a better place to ask would have been stack overflow, and, accordingly, I found some good info there. Though I’m still surprised there are no conventions anywhere for this kind of thing.

To be more specific about my problem: In our code there are three layers of classes; Services which are the public interface, a Database (I/O) layer, and a middle layer where the classes right now are called “<Something>StatefulService”, because they used to contain cached, calculated data. But now they don’t cache anything, they are just a translator between the two layers (and indeed Translator is one candidate for what to call this layer).

Actually, Stack Overflow is a bad place to ask because it’s considered too opinion-based or broad. Programmers Stack Exchange is probably where this sort of question would go.

Edit: Translator sounds fine to me.

Luckily, most of the languages that allow classes are case sensitive. This is ideal, since it allows you to find one solution that works and re-use it. For example, the first class in your project should be called “Ishmael,” because, we’ll, that’s what you call it. The second class is called “IShmael,” followed by “ISHmael”, and so on. You get 128 different classes to use – after that, just start compiling them as separate units and re-use the names.

This has all sorts of benefits: No time is spent thinking of a name for your “next” class, and you always know what symbol to look up in the documentation.

What?

And if your language supports unicode, you can add accents too!

<Insert Zalgo-fied Ishmael here, but apparently VBulletin is too much a loser to handle Zalgo-fied text>

I would call this a ServiceBus. See this wiki for a description: