A data type consisting of a set of named values called elements, members or enumerators of the type.
3
votes
1answer
46 views
Critique of Cardinal Direction Enum
I'm working on a simple game in which I need to track the cardinal direction of an object. I experimented with using the enum's ordinal value, as well as using switches for the rotation, but both ...
2
votes
4answers
127 views
Enum or Constant
I'm writing a SDK for a NFC device in .NET so I don't have to import the SDK from C++. Right now I'm working on the ISO14443-3 part which is just simple Halt, Request, and Anticollision commands. The ...
4
votes
2answers
103 views
Alternative to starting enum values with a number?
I have an enum like the following:
enum MeasurementBandwidth
{
Hz1 = 1,
Hz3 = 3,
Hz10 = 10,
...
}
But I do not like the Hz1, but 1Hz is not valid as it starts with a number.
Does ...
2
votes
1answer
54 views
Critique of enum
I'm working my way through The Java Programming Language, Fourth Edition - The Java Series. This is Exercise 6.4:
Expand your traffic light color enum from Exercise 6.1 on page 152 so that each ...
7
votes
4answers
243 views
Tic-Tac-Toe design
Kindly look at this code and point out design flaws or areas for improvement. I think I've done the last part right (the enum). I think the rest of the design is flawed but I am very new to ...
2
votes
3answers
494 views
Converting enum values to strings in C++
Question 1: functionxxx_as_string() is used below. How else could it be more elegantly named?
Question 2: Is the static char* array method adopted below the only solution? Best solution? Any ...
0
votes
3answers
200 views
Converting a c# enum into a list to be sent to the client
I want to use the enum on the client for a dropdown list. Does this make sense, or is there a smarter way of doing this?
public class clientEnum
{
public string Value { get;set;}
public int ...
2
votes
3answers
146 views
An attempt at a simple type safe python enum
There have been many posts here about enums in python, but none seem to be both type safe and simple. Here is my attempt at it. Please let me know if you see anything obviously wrong with it.
def ...
3
votes
1answer
125 views
Enums with different methods, useful or abuse?
I'm wondering if the way I wrote our TextHelper class is a really a proper way to do it.
We have products that are interlinked in different ways and every product has multiple text fields that might ...
1
vote
1answer
62 views
Is this enum declaration “wrong,” or is it just me?
Legacy code has this enum declaration:
public enum ChangeListTypes
{
Always = 1,
Never = 2,
CostChange = 3,
None = 0
}
I would have done it this way:
public enum ChangeListTypes
{
...
35
votes
14answers
2k views
Cleaner way to code BOOL×BOOL→ENUM mapping?
Does this part look clean enough? Any suggestions on how to make it cleaner?
if (isCheck)
{
if (isStuck)
{
return GameState.Mate;
}
else
{
return GameState.Check;
...
3
votes
1answer
129 views
Parse Flags enum from array of booleans
I need to get from an array of booleans to a Flags enum.
Here's what my enum looks like:
[Flags]
public enum UserContactPreferences { None = 0, SMS = 1, Email = 2, Phone = 4 }
Here's what my ...
11
votes
2answers
438 views
Advice on naming convention with enum
I have an enum called NodeType. Since my public field does not want to conflict with enum, I've used MyNodeType. Is there a better naming convention?
public class TreeNode
{
public enum ...
1
vote
1answer
539 views
Class to Simulate Enums in PHP
I have been reading this thread on StackOverflow about simulating enums in PHP and it seems that the most common approach is to use class constants. My problem with that is I can't use it for type ...
2
votes
2answers
1k views
How can an Enumeration with Descriptions be cast into a Dictionary?
The Enumeration in question is based on int, so the following Extension returns a Dictionary<int, string> of the Enum's Value and Description.
Is there a cleaner way of implementing this?
...
17
votes
5answers
1k views
Boolean enums: improved clarity or just overkill?
Suppose we are writing a GUI toolkit in C++ (though this question may also apply to other languages). We have a button class with a member function hide, which hides the button. This member function ...
1
vote
2answers
2k views
Boolean flags encoded as integer implemented with EnumSet
I'm a beginner in Java so I would appreciate a review of following simple class - in fact it's my first real usage of enums.
The background: I'm parsing MySQL internal client-server protocol. One of ...
5
votes
3answers
155 views
Should I design my enumeration in some way that indicates what the highest value is?
This is a subtle question about design in which I want to find the most elegant and appropriate solution.
I have an enumeration representing a French card deck (see code below). With it I need to do ...
5
votes
3answers
2k views
Enum vs int wrapper struct
I am writing code that has objects having integer member variables where the integer value has a specific constant meaning, which normally means "use an enum".
Suppose the values are the days of the ...
2
votes
1answer
143 views
Scala Direction enum with Enumeration and collection usage
I've just implement direction enum
object Direction extends Enumeration {
type Direction = Value
val Up, Right, Down, Left = Value
val pairs = HashSet() ++ List((HashSet() ++ List(Up, Down)), ...
8
votes
1answer
7k views
Getting the value of a custom attribute from an enum
Suppose we have an enum called "Planet" and it has a custom attribute of class "PlanetAttr",
these methods will give you the attribute value for a given Planet value:
private static PlanetAttr ...