- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Major oversight: They forgot FILE_NOT_FOUND.
Admin
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.
Admin
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. :)
Admin
type safe? in java enums are their own class unlike in other C style languages where they are int constants
Admin
This is not necessarily a WTF.
Admin
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.
Admin
Usually in these kinds of type-safe enumerations, one constructs all the possible static "enumeration values" within the private constructor.
Admin
Most new languages don't require a constructor with zero arguments.
Admin
As provided it won't work I think, but I think they tried something like this: https://stackoverflow.com/questions/3007596/behaviour-to-simulate-an-enum-implementing-an-interface/3007754#3007754
Which can be really usefull so you won't have to generate giant switches everywhere in the code using the "enum", but you can keep specific values, formatting with the "enum" it belongs with.
Admin
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!" }
Admin
Please stop using discourse! How else can I impersonate snoofle in order to say something he'd thought is witty if he were Me?
Admin
Including the why, the how and the advantages.
Admin
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.
Admin
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.
Admin
+666, er, I mean +1
Admin
Admin
Admin
Admin
people who learned java in early days had to roll out their own Enums.
Admin
This is similar to Jimmy Bogard's solution here: http://lostechies.com/jimmybogard/2008/08/12/enumeration-classes/
By modeling the enumeration as a class structure, it allows you to map it to a table using your ORM, thus keeping your lookup tables in sync with your code, while at the same time being flexible enough to allow additional codes to be in the database and not break your app.(perhaps an older version of an API)
I haven't used the new enum support in Entity Framework, but from reading the documentation I don't see anything that implies it works the same way.
There are a lot of WTF's in this world. This is not one of them.
Admin
Oh god... I'm doing the thing. I'M DOING THE THING.
inhales deeply
This is not a WTF.
The Los Techies article linked by faoileag makes a good case for a full-blown enum replacement, but judging from the presence of a single string parameter in the constructor, today's featured code looks more like it's trying to implement a 'String Enum', which is not "rolling your own" but rather adding something the language itself doesn't have at all (assuming the code is indeed C#). It's there to solve a problem that vanilla enums can't.
Granted, the actual code featured in the article doesn't actually work, but it looks to me like it's incomplete (probably truncated during anonymization or submission). It won't compile as-is (verified by self-testing, again assuming it's C#) and it's not actually creating any instances, making the whole thing moot. Concept still stands as a non-WTF though, unless I guess one subscribes to a "don't ever use string 'enums'" point of view. :P
exhales
I did the thing.
Admin
Admin
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?
Admin
Hear Hear! Discourse is TRWTF
Admin
Discourse is so bad that if it continues, I'll be forced to abandon this site after coming regularly for ~14 years.
Admin
My employer only supplies IE8, so I can't even read the comments when Discourse is in use.
Admin
Admin
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?
Admin
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.
Admin
Way better than FILE_NOT_FOUND.
Admin
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."
Admin
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.
Admin
This class approach can give rise to inheritance hierarchies of enumerations.
Admin
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.
Admin
I'm still amazed at how bad most developers are when it comes to enumerations.
Admin
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:
Want to "apply" a color to a string?
Want to be more general?
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.
Admin
I've been doing C# for 13 years, I would call some of that code 'old' (but not 'ancient' like COBOL/C)
Admin
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.
Admin
hah
Admin
I do have a doctorate in ineptitude. They have no such excuse.
Admin
Admin
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...
Admin
Admin
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.
Admin
Admin
Admin
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?
Admin
If it touches a work system it become there's
Admin
The WTF is why you still work for them.
Admin