tags:

views:

356

answers:

9
+4  Q: 

Naming enum types

If you have a set of related words (e.g. Row & Column or On & Off), how do you find the collective word that describes those words? Specifically, how do you name an enum?

If I have "Red", "Green" and "Blue", a sensible enum name might be "Color". Values of "On" and "Off" might have a sensible enum name of "Power". But how do I name the enum that can have a value of "Row" or "Column"?


Couple of good answers to "What do you name a Row or Column enum?" - Cartesian and IndexType.

What about finding collective words in general - are there any resources out there or do you just have to be good at English / know lots of words?

+3  A: 

For (Row | Colum) I usually use 'IndexType' or something like that. As I see the row or columns being two different indexes into the same data structure.

I find myself using it primarily when I'm writing a table-based data structure it lets you write the vast majority of your code generically without regard to whether you're operating on rows or columns, just a range of indexes into the data structure. Then to do a row or column specific operation you just call the generic operation with the specific index type to use.

It works best if it is scoped to a class so that it's

Table.IndexType or Grid.IndexType (etc.)
+2  A: 

The first thing that comes to my mind is "Cartesian". As in

public enum Cartesian
{
   Row, Column
}

The reasoning behind this is because row/column most closely suggests the Cartesian Coordinates of a grid system.

Cyberherbalist
+8  A: 

Try using a name which indicates what the enum is used for, e.g

public enum CountMethod 
{
    Row,
    Column
}
bbmud
How do you know it's going to be counted?
Steve Kuo
The point was to give an example where this enum can be used. If you need rows or columns for specifying how user views his data, it could be ViewMode enum.
bbmud
To follow the Color example, you could name it something like PrintColors, ScreenColors, Palette, etc.
Ed Brannin
+1  A: 

You want a name that describes what the individual elements inside the enum are. For example your Row, Column example or both Cartesian elements, so Cartesian would be a good name for it. If you had a list of parts for a hardware store as an enum, a good name for it would be HardwareStoreParts, etc. If you have a enum of things like shoes, graphs, elephants, blue, pluto, Martha Stewart, then you're doing something wrong. If you can't think of a term for the items perhaps you're trying to force the enum to fit something it's not made for.

Malfist
+2  A: 

A good knowledge of English vocabulary would be helpful for this, but there are a plethora of collective nouns in the language that even most native speakers are completely ignorant of. For example, how many people happen to know that the collective noun for crows is "murder"? Sting used this word in his song "All This Time...", btw.

I suggested Cartesian originally because of the analog to cartesian coordinates in mathematics. The ancillary question, what about collective words, is interesting in and of itself, so for the benefit of anyone who might want to scope this out, from Wikipedia:

Collective Nouns from A-H

Collective Nouns from I-Z

Maybe there is something there that might trigger a good enum name!

Cyberherbalist
Everybody knows about a murder of crows. It was the title of a Cuba Gooding Jr movie.
Ken
"Everybody" certainly does not know this. I didn't know that Cuba Gooding Jr appeared in a movie of this title. There may even be people who don't even know who Cuba Gooding Jr is.
Cyberherbalist
+1  A: 

Think about how it will be used. What property or properties are you looking to describe?

The term you settle on should be reflective of the actual use of the values. It should be natural and and somewhat guessable for users of the API.

For example, these are probably pretty good:

widget.IndexMethod = IndexMethod.Row
widget.CountBy = CountMethod.Column

Along these same lines, I think Cartesian would be an awful choice in most circumstances. Cartesian is neither natural nor guessable, unless you're dealing with a technical graphing feature or something.

Baldu
True, Cartesian might be a trifle too arcane for some folks (many of whom have long ago forgotten everything they learned in Algebra 101). I do tend to think in terms of the kinds of grids that a row/column meme trends to.
Cyberherbalist
I'm mostly coming at it from the perspective of using the API instead of just designing it. Cartesian may seem like a perfect fit for describing rows/columns, but it is somewhat of a mental leap going the other direction. Maybe it doesn't matter so much with intellisense and smart IDEs and all that, though.
Baldu
A: 

Another possibility:

public enum Mapping
{
   Row, Column
}
Cyberherbalist
+6  A: 

There is a software called WordNet which has essentially classified every english word in a complex class hierarchy and has software built for it which can take two words and return their earliest common superclass (hypernym in wordnet language).

In this case, querying for the word red would return something like

red, redness
   => chromatic color, chromatic colour, spectral color, spectral colour
       => color, colour, coloring, colouring
           => visual property
               => property
                   => attribute
                       => abstraction, abstract entity
                           => entity

Querying for blue gives

blue, blueness
   => chromatic color, chromatic colour, spectral color, spectral colour
       => color, colour, coloring, colouring
           => visual property
               => property
                   => attribute
                       => abstraction, abstract entity
                           => entity

So you know, the most accurate way to describe red or blue is 'chromatic color'

adi92
Slick! Thanks for posting that!
Cyberherbalist
http://wordnetweb.princeton.edu/perl/webwn
demoncodemonkey
+1  A: 

I try to come up with a name that makes most sense when the enum is actually used. Depending on the context that might be something like:

Table.ROW

Or something rather different like:

SortMode.ROW
Fabian Steeg