- 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
Admin
Admin
What was the question?
Admin
Admin
Admin
The real problem is with this David G. He shouldn't have assumed that his co-worker's switch statement wasn't intentional. There can be plenty of legitimate reasons for doing it this way, but David G. was too arrogant to find that out.
Admin
Admin
Admin
Admin
Admin
The real WTF was to teach geoffrey the use of his fingers. The remedy is to break them all off.
Admin
If you were in a performance sensitive environment you'd realise that the register and memory allocation of the compiler has very little resenblance to the exact things you write on your code. You should just have the compiler optimize memory access for you, and be done with that.
Admin
Admin
Dave counted at least four ... note that the code is C# .
So it is five then!
Admin
Why does the code care what the application is? If it's common code, it should do the same thing regardless of the application. If it's not doing the same thing, it shouldn't be common code and know what application it is.
Admin
So, umm, no.
Admin
Admin
Admin
Wait, what? It would issue a warning, sure - but it would still compile. Oh, unless of course you're being reckless and not treating warnings as errors; it's just that being reckless is the default.
Admin
A clear occurrence of stringly typed programming.
Admin
Stragedy: when the coding standard's gone and you can't go on it's...
Admin
Funny how closed questions on SO can sometimes be more interesting than open ones.
Oh well, I guess it's better for my productivity anyway.
Admin
I may be retarded here but would it not make more sense to have application id as a property?
i.e. int _applicationId = ApplicationUserInfo.Current.ApplicationType.applicationId;
or just not even bother with creating the variable in the first place and then just reference the object directly as and when needed?
Admin
Anybody who wonder what happened to Stradegy1 should look at the state of the current economy and it shall all be explained.
inhibeo: present active inhibeō, present infinitive inhibēre, perfect active inhibuī, supine inhibitum.
Admin
Admin
Admin
You could, but that would make sense and be far too simple.
Admin
You could, but that would make sense and be far too simple.
Admin
Seeing as enums resolve to ints, yeah... i would suspect that there's no need to cast/convert it to an int.
Admin
one line return (int)ApplicationUserInfo.Current.ApplicationType;
Added fun, What word is Stradegy Convert.ToInt32(ApplicationTypeEnum.Stradegy2); Convert.ToInt32(ApplicationTypeEnum.StradegyOnline);
Admin
Also, in .Net (C#, not sure about VB.Net), you would have to cast to int, even though the enum is of type int.
Admin
That is what code comments are for: turning a WTF in TIS a (This Is Why). Should I have to go track down some dev that might not even work for the company anymore to ask if there is any valid reason for the stupid-looking code?
Captcha: validus. The code might be validus, but I cannot find the developus to askus him.
Admin
Admin
Point being... you don't need both!!!
Admin
Bear in mind there are sometimes situations (this not being one of them) in which you want the code to fall through to the next case.
Admin
One of the wtfs people missed is stradegy when it should be strategy.
Admin
Simplifying the code significantly requires a bunch of assumptions that just aren't there.
You can't rely on the name of the enum members being correct if the assembly is obfuscated (though the original does make this assumption)
Based on the stuff that we've been given, we can't know if all of the values in the enum are being returned (or if there are application ids that are supposed to return 0)
Calls to ApplicationUserInfo.Current.ApplicationType may be non-idempotent, so we should probably only call it once.
We should also keep the convert.ToInt32() because the behavior of that is different to a (int) cast (convert runs the conversion as checked IIRC). This is almost certainly not going to be a problem, unless the IDs are being generated dynamically or something or the enum is backed with longs, but an overflow exception in the future is better than the application returning the wrong ID if/when someone decides to change the values in the enum or something. If we keep behavior identical, the testing required can be far more minimal.
Here's my stab at refactoring it based on the items above - the only way that we can be certain that we're not changing behavior means that we can't collapse it down to 1 line (though if we had the source we could clarify some of the above assumptions):
int ApplicationType { get { ApplicationTypeEnum applicationType = ApplicationUserInfo.Current.ApplicationType; switch (applicationType) { case ApplicationTypeEnum.Stradegy2: case ApplicationTypeEnum.AdDetector: //etc case ApplicationTypeEnum.FrenchAdex: return Convert.ToInt32(applicationType); case default: return 0; } } }
As you can see, it's not all that much better.
Admin
Maybe you are underestimating the genius of their "Stradegy"
Admin
Fail. Look at the JavaDoc comment of ordinal.