Suggestion: Remove sentinel values in enums
PostPosted: Fri Feb 27, 2009 8:26 am
My next great project approaches... what have I gotten myself into...
I suggest we abandon the practice of using sentinel values in enums. It can cause problems (see below) and is not recommended.
(A sentinel value is a duplicate value in an enum to indicate boundaries, like eRealm.Albion = 1 and the sentinel value eRealm._FirstPlayerRealm = 1.)
Consider the following:
I do realize that a fair bit of information has changed as DAOC has evolved (new weapons, classes), but enums should generally be used for static data. Which means we know what's there. Which means we don't need sentinel values. Instead of:
Please share your thoughts on the idea. If it's agreed to be a good idea, I'll probably sacrifice myself to the hassle of implementing it.
I have a dream... one day, I imagine I will look upon the DOL API and be pleased, and I will use it to make new things... in the meantime, it looks like I'm stuck trying to give the API some extra shiny.
I suggest we abandon the practice of using sentinel values in enums. It can cause problems (see below) and is not recommended.
(A sentinel value is a duplicate value in an enum to indicate boundaries, like eRealm.Albion = 1 and the sentinel value eRealm._FirstPlayerRealm = 1.)
Consider the following:
- Code: Select all
Dictionary<eRealm, int> resists = new Dictionary<eRealm, int>();
resists.Add( eRealm.Hibernia, 10);
- Code: Select all
eRealm hib = eRealm.Hibernia;
int resist = resists[hib];
I do realize that a fair bit of information has changed as DAOC has evolved (new weapons, classes), but enums should generally be used for static data. Which means we know what's there. Which means we don't need sentinel values. Instead of:
- Code: Select all
if( realm >= eRealm._First && realm <= eRealm._Last )
- Code: Select all
if( realm >= eRealm.Albion && realm <= eRealm.Hibernia )
Please share your thoughts on the idea. If it's agreed to be a good idea, I'll probably sacrifice myself to the hassle of implementing it.
I have a dream... one day, I imagine I will look upon the DOL API and be pleased, and I will use it to make new things... in the meantime, it looks like I'm stuck trying to give the API some extra shiny.