EncodeFlags
-
It makes no sense: 1 - There are combinations not covered by the encoder. ie
Alarm | Malfunction
2 - It only makes sense to encode it if whatever is using does not support integers (or maybe it's meant to have a meaningful representation on a digital display, still what if it's alarming and malfunctioning). 3 - Should have used enum's HasFlag method. Now, an expert in C# and 25+ years in programming could only do this if he's hung over, lazy, dumb or having an idea so bright nobody can understand.To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia
Fabio Franco wrote:
could only do this if he's
pissed-off at legacy crap.
#SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
-
An expert of programming and C# with some 25+ years of experience in software engineering wrote a really useful function:
private string EncodeFlags(EventType _eventType)
{
if (_eventType == EventType.Alarm)
{
return "A";
}
if (_eventType == EventType.PreAlarm)
{
return "P";
}
if (_eventType == EventType.Malfunction)
{
return "M";
}
return "";
}Already this function alone is some kind of WTF. But let's look at the definition of the input parameter which he translates:
[Flags]
public enum EventType
{
None = 0,
PreAlarm = 1,
Alarm = 2,
Malfunction = 4
}So he translates an
enum
with aFlags
attribute to astring
, ignoring the fact that they are flags, in order to store that value in a database eventually. :~ X|Bernhard Hiller wrote:
ignoring the fact that they are flags
It could have been changed to [Flags] after-the-fact and this code was just not updated.
#SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
-
thund3rstruck wrote:
I learned decades ago that its a fool errand to insult the previous developer(s), especially if one was not there participating in the decision making process. There are a multitude of factors and/or external forces that impact decisions like this and arrogantly criticizing these choices accomplishes little.
I agree with you. I know the guy who wrote that code, and the circumstances: it's fresh code written this week. Some time ago, I discussed with him his obsession of encoding everything in magical ints or one-letter-strings, sometimes also providing "endode"/"decode" functions for converting between the magical ints and the one-letter-strings and the other way round...
Ignore my previous post. I used to work with someone like that. He no longer works here. Smart guy, very capable, but continuously made "mistakes" like that. His "code" has caused us lots of grief.
#SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun