Enum (also enumeration) is a data type consisting of a set of named values called elements, members or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language.
7
votes
2answers
159 views
Using scoped enums for bit flags in C++
An enum X : int (C#) or enum class X : int (C++11) is a type that has a hidden inner field of int that can hold any value. In addition, a number of predefined constants of X are defined on the enum. ...
1
vote
2answers
334 views
Nested Enum type in C++ or C#?
I've come across a recurring issue in a few of my recent projects in which I find myself using enums to represent state, or type, or something else, and I need to check against a few conditions. Some ...
4
votes
2answers
324 views
Is it possible to avoid enormously big switch in that case? [duplicate]
I'm writing a simple chess-related code with intention to write it clearly (performance doesn't matter at all). And this method I have doesn't look clean to me at all:
public static Piece ...
4
votes
2answers
157 views
Do I really want a dynamic Enum, or something else? Better caching? A Struct?
This question is asked on SO and this site often it looks like. "How do I do a dynamic enum?" Answers range from you shouldn't to possible compile time solutions. Now my question is do I want a ...
3
votes
1answer
319 views
What are the downsides of implementing a singleton with Java's enum?
Traditionally, a singleton is usually implemented as
public class Foo1
{
private static final Foo1 INSTANCE = new Foo1();
public static Foo1 getInstance(){ return INSTANCE; }
private ...
7
votes
5answers
745 views
Is it a bad practice to include all the enums in one file and use it in multiple classes?
I'm an aspiring game developer, I work on occasional indie games, and for a while I've been doing something which seemed like a bad practice at first, but I really want to get an answer from some ...
5
votes
4answers
253 views
Keeping an enum and a table in sync
I'm making a program that will post data to a database, and I've run into a pattern that I'm sure is familiar: A short table of most-likely (very strongly likely) fixed values that serve as an enum. ...
3
votes
3answers
321 views
How to deal with almost the same enums?
I need to define enums in several classes. The majority of fields are the same in all of the enums. But one has one or two more fields, another has fewer fields. Now I wonder what is the best way to ...
5
votes
4answers
410 views
Should I create an Enum mapping to my database table
I have a database table containing a list of systems relevant to the tool I am building, mostly in-house applications, or third-party systems we receive data from. This table is added to infrequently, ...
3
votes
2answers
273 views
Is switch-case over enumeration bad practice?
I have an enumeration with the commands Play, Stop and Pause for a media player. In two classes I do a switch-case over the received commands. The player runs in a different thread and I deliver the ...
2
votes
2answers
573 views
Best practice for packing Java enums?
What is the best practice for packaging Java enums?
is it separate file for each enum?
or
having same file for all the enums?
What are the pros and cons ?
0
votes
1answer
99 views
How far should I expose this status enum?
I wrote a little app to manage an arbitrary series of tasks (e.g., call a SQL sproc and capture out-vars, run another app, run an SSIS package) with dependencies between tasks. Each task has a status ...
4
votes
2answers
770 views
Why would one ever want to use a synchronized method in Enum?
I stumbled upon this question and a couple of other along the same lines.
While we know creation of enum is thread safe and enums are by birth singletons .
It kind of confuses me that why would ...
8
votes
5answers
677 views
switch statement - handling default case when it can't be reached
If I'm using a switch statement to handle values from an enum (which is owned by my class) and I have a case for each possible value - is it worth adding code to handle the "default" case?
enum ...
5
votes
3answers
1k views
How to use a switch statement with enum efficiently?
I would like to know how I can use a switch statement with enum values for the following scenarios:
I am making a small program for a flight reservation system. The program is meant to enter certain ...