473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

is this usage of enum healthy?

Hello

I sometimes convert lots of numeric defines to enum, as:

#define XYZ 0x12345

to

enum some_consts
{
XYZ = 0x1234
};

Sometimes one enum, is used as:

enum some_consts
{
XYZ1 = 0x1234,
X1 = 1,
X2 = 2,
Y1 = 1,
Y2 = 2
};

etc...too many duplicate values, no order is used, etc...is that okay?

Or I create a namespace and use const int definitions inside?

Regards,
Elias
Jul 23 '05 #1
2 1595
lallous wrote:
Hello

I sometimes convert lots of numeric defines to enum, as:

#define XYZ 0x12345

to

enum some_consts
{
XYZ = 0x1234
};

Sometimes one enum, is used as:

enum some_consts
{
XYZ1 = 0x1234,
X1 = 1,
X2 = 2,
Y1 = 1,
Y2 = 2
};

etc...too many duplicate values, no order is used, etc...is that okay?

Or I create a namespace and use const int definitions inside?

Regards,
Elias


I don't think this will break your program or so, but it's just not what
enums are intendend to use for. As you said, namespaces are your friends:

namespace my_const_data
{
const int BAR = 1;
const int FOO = 0x22;
// ...
}

--
Matthias Kaeppler
Jul 23 '05 #2


lallous wrote:
Hello

I sometimes convert lots of numeric defines to enum, as:

#define XYZ 0x12345

to

enum some_consts
{
XYZ = 0x1234
};

Sometimes one enum, is used as:

enum some_consts
{
XYZ1 = 0x1234,
X1 = 1,
X2 = 2,
Y1 = 1,
Y2 = 2
};

etc...too many duplicate values, no order is used, etc...is that okay?

Or I create a namespace and use const int definitions inside?


In general I wouldn't use enums to introduce a set of value constants
unless the set was cohesive and the values had to map directly into the
problem domain. In most cases I'll use single value enums as in

enum utilsCopy {
utilsCOPY
};

enum geomOrigin {
geomORIGIN
};

enum geomXaxis {
geomXAXIS
};

and use them as in:

class Vector {
public:
Vector(geomXaxis);
Vector(geomYaxis);
Vector(geomZaxis);
};

class Point {
public:
Point(geomOrigin);
}

class myClass {
public:
myClass(utilsCopy, const myClass& a);
};
void some_method(const myClass& arg)
{

Vector v(geomXAXIS);
myClass c(utilsCOPY, arg);

}
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

383
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a...
11
by: ma740988 | last post by:
I'm perusing a slide with roughly 12 bullets spread across 3 pages. Each bullet reflects 'advice'. I'm ok with all but 1 bullet, more specifically the bullet that states: " Avoid the STL unless...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
1
by: JimM | last post by:
I know this is the VB languages new group. I have a .NET library (DLL) written in C#. I am adding examples to my documentation for my VB users. I have a VB example that will not compile. C#...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
3
by: hta1984 | last post by:
In my homework i need to use enum type input,and these inputs will contain a port number and a description. Here is the input: HTTP : 80 “Hypertext Transfer Protocol” SSH : 22 “Secure Shell” ...
3
by: Thom Little | last post by:
I want to check if a remote server is healthy. For FTP and HTTP ports I use ... public static string Connect( string hoist, int port ) { try { IPAddress ipa = Dns.GetHostAddresses( host );...
9
by: Cralis | last post by:
I have a List of data objects. I need to populate a ComboBox with the 'Description' field from the objects. I can do that with cmbBx.Items.Add( myObject.Description.ToString() ); myObject has 2...
18
by: David Moss | last post by:
Hi, I want to manage and control access to several important attributes in a class and override the behaviour of some of them in various subclasses. Below is a stripped version of how I've...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.