Tim Gradwell
Tim Gradwell

Reputation: 2422

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?

Upvotes: 5

Views: 790

Answers (9)

Fabian Steeg
Fabian Steeg

Reputation: 45754

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

Upvotes: 1

Aditya Mukherji
Aditya Mukherji

Reputation: 9256

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'

Upvotes: 6

Baldu
Baldu

Reputation: 5774

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.

Upvotes: 1

Cyberherbalist
Cyberherbalist

Reputation: 12329

Another possibility:

public enum Mapping
{
   Row, Column
}

Upvotes: 1

Cyberherbalist
Cyberherbalist

Reputation: 12329

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!

Upvotes: 2

Malfist
Malfist

Reputation: 31815

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.

Upvotes: 1

user21714
user21714

Reputation: 5951

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.)

Upvotes: 3

bbmud
bbmud

Reputation: 2688

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

public enum CountMethod 
{
    Row,
    Column
}

Upvotes: 9

Cyberherbalist
Cyberherbalist

Reputation: 12329

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.

Upvotes: 2

Related Questions