Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. EncodeFlags

EncodeFlags

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpdatabase
23 Posts 14 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Fabio Franco

    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

    T Offline
    T Offline
    TheGreatAndPowerfulOz
    wrote on last edited by
    #21

    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

    1 Reply Last reply
    0
    • B Bernhard Hiller

      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 a Flags attribute to a string, ignoring the fact that they are flags, in order to store that value in a database eventually. :~ X|

      T Offline
      T Offline
      TheGreatAndPowerfulOz
      wrote on last edited by
      #22

      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

      1 Reply Last reply
      0
      • B Bernhard Hiller

        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...

        T Offline
        T Offline
        TheGreatAndPowerfulOz
        wrote on last edited by
        #23

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups