• (cs)

    You might think you can replace this gem with one line, but you can't. Because when "ApplicationUserInfo.Current.ApplicationType" is "ApplicationTypeEnum.Stradegy2" then "ApplicationUserInfo.Current.ApplicationType.toString()" returns "MagAdvisor".

    Fooled you, huh?

  • (cs) in reply to frits
    frits:
    C-Octothorpe:
    based on use of color tags, I'm guessing it's a slow morning?
    Ever since Hortical's disproportionate reaction to my use of color tags, I'm trying to use them whenever possible, slow morning or not.
    I think you missed a "where" in your syntax highlighting. Better post again. (Sorry Hortical)
  • (cs) in reply to boog
    boog:
    frits:
    C-Octothorpe:
    based on use of color tags, I'm guessing it's a slow morning?
    Ever since Hortical's disproportionate reaction to my use of color tags, I'm trying to use them whenever possible, slow morning or not.
    I think you missed a "where" in your syntax highlighting. Better post again. (Sorry Hortical)
    I'll have to take a look... 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.
  • (cs) in reply to frits
    frits:
    boog:
    frits:
    C-Octothorpe:
    based on use of color tags, I'm guessing it's a slow morning?
    Ever since Hortical's disproportionate reaction to my use of color tags, I'm trying to use them whenever possible, slow morning or not.
    I think you missed a "where" in your syntax highlighting. Better post again. (Sorry Hortical)
    I'll have to take a look... 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.
    And you're gonna need some reflection to get the description code, because you want to make it globalizable, right? We can add that in as an extension method.

    EDIT: now if you can make THAT a one-liner, I'll owe you beer and wings.

  • Jack S. (unregistered)

    Another wtf is that we don't know whether that function should merely convert the value or whether the intention was to filter it; maybe the writer was only interested in those 12 values.

  • (cs) in reply to Jack S.
    Jack S.:
    Another wtf is that we don't know whether that function should merely convert the value or whether the intention was to filter it; maybe the writer was only interested in those 12 values.
    Even if you give him/her that much credit (which is a LOT), there are still enough WTFs there to feed a small army.
  • Manadar (unregistered)

    Bonus points get!

    private int SetApplicationId(){ switch (ApplicationUserInfo.Current.ApplicationType.ToString()) { case "Stradegy2": return Convert.ToInt32(ApplicationTypeEnum.Stradegy2); case "AdDetector": return Convert.ToInt32(ApplicationTypeEnum.AdDetector); case "MagAdvisor": return Convert.ToInt32(ApplicationTypeEnum.MagAdvisor); case "AdDetectorAlerts": return Convert.ToInt32(ApplicationTypeEnum.AdDetectorAlerts); case "MarketAdvisorAdTel": return Convert.ToInt32(ApplicationTypeEnum.MarketAdvisorAdTel); case "NewspaperAdvisor": return Convert.ToInt32(ApplicationTypeEnum.NewspaperAdvisor); case "MarketAdvisorMarketSpender": return Convert.ToInt32(ApplicationTypeEnum.MarketAdvisorMarketSpender); case "StradegyOnline": return Convert.ToInt32(ApplicationTypeEnum.StradegyOnline); case "AdSpender": return Convert.ToInt32(ApplicationTypeEnum.AdSpender); case "Evaliant": return Convert.ToInt32(ApplicationTypeEnum.Evaliant); case "eBooks": return Convert.ToInt32(ApplicationTypeEnum.eBooks); case "FrenchAdex": return Convert.ToInt32(ApplicationTypeEnum.FrenchAdex); } return 0;}
  • Erdogan Kurtur (unregistered)

    4 Years ago, I had seen functions like this. I replaced them all. There was a function for each enum. There was about 50 enums :(

  • JB (unregistered)

    How come this story isn't the top hit for "stradegy"?

    https://www.google.com/search?q=stradegy

  • Mike (unregistered)

    Don't do it in a tight loop - the innocuous-seeming Enum.ToString and Enum.Parse invoke reflection to query the metadata and figure out the name you gave to that enumerated value.

    GetName uses a hash table for quick look-up; that hash table is filled when GetName is first used for the type and holds up to 100 types (though on the 101st it dumps the lot!). It uses a special function in the runtime optimized for this rather than the generic reflection system. It's still way more costly than a cast to int, though.

  • (cs)

    OK, correct answer is of course:

    int applicationId = (int)ApplicationUserInfo.Current.ApplicationType;
    ...but an even correcter answer would be:
    ApplicationTypeEnum appType = ApplicationUserInfo.Current.ApplicationType;
    ...why convert it to a loosely typed int in the first place? If it needs to be sent in as an argument for a method call then use:
    SomeMethod((int)appType);
    ...or better, just change the method to accept an enum of type ApplicationTypeEnum. And also changed the name of the type to just ApplicationType, drop the 'Enum', it's hungarian notation all over again.

  • (cs)
    <!-- This is a comment solely to annoy Hortical -->
  • odio (unregistered) in reply to ParkinT
    ParkinT:
    //FIRST - BRILLANT - PAULA - IRISH GIRL
    int _applicationId = Convert.ToInt32(ApplicationUserInfo.Current.ApplicationType.ToString());
    

    I didn't look if anyone corrected you yet, but the "ToString" there is going to do something you didn't want; correct is:

    int _applicationId = Convert.ToInt32(ApplicationUserInfo.Current.ApplicationType);

  • Anno (unregistered)

    TRWTF is that this site is all about poking fun at people who aren't good at writing code, but the person who runs the site is incapable of writing a single post without a typo, no matter how short that post is.

  • FrostCat (unregistered) in reply to Topper
    Topper:
    WTF6: Convert.ToInt32() is useless when you can just cast to int.

    Moreso, you can write an implicit conversion so you can skip the explicit cast!

  • gonzalo (I couldn't login don't know why :( ) (unregistered) in reply to C# Developer

    this is not true.. without the break after each return will not compile...

  • (cs) in reply to ParkinT
    ParkinT:
    //FIRST - BRILLANT - PAULA - IRISH GIRL
    int _applicationId = Convert.ToInt32(ApplicationUserInfo.Current.ApplicationType.ToString());
    
    .
    fTFY (frits'd That For You)
  • dolor (unregistered) in reply to Mmmpf
    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.

  • AerieC (unregistered) in reply to Manadar
    Manadar:
    Bonus points get!
    private int SetApplicationId(){ switch (ApplicationUserInfo.Current.ApplicationType.ToString()) { case "Stradegy2": return Convert.ToInt32(ApplicationTypeEnum.Stradegy2); case "AdDetector": return Convert.ToInt32(ApplicationTypeEnum.AdDetector); case "MagAdvisor": return Convert.ToInt32(ApplicationTypeEnum.MagAdvisor); case "AdDetectorAlerts": return Convert.ToInt32(ApplicationTypeEnum.AdDetectorAlerts); case "MarketAdvisorAdTel": return Convert.ToInt32(ApplicationTypeEnum.MarketAdvisorAdTel); case "NewspaperAdvisor": return Convert.ToInt32(ApplicationTypeEnum.NewspaperAdvisor); case "MarketAdvisorMarketSpender": return Convert.ToInt32(ApplicationTypeEnum.MarketAdvisorMarketSpender); case "StradegyOnline": return Convert.ToInt32(ApplicationTypeEnum.StradegyOnline); case "AdSpender": return Convert.ToInt32(ApplicationTypeEnum.AdSpender); case "Evaliant": return Convert.ToInt32(ApplicationTypeEnum.Evaliant); case "eBooks": return Convert.ToInt32(ApplicationTypeEnum.eBooks); case "FrenchAdex": return Convert.ToInt32(ApplicationTypeEnum.FrenchAdex); } return 0;}

    Damn, lol. Beat me to it.

  • Hortical (unregistered) in reply to frits
    frits:
    C-Octothorpe:
    based on use of color tags, I'm guessing it's a slow morning?
    Ever since Hortical's disproportionate reaction to my use of color tags, I'm trying to use them whenever possible, slow morning or not.
    DIE FRITS DIE

    oohhhh... I'm feeling woozy. Maybe I should just use a pen...

  • Topper (unregistered) in reply to C-Octothorpe
    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!
  • m0sh (unregistered)

    Strategy + Tragedy = Stradegy

  • dave g (unregistered) in reply to Topper
    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!

  • (cs) in reply to HP PhaserJet
    HP PhaserJet:
    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!

    Your meking hard atempt at troling, but low on humerus content. Sorry brother!

  • (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!

    kidney bean?

  • (cs) in reply to dave g
    dave g:
    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.
    I figured as much.

    Also, TRWTF is #9: who ever wrote the app(s) didn't use OO principles and simply declare functionality in interfaces or an abstract base class.

  • r66 (unregistered)

    private int SetApplicationId() { switch (ApplicationUserInfo.Current.ApplicationType.ToString()) { case "Stradegy2": return Convert.ToInt32(ApplicationTypeEnum.Stradegy2); case "AdDetector": return Convert.ToInt32(ApplicationTypeEnum.AdDetector); case "MagAdvisor": return Convert.ToInt32(ApplicationTypeEnum.MagAdvisor); case "AdDetectorAlerts": return Convert.ToInt32(ApplicationTypeEnum.AdDetectorAlerts); case "MarketAdvisorAdTel": return Convert.ToInt32(ApplicationTypeEnum.MarketAdvisorAdTel); case "NewspaperAdvisor": return Convert.ToInt32(ApplicationTypeEnum.NewspaperAdvisor); case "MarketAdvisorMarketSpender": return Convert.ToInt32(ApplicationTypeEnum.MarketAdvisorMarketSpender); case "StradegyOnline": return Convert.ToInt32(ApplicationTypeEnum.StradegyOnline); case "AdSpender": return Convert.ToInt32(ApplicationTypeEnum.AdSpender); case "Evaliant": return Convert.ToInt32(ApplicationTypeEnum.Evaliant); case "eBooks": return Convert.ToInt32(ApplicationTypeEnum.eBooks); case "FrenchAdex": return Convert.ToInt32(ApplicationTypeEnum.FrenchAdex);

    }
    return "FILE NOT FOUND";
    

    }

  • (cs) in reply to Severity One
    Severity One:
    WTF 4: No default case, but instead returning 0 at a different location

    I don't do C# either, but if it's like most languages wouldn't control just fall through the entire switch statement and move onto the return 0 if it didn't match any case?

    I think most would consider it poor style, but not necessarily a wtf on its own. But now I'm just nitpicking I guess.

  • (cs) in reply to Mmmpf
    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.

    Throw, yeah, that's what I just fucking did.

  • (cs) in reply to C-Octothorpe
    C-Octothorpe:
    Another question to ask is where and how is
    ApplicationUserInfo.Current.ApplicationType
    set?
    Meh, that's obvious.

    It is set in a method called

    private void GetApplicationId(ApplicationTypeEnum applicationId_)
    
  • (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!

    If Mr T. Experience gets to him first, you might not need to give him the wings, he might just be getting a pair of his own. Or horns.

  • (cs) in reply to m0sh
    m0sh:
    Strategy + Tragedy = Stradegy

    Strad + e(d)gy: Nigel Kennedy?

  • JLC (unregistered) in reply to Zach

    She's brilliant, obviously.

  • Wonk (unregistered) in reply to Hortical
    Hortical:
    frits:
    C-Octothorpe:
    based on use of color tags, I'm guessing it's a slow morning?
    Ever since Hortical's disproportionate reaction to my use of color tags, I'm trying to use them whenever possible, slow morning or not.
    DIE FRITS DIE

    oohhhh... I'm feeling woozy. Maybe I should just use a pen...

    No, no, no. That's just German for "The Frits, the."

  • Unknown coward (unregistered)

    I don't know C# but I bet I could replace that gem with one line. Just don't ask me to make it one statement . . .

    Zing!

  • (cs) in reply to Fool

    Yeah, that's what I'd do.

  • (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?

    CAPTCHA: jumentum ... made me giggle for some reason.

    Yeah, that's what I'd do.

  • Rubix (unregistered)

    WTF? The function should be named "GetApplicationId()"

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

    No, I'm pretty sure that's valid. If you put a break after the return, you would get an "unreachable code" warning.

  • Tom (unregistered) in reply to Unknown coward
    I don't know C# but I bet I could replace that gem with one line. Just don't ask me to make it one statement . . .

    Since ApplicationName is an enum, you can just do a simple typecast. In general, typecasting an enum to int (or whatever the underlying value type is) just gives you back the enumeration value.

    So if you wrote something like enum names { Tom=1, Jeff=2 }

    int num=(int)names.Tom;

    num would end up as 1.

  • (cs) in reply to Tom
    Tom:
    I don't know C# but I bet I could replace that gem with one line. Just don't ask me to make it one statement . . .

    Since ApplicationName is an enum, you can just do a simple typecast. In general, typecasting an enum to int (or whatever the underlying value type is) just gives you back the enumeration value.

    So if you wrote something like enum names { Tom=1, Jeff=2 }

    int num=(int)names.Tom;

    num would end up as 1.

    So there are cases where casting *won't* return the underlying value? Interesting...
  • Tom (unregistered) in reply to Mike
    Don't do it in a tight loop - the innocuous-seeming Enum.ToString and Enum.Parse invoke reflection to query the metadata and figure out the name you gave to that enumerated value.

    You're missing the whole point, though.

    This thing simply converts an int-based enum to its underlying integer value.

    x=(int) y;

    that's all that's required yere.

  • (cs) in reply to Wonk
    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.
  • (cs) 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.
    Well duh... I thought everybody knew the Dutch are the only *real* evil people.
  • Devil's advocate (unregistered)

    All of your one line solutions are wrong. This will print 2, which should be 0 according to the original method being replace.

    public enum Foo { Test = 1 } class Program { static void Main(string[] args) { Foo bar = (Foo)2; Console.WriteLine((int)bar); } }

  • your mom (unregistered)

    hmm... was this supposed to be anonymized? a quick google search brings up http://kantarmediana.com/intelligence/products

  • Hortical (unregistered) in reply to C-Octothorpe
    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.
    I remember hearing that Hitler may have been part Jewish...

    so...

    he was right?

  • me (unregistered) in reply to Hortical

    Hitler wasn't all bad, after all he did kill Hitler.

  • Turcogj (unregistered) in reply to Zach

    That is exactly what I was thinking. Why bother with the casting, you have an Enum setup! Now you have strongly type code.

  • (cs) in reply to C-Octothorpe
    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?

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

Log In or post as a guest

Replying to comment #364731:

« Return to Article