• foo (unregistered)

    Major oversight: They forgot FILE_NOT_FOUND.

  • Hmpfs (unregistered)

    Maybe they were old Java coders. Something like this used to be quite a usual pattern in older versions of that language, since it did not have enums.

  • Eric (unregistered)

    It's called the type safe enum design pattern, and it does have its uses. They're rare, but they do exist. Captcha was enim. :)

  • ratchet freak (cs) in reply to Eric
    Eric:
    It's called the type safe enum design pattern, and it does have its uses. They're rare, but they do exist. Captcha was enim. :)

    type safe? in java enums are their own class unlike in other C style languages where they are int constants

  • WailyDTF (unregistered)

    This is not necessarily a WTF.

  • Nutster (cs)

    Am I seeing a potential problem, or is this just my C++ coding knowledge getting in the way of C# understanding? There does not seem to be a void constructor for the class nor its parent. If someone tries to instantiate an object for this class, you should get some compile errors, saying something about no available constructor taking 0 arguments.

  • WailyDTF (unregistered) in reply to Nutster
    Nutster:
    Am I seeing a potential problem, or is this just my C++ coding knowledge getting in the way of C# understanding? There does not seem to be a void constructor for the class nor its parent. If someone tries to instantiate an object for this class, you should get some compile errors, saying something about no available constructor taking 0 arguments.
    Actually, the code snippets as provided won't compile themselves, since the constructors have no body defined.

    Usually in these kinds of type-safe enumerations, one constructs all the possible static "enumeration values" within the private constructor.

  • Kabili (unregistered) in reply to Nutster

    Most new languages don't require a constructor with zero arguments.

  • haha (unregistered)
    Comment held for moderation.
  • Anonymoose (unregistered)

    These are cool. They can work as enums, but you can also add more properties to it, so you can basically have a coding identifier, a numerical ID, and a string. Like { BOOL_FILENOTFOUND, 666, "File not found! Crikey!" }

  • snoofle (unregistered)

    Please stop using discourse! How else can I impersonate snoofle in order to say something he'd thought is witty if he were Me?

  • faoileag (unregistered) in reply to haha
    Comment held for moderation.
  • Bob Lied (unregistered)

    If you were coding Java about a decade ago, before the language magically sprouted its enumeration feature, this was not only not a WTF, it was a best practice. It's item 21 in Joshua Bloch's "Effective Java" book, which was practically required reading.

  • yojin (unregistered) in reply to Bob Lied

    I think this is the real wtf. Only in Java would you need to create two classes to use an enum. In Java this is not insane, and in fact is a documented best practice.

  • Lucy Fur (unregistered) in reply to Anonymoose
    Anonymoose:
    These are cool. They can work as enums, but you can also add more properties to it, so you can basically have a coding identifier, a numerical ID, and a string. Like { BOOL_FILENOTFOUND, 666, "File not found! Crikey!" }

    +666, er, I mean +1

  • dkf (cs) in reply to yojin
    yojin:
    I think this is the real wtf. Only in Java would you need to create two classes to use an enum. In Java this was not insane, and in fact was a documented best practice.
    FTFY; Java has had proper enums since 5…
  • RaceProUK (cs) in reply to Nutster
    Nutster:
    Am I seeing a potential problem, or is this just my C++ coding knowledge getting in the way of C# understanding? There does not seem to be a void constructor for the class nor its parent. If someone tries to instantiate an object for this class, you should get some compile errors, saying something about no available constructor taking 0 arguments.
    In C#, if no constructors are provided, the compiler injects a void constructor with no body for you.
  • Evan (unregistered) in reply to Hmpfs
    Hmpfs:
    Maybe they were old Java coders.
    Hell, maybe it was old code.
  • Nagesh (unregistered)

    people who learned java in early days had to roll out their own Enums.

  • Steve (unregistered)
    Comment held for moderation.
  • Xaser (unregistered)
    Comment held for moderation.
  • Evan (unregistered) in reply to Evan
    Evan:
    Hmpfs:
    Maybe they were old Java coders.
    Hell, maybe it was old code.
    Actually I take this back, because as others have pointed out, it is c#. Whoops. Not paying enough attention.
  • Coyne (cs)

    Actually, I was surprised they didn't roll their own "string", "char", and arrays as well. I guess they have some restraint.

    It's clear they need more restraint yet, though...maybe a straitjacket?

  • Snoffle (unregistered) in reply to snoofle

    Hear Hear! Discourse is TRWTF

  • OldCoder (unregistered) in reply to snoofle
    snoofle:
    Please stop using discourse!
    Fixed that for you.

    Discourse is so bad that if it continues, I'll be forced to abandon this site after coming regularly for ~14 years.

  • The Great Lobachevsky (cs) in reply to snoofle
    snoofle:
    Please stop using discourse! How else can I impersonate snoofle in order to say something he'd thought is witty if he were Me?

    My employer only supplies IE8, so I can't even read the comments when Discourse is in use.

  • Nagesh (unregistered) in reply to The Great Lobachevsky
    The Great Lobachevsky:
    snoofle:
    Please stop using discourse! How else can I impersonate snoofle in order to say something he'd thought is witty if he were Me?

    My employer only supplies IE8, so I can't even read the comments when Discourse is in use.

    Haven't you heard of USB sticks and Portable Apps?

  • v (unregistered)

    Ok, it is nice to read from the above comment that this is not as much a WTF as the WTF author thought... but WTF is up with the array part in it?

    public static readonly SubscriptionStatus[] STATUSES;

    WTF?

  • v (unregistered)

    Oh nevermind, I get it now, we are only shown like the header file and not the implementation, where that array and all other members for that matter would have a more sensible definition and not be completely uninitialized.

    So the full code makes perfect sense, and the WTF is with the posted cutout.

  • Andrew (unregistered)

    Way better than FILE_NOT_FOUND.

  • Ehnonymouse (unregistered) in reply to Nagesh
    Nagesh:
    The Great Lobachevsky:
    snoofle:
    Please stop using discourse! How else can I impersonate snoofle in order to say something he'd thought is witty if he were Me?

    My employer only supplies IE8, so I can't even read the comments when Discourse is in use.

    Haven't you heard of USB sticks and Portable Apps?

    Use of USB sticks is incompatible with a secure environment. As is any version of IE greater than 8. The only reason we're not still using Windows XP is because it cost too much to pay for the off-support support. Remember the IT professional's creed: "It's not secure if users can still use it."

  • Coyne (cs) in reply to Ehnonymouse
    Ehnonymouse:
    Nagesh:
    The Great Lobachevsky:
    snoofle:
    Please stop using discourse! How else can I impersonate snoofle in order to say something he'd thought is witty if he were Me?

    My employer only supplies IE8, so I can't even read the comments when Discourse is in use.

    Haven't you heard of USB sticks and Portable Apps?

    Use of USB sticks is incompatible with a secure environment. As is any version of IE greater than 8. The only reason we're not still using Windows XP is because it cost too much to pay for the off-support support. Remember the IT professional's creed: "It's not secure if users can still use it."

    I second this. Nagesh has obviously never worked in a locked-down corporate environment, where you can't download, open a zip file, install anything, use USB, or run an app off of a portable device.

  • G. Applqst (unregistered)

    This class approach can give rise to inheritance hierarchies of enumerations.

  • Matt Westwood (cs) in reply to Bob Lied
    Bob Lied:
    If you were coding Java about a decade ago, before the language magically sprouted its enumeration feature, this was not only *not* a WTF, it was a best practice. It's item 21 in Joshua Bloch's "Effective Java" book, which was practically required reading.
    I myself wrote a considerable proportion of a majorly colossal app using a pattern derived from this. It was the way you did it in those days.

    You also got to point out that the design of the Java 5 Enum relied a lot on this thesis of Bloch's. Come on, it wasn't that long ago that Java 4 was the only game in town.

    The advantage to this pattern is that it's straightforward to replace it with the equivalent (much more compact) Java 5 version when you upgrade, and (if you done it right) it's practically plug-and-play.

    Conclusion: Not a WTF.

  • chubertdev (cs)

    I'm still amazed at how bad most developers are when it comes to enumerations.

  • Captain Oblivious (cs)

    I like how Haskell handles this, with its algebraic data types. All you have to do is create a data type with alternative nullary constructors:

    data Color = Red | Orange | Yellow | Green | Blue | Indigo | Violet
    

    Want to "apply" a color to a string?

    data Colored a = Colored Color a deriving (Functor)
    
    redString :: String -> Colored String
    redString = Colored Red
    

    Want to be more general?

    red :: a -> Colored a
    red = Colored Red
    

    Oh look, Colored is an adjunction, and red is in the Kliesli algebra for its monad. So functions like red form an "imperative" dsl for coloring things.

  • John Muller (unregistered) in reply to Evan
    Evan:
    Evan:
    Hmpfs:
    Maybe they were old Java coders.
    Hell, maybe it was old code.
    Actually I take this back, because as others have pointed out, it is c#. Whoops. Not paying enough attention.

    I've been doing C# for 13 years, I would call some of that code 'old' (but not 'ancient' like COBOL/C)

  • Doctor_of_Ineptitude (unregistered) in reply to OldCoder
    OldCoder:
    snoofle:
    Please stop using discourse!
    Fixed that for you.

    Discourse is so bad that if it continues, I'll be forced to abandon this site after coming regularly for ~14 years.

    Alex seems to be missing in action, and his minions seem happy to burn the place down. Discourse shows the number of comments for articles at the bottom. Just have a look as to how many comments are there as compared to (pick at random) any other article. Fact is people have started fleeing the ship. And those in power don't care. Discourse has features that don't matter, and fails miserable at it's basic task, making comments readable and enabling a conversation. This is a WTF of epic proportions right at thedailywtf.

  • chubertdev (cs) in reply to Doctor_of_Ineptitude
    Doctor_of_Ineptitude:
    fails miserable at it's basic task

    hah

  • Doctor_of_Ineptitude (unregistered) in reply to chubertdev
    chubertdev:
    Doctor_of_Ineptitude:
    fails miserable at it's basic task

    hah

    I do have a doctorate in ineptitude. They have no such excuse.

  • D-Coder (cs) in reply to Captain Oblivious
    Captain Oblivious:
    I like how Haskell handles this, with its algebraic data types. All you have to do is create a data type with alternative nullary constructors:

    ((snippage))

    Want to be more general?

    red :: a -> Colored a
    red = Colored Red
    

    Oh look, Colored is an adjunction, and red is in the Kliesli algebra for its monad. So functions like red form an "imperative" dsl for coloring things.

    So to use Haskell, I need to understand adjuntions, monads, and... Kliesli algebra? Yow. Thank you, C# and Javascript (and a dozen other things) for me.

  • snoofle (cs)

    Hi Guys,

    I too, used to roll my own enums and type safe collections before they were built into java 1.5, and have no doubt that folks did the same in other languages.

    I omitted it from the post, but this particular feat of engineering dates significantly after enumerations were added to the language...

  • Friedrice The Great (unregistered) in reply to Nagesh
    Nagesh:
    The Great Lobachevsky:
    snoofle:
    Please stop using discourse! How else can I impersonate snoofle in order to say something he'd thought is witty if he were Me?

    My employer only supplies IE8, so I can't even read the comments when Discourse is in use.

    Haven't you heard of USB sticks and Portable Apps?
    At my office, plugging a USB stick into a computer gives one of two results. If the stick is writable, the security software wipes it. If the stick isn't writable, the security software blocks access to it. But Discourse is still TRWTF.

  • Neal Blomfield (unregistered)

    Depending on the language, rolling your own enums using classes is actually better than using enums as you can add behaviour to class based enums but you can't add behaviour to enum based enums (at least in c# you can't). If you start with a class based enum it takes a lot more work to replace it later when you want to add behaviours.

  • Neal Blomfield (unregistered) in reply to Neal Blomfield
    Neal Blomfield:
    Depending on the language, rolling your own enums using classes is actually better than using enums as you can add behaviour to class based enums but you can't add behaviour to enum based enums (at least in c# you can't). If you start with a class based enum it takes a lot more work to replace it later when you want to add behaviours.
    ... If you start with *enum-based* enums ...
  • dreadwolf (unregistered) in reply to yojin
    yojin:
    I think this is the real wtf. Only in Java would you need to create two classes to use an enum. In Java this is not insane, and in fact is a documented best practice.
    Except this isn't Java and Java has had enums for 10 years. Why did your mommy let you near a computer?
  • Captain Oblivious (cs) in reply to D-Coder
    D-Coder:
    Captain Oblivious:
    I like how Haskell handles this, with its algebraic data types. All you have to do is create a data type with alternative nullary constructors:

    ((snippage))

    Want to be more general?

    red :: a -> Colored a
    red = Colored Red
    

    Oh look, Colored is an adjunction, and red is in the Kliesli algebra for its monad. So functions like red form an "imperative" dsl for coloring things.

    So to use Haskell, I need to understand adjuntions, monads, and... Kliesli algebra? Yow. Thank you, C# and Javascript (and a dozen other things) for me.

    The Kliesli algebra for a monad M is just the the set of functions with the type a -> M a -- the ones that let you compose monad actions.

    Your objection comes down to "math is hard wah" when it is demonstrably easier than the ad hoc constructions a typical language uses.

    How would you make a similar DSL (one that lets you attach colors to arbitrary objects) in the OO language of your choice?

  • Yuri (unregistered) in reply to Friedrice The Great
    Friedrice The Great:
    Nagesh:
    The Great Lobachevsky:
    snoofle:
    Please stop using discourse! How else can I impersonate snoofle in order to say something he'd thought is witty if he were Me?

    My employer only supplies IE8, so I can't even read the comments when Discourse is in use.

    Haven't you heard of USB sticks and Portable Apps?
    At my office, plugging a USB stick into a computer gives one of two results. If the stick is writable, the security software wipes it. If the stick isn't writable, the security software blocks access to it. But Discourse is still TRWTF.
    Our IT security take the "All your USB is belong to us" type attitude....

    If it touches a work system it become there's

  • Steve (unregistered) in reply to The Great Lobachevsky
    The Great Lobachevsky:
    My employer only supplies IE8, so I can't even read the comments when Discourse is in use.

    The WTF is why you still work for them.

  • Norman Diamond (unregistered) in reply to Friedrice The Great
    Friedrice The Great:
    At my office, plugging a USB stick into a computer gives one of two results. If the stick is writable, the security software wipes it. If the stick isn't writable, the security software blocks access to it.
    Ah, that explains it. Lois Lerner's e-mail was backed up on a USB stick, along with records of my Forms 1099 and some registered letters.

Leave a comment on “Rolling Your Own”

Log In or post as a guest

Replying to comment #:

« Return to Article