• (cs) in reply to boog
    boog:
    C-Octothorpe:
    boog:
    Wonk:
    Hortical:
    DIE FRITS DIE
    No, no, no. That's just German for "The Frits, the."
    No one who speaks German could be an evil man.
    Well duh... I thought everybody knew the Dutch are the only *real* evil people.
    Not a Simpsons fan, I take it?
    I am a fan and I got the first two references, but I forgot about the "nobody who speaks German can be evil" part.
  • (cs) in reply to C-Octothorpe
    C-Octothorpe:
    boog:
    C-Octothorpe:
    boog:
    Wonk:
    Hortical:
    DIE FRITS DIE
    No, no, no. That's just German for "The Frits, the."
    No one who speaks German could be an evil man.
    Well duh... I thought everybody knew the Dutch are the only *real* evil people.
    Not a Simpsons fan, I take it?
    I am a fan and I got the first two references, but I forgot about the "nobody who speaks German can be evil" part.
    But that part of the joke is crucial to the plot. *sigh* </genuine-worry>
  • Hortical (unregistered) in reply to boog
    boog:
    C-Octothorpe:
    boog:
    Wonk:
    Hortical:
    DIE FRITS DIE
    No, no, no. That's just German for "The Frits, the."
    No one who speaks German could be an evil man.
    Well duh... I thought everybody knew the Dutch are the only *real* evil people.
    Not a Simpsons fan, I take it?
    Oh, especially C-Octothorpe, but especially boog.
  • phreddy (unregistered) in reply to Bronie

    What was the question?

  • Mark (unregistered) in reply to C# Developer
    C# Developer:
    I suspect this at least partially a fictional WTF, that code would never compile without break; after each return;
    Sure about that?
  • Jiommy (unregistered) in reply to Zach
    Zach:
    2011-10-24 08:16 • by ParkinT
    ParkinT:
    //FIRST - BRILLANT - PAULA - IRISH GIRL
    int _applicationId = Convert.ToInt32(ApplicationUserInfo.Current.ApplicationType.ToString());
    

    TRWTF, how did first post 2 days before the post was posted?

    Good Pick Up!!!
  • geoffrey (unregistered)

    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.

  • etr (unregistered) in reply to dolor
    dolor:
    Mmmpf:
    C# Developer:
    I suspect this at least partially a fictional WTF, that code would never compile without break; after each return;

    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.

    I think that return; break; would actually not compile at all.

    Tink you right. Unreachable statement....

  • AssHole (unregistered) in reply to dave g
    dave g:
    Topper:
    Topper:
    Severity One:
    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

        return Convert.toInt32(ApplicationUserInfo.Current.ApplicationType);

    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:

        return applicationUserInfo.current.applicationType.ordinal();

    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.

    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.

    WTF7 is the real winner! No need to convert it in the first place. _applicationId should be of type ApplicationTypeEnum to begin with.

    And yes, ApplicationTypeEnum.None = 0

    ApplicationUserInfo.Current.ApplicationType is set when the user logs into one of the applications listed and is a static method, (sorry, didn't mention that) so there is no reason for this method in the first place.

    Thank you all for playing!

    TRWTF: I didn't obfuscate the names!

    So....we lag you in to King Kantar, eh?

  • Basil Fawlty (unregistered) in reply to boog
    boog:
    Wonk:
    Hortical:
    DIE FRITS DIE
    No, no, no. That's just German for "The Frits, the."
    No one who speaks German could be an evil man.
    Don't mention the war....
  • (cs) in reply to C-Octothorpe
    C-Octothorpe:
    boog:
    C-Octothorpe:
    boog:
    Wonk:
    Hortical:
    DIE FRITS DIE
    No, no, no. That's just German for "The Frits, the."
    No one who speaks German could be an evil man.
    Well duh... I thought everybody knew the Dutch are the only *real* evil people.
    Not a Simpsons fan, I take it?
    I am a fan and I got the first two references, but I forgot about the "nobody who speaks German can be evil" part.
    Ja, das ist korrekt.
  • (cs) in reply to geoffrey
    geoffrey:
    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.

    The real WTF was to teach geoffrey the use of his fingers. The remedy is to break them all off.

  • (cs) in reply to Josh
    Josh:
    Anon:
    Zach:
    My first question is do you even need to store it in another variable.

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

    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.

    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.

  • (cs) in reply to Topper
    Topper:
    C-Octothorpe:
    frits:
    Maybe I should write a C#toBBCode utility. If I fix my previous post, I should address the bug C-Octo pointed out by adding a dictionary query with some lambda expressions.
    EDIT: now if you can make THAT a one-liner, I'll owe you beer and wings.
    That's nothing! I'll give him a kidney!
    That's nothing! I'll give him both your kidneys!
  • Anonymous (unregistered)

    Dave counted at least four ... note that the code is C# .

    So it is five then!

  • wydok (unregistered)

    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.

  • (cs) in reply to your mom
    your mom:
    hmm... was this supposed to be anonymized? a quick google search brings up http://kantarmediana.com/intelligence/products
    (from comment #364711)
    dave g:
    Thank you all for playing!

    TRWTF: I didn't obfuscate the names!

    So, umm, no.

  • (cs) in reply to geoffrey
    geoffrey:
    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.
    David G was too busy tying up the print queue with running applications to have time to find stuff out.
  • (cs) in reply to bebna
    bebna:
    jumentum? Where was it...

    Ah, there: http://hardware.slashdot.org/story/11/10/23/0353245/jumentum-introduces-a-single-chip-linux-system

    Oh, good. A source for new trade names. Any takers for the "Lorem ipsum" chipset?

  • (cs) in reply to etr
    etr:
    dolor:
    Mmmpf:
    C# Developer:
    I suspect this at least partially a fictional WTF, that code would never compile without break; after each return;

    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.

    I think that return; break; would actually not compile at all.

    Tink you right. Unreachable statement....

    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.

  • (cs)

    A clear occurrence of stringly typed programming.

  • (cs) in reply to Nagesh

    Stragedy: when the coding standard's gone and you can't go on it's...

  • Mmmpf (unregistered) in reply to Musaran
    Musaran:
    A clear occurrence of stringly typed programming.

    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.

  • Anon Too (unregistered)

    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?

  • Corporate drone (unregistered)

    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.

    I lay hold of, keep back, restrain, curb, check, stop.
    I hinder, prevent, inhibit.
    I practise, perform, use, employ.
    
  • (cs) in reply to Watson
    Watson:
    bebna:
    jumentum? Where was it...

    Ah, there: http://hardware.slashdot.org/story/11/10/23/0353245/jumentum-introduces-a-single-chip-linux-system

    Oh, good. A source for new trade names. Any takers for the "Lorem ipsum" chipset?
    I've already submitted an application to trademark "Valetudo".

  • (cs) in reply to Mmmpf
    Mmmpf:
    Musaran:
    A clear occurrence of stringly typed programming.

    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.

    That's even more true of programmers.stackexchange. Questions with a correct answer are closed as not subjective. Questions that are too subjective are also closed, as are questions that actually merit discussion. What's left are questions where everyone engages in groupthink for rep and downvotes anyone with an original opinion.

  • (cs) in reply to Fool

    You could, but that would make sense and be far too simple.

  • (cs) in reply to Fool
    Fool:
    Never even looked at c# in my life so I have to ask.

    Couldn't you jsut type _applicationId as an enum?

    You could, but that would make sense and be far too simple.

  • big picture thinker (unregistered) in reply to TheSHEEEP
    TheSHEEEP:
    Wouldn't this be enough?

    int _applicationId = ApplicationUserInfo.Current.ApplicationType;

    Also... I wonder what 0 is.... probably something very dark and mysterious.

    Seeing as enums resolve to ints, yeah... i would suspect that there's no need to cast/convert it to an int.

  • lindholm (unregistered)

    one line return (int)ApplicationUserInfo.Current.ApplicationType;

    Added fun, What word is Stradegy Convert.ToInt32(ApplicationTypeEnum.Stradegy2); Convert.ToInt32(ApplicationTypeEnum.StradegyOnline);

  • (cs) in reply to big picture thinker
    big picture thinker:
    TheSHEEEP:
    Wouldn't this be enough?

    int _applicationId = ApplicationUserInfo.Current.ApplicationType;

    Also... I wonder what 0 is.... probably something very dark and mysterious.

    Seeing as enums resolve to ints, yeah... i would suspect that there's no need to cast/convert it to an int.

    Enums can be defined as Double, Float, etc., not just Int32. It does default to int, though.

    Also, in .Net (C#, not sure about VB.Net), you would have to cast to int, even though the enum is of type int.

  • Dotan Cohen (unregistered) in reply to geoffrey
    geoffrey:
    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.

    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.

  • Dirk (unregistered) in reply to ParkinT
    ParkinT:
    //FIRST - BRILLANT - PAULA - IRISH GIRL
    int _applicationId = Convert.ToInt32(ApplicationUserInfo.Current.ApplicationType.ToString());
    
    Ummm.... FAIL!! "eBooks" doesn't convert to Int32 in my universe. Hasty douche bag!
  • iMalc (unregistered) in reply to gonzalo (I couldn't login don't know why :( )
    gonzalo (I couldn't login don't know why :( ):
    this is not true.. without the break after each return will not compile...
    Rubbish! In fact doing that would probably get you unreachable code warnings. You can have two consecutive case statements with no code between them. Then the moment you put code between them to keep the compiler happy all you have to do is ensure that it can't fall through to the next case. return does that equally as well as break does. Heck continue would work too if this switch statement were inside a loop.

    Point being... you don't need both!!!

  • (cs) in reply to iMalc
    iMalc:
    gonzalo (I couldn't login don't know why :( ):
    this is not true.. without the break after each return will not compile...
    Rubbish! In fact doing that would probably get you unreachable code warnings. You can have two consecutive case statements with no code between them. Then the moment you put code between them to keep the compiler happy all you have to do is ensure that it can't fall through to the next case. return does that equally as well as break does. Heck continue would work too if this switch statement were inside a loop.

    Point being... you don't need both!!!

    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.

  • Omego2K (unregistered)

    One of the wtfs people missed is stradegy when it should be strategy.

  • My Name (unregistered)

    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.

  • Dave Edelhart (unregistered)

    Maybe you are underestimating the genius of their "Stradegy"

  • snapsnapsnap (unregistered) in reply to Severity One

    Fail. Look at the JavaDoc comment of ordinal.

Leave a comment on “Count The WTF: Conversion Go-Round”

Log In or post as a guest

Replying to comment #:

« Return to Article