- 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
Admin
thats 2 lines!
captcha - 'nobis' almost noobis...sheeeesh.
Admin
It's a goddamned Greek stradegy
Admin
int _applicationId = Convert.ToInt32(ApplicationUserInfo.Current.ApplicationType);
?
Admin
int _applicationId = (int)ApplicationUserInfo.Current.ApplicationType;
Admin
Never even looked at c# in my life so I have to ask.
Couldn't you jsut type _applicationId as an enum?
CAPTCHA: jumentum ... made me giggle for some reason.
Admin
Wouldn't this be enough?
int _applicationId = ApplicationUserInfo.Current.ApplicationType;
Also... I wonder what 0 is.... probably something very dark and mysterious.
Admin
We have the EE version of this at my work, designed by The Architect Himself. It spans two maven modules but does roughly the same.
Admin
All of your suggestions ignore the case where the value of the ApplicationType was in the Enum but not in the hard coded list. Not the best method for handling something like a sale, but it would be functional.
Admin
jumentum? Where was it...
Ah, there: http://hardware.slashdot.org/story/11/10/23/0353245/jumentum-introduces-a-single-chip-linux-system
Admin
int _applicationId = (int)ApplicationUserInfo.Current.ApplicationType;
Admin
My first question is do you even need to store it in another variable. Why not just access ApplicationUserInfo.Current.ApplicationType when needed? Possibly they need it because ApplicationUserInfo is going to go out of scope. If you must store into another variable--
ApplicationTypeEnum _app = ApplicationUserInfo.Current.ApplicationType;
Admin
LOL, nice wtf throwing an exception :-)
Admin
WTF 1: You need to modify this routine every time that ApplicationTypeEnum changes WTF 2: Converting an enum to a string and then referring to the enum again WTF 3: Having a getter method called 'Set...' WTF 4: No default case, but instead returning 0 at a different location
Can be rewritten as
Note: I don't do C#, so if there's a problem with the libraries or the Convert.toInt32, I wouldn't know. In Java, I'd have written it as follows:
Admin
Right?
Admin
you're the winner!!
Admin
WTF5: in C# you're supposed to use Enum.GetName(...) instead of ToString() (see the Remarks section of the related MSDN article). WTF6: Convert.ToInt32() is useless when you can just cast to int. WTF7: there was probably no reason to convert it in the beginning.
Admin
I like the original WTF better than this, even though this might be correct.
Admin
There's no need to harp your trumpet on this fiddle of a flute. Everywhere you will find microcosms of the bizarre is a world that appears uniformly adherent to the edicts of The Brotherhood, but only to the shallow-minded.
Why can't we escape this torrent of confusion?
I would love to. But I would also love to not. Therein lies the crux of our misery and listlessness.
Free the surface of your home planet from your grasp and embrace the void. It will embrace you as well. It will love you more than any mammalian biped ever could - it will love you without end.
Good luck on your journey, brothers and sisters in code!
Admin
No. You need the explicit cast to int or the compiler will complain.
int _applicationId = (int) ApplicationUserInfo.Current.ApplicationType;
Admin
And also WTF8: I don't know what happens when you do all these ToString() stuff if it's a [Flags] enum, but it must not be pretty.
Admin
The only reason I can think off is for convenience (save typing ApplicationUserInfo.Current.ApplicationType - although intellisense makes this less of a problem) or maybe readability (perhaps _applicationId is a more meaningful name in the context of where it's being used).
Admin
TRWTF is that C# lets you put any int into any enum, so if the ApplicationUserInfo.Current.ApplicationType == 54321, this method will return 0, not 54321 like all your other examples do. I doubt, however, that the pseudo-default case ever shows up. PS. Is "stradegy" another word for "strategery"?
Admin
Admin
2011-10-24 08:16 • by ParkinT
TRWTF, how did first post 2 days before the post was posted?
Admin
If an application type isn't defined, then you're probably facing a bigger problem.
That said, the wonderful ternary operator may be used to obfuscate the solution into a single line:
return Enum.IsDefined(typeof(ApplicationTypeEnum), ApplicationUserInfo.Current.ApplicationType) ? (int)ApplicationUserInfo.Current.ApplicationType : 0;
Captcha: odio - odious code, yes.
Admin
Admin
I suspect this at least partially a fictional WTF, that code would never compile without break; after each return;
Admin
If you're in a performance sensitive environment assigning to a local value type variable would be much faster then referencing a property of a static class repeatedly.
Admin
Addendum (2011-10-26 10:00): Whoops, screwed the bbcode.
Admin
Admin
I suspect you're at least partially a C# developer, that code would definitely compile with return, which is a jump statement, as are break, goto case, and throw.
Admin
damn, burned!
Admin
If Alex told you jump outta window, y'all do, right?
Okay real fix now:
Admin
Dammit, the printer got onto the internet again.
Admin
Admin
The Real WTF: They spelled "Stragedy" wrong.
Admin
Doesn't matter if it went wrong, one always needs to have a backup stradegy.
Admin
Admin
Also, based on use of color tags, I'm guessing it's a slow morning? :)
Technical side note that I'm sure you know: the Enum.GetNames isn't guaranteed to return the correct (expected) enum name, especially when you obfuscate the assembly or build in release. One should use the DescriptionAttribute to decorate your enums.
Admin
Admin
Admin
Admin
Admin
A bit like the old joke:
Admin
You mean your curiosity SET the better of you...
return Convert.ToInt32(Enum.Parse(typeof(ApplicationTypeEnum), ApplicationUserInfo.Current.ApplicationType.ToString()));
In other words: return OCR(TakePicture(Print(ApplicationUserInfo.Current.ApplicationType.ToString())));
Parentheses pried from McCarthy's cold dead hands (RIP).
Admin
Another question to ask is where and how is
set?It's just a guess, but it seems that ApplicationUserInfo.Current.ApplicationType is probably only ever set once, most likely on app startup, and likely not based on user input. It should be validated only once before setting ApplicationUserInfo.Current.ApplicationType, and if it's not defined, throw the exception there.
That way you never have to validate that value again.
Admin
Admin
Admin