CompareObjectAsIAlertDocumentOrNullIfNotCastable and More

  • serguey123 2010-12-20 11:24
    First?

    And no, this is not spam, you soulcrushing scrip!
  • Mythran 2010-12-20 11:25
    This comment is very important. DO NOT TOUCH!
  • NotFirst 2010-12-20 11:26
    bool memberHasFirstComment = bool.Parse(bool.FalseString);
  • Power Troll 2010-12-20 11:31
    The colon is very important. DO NOT TOUCH.


    That's what she said.
  • Wormlore 2010-12-20 11:31
    That is not the worst way to set a boolean to False.
    Something like this would have been "less good"

    bool memberHasFingerprint = !bool.Parse(bool.TrueString);

    And I'm sure someone creative enough could come up with something worst yet.

  • Rictor 2010-12-20 11:31
    Seems like this programmer had a bit of a potty mouth...

    Private Function FnPtrToLong(ByVal lngFnPtr As Integer) As Integer
  • Bobbo 2010-12-20 11:32
    The Article:
    # The colon is very important. DO NOT TOUCH.


    throw new AccessViolationException("Ouch, that's cold");
  • DOA 2010-12-20 11:33
    unless custId is 1521.
    The one constant in every software development department.
  • frits 2010-12-20 11:34
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    .

    Really? Replace them when you see them? You would think there would be an automated way to "find and replace" such "atrocities" with such a useful "fix". Nevermind the fact that this fix is as least as dumb as the original. At least.
  • trwtf 2010-12-20 11:35

    for (var i:int = 0; i < 100; i++){
    var rand:int = Math.random() * 6;
    }
    SoundHandler.playExternalSounds(["positive_override" + rand]);



    The loop makes it more random, you see...
  • tim 2010-12-20 11:37
    Actually I remember doing something like the 'pointer to long' in fortran on VMS once

    IIRC fortran didn't have pointers but it was possible to call C functions like malloc. however, the only way to get the return value from malloc into an int was to hide it inside an additional layer of function call because fortran is less funny about type coercions across function boundaries

    but of course if that example wasn't VMS fortran then it is a WTF ;-)
  • XX 2010-12-20 11:40
    A good developer never forgets about FileNotFound.

    bool memberHasFingerprint;
    try {
    memberHasFingerprint = bool.Parse(FileNotFoundString);
    catch (FormatException) {
    memberHasFingerprint = !bool.Parse(bool.TrueString);
    }
  • tim 2010-12-20 11:41
    Wormlore:
    That is not the worst way to set a boolean to False.
    Something like this would have been "less good"

    bool memberHasFingerprint = !bool.Parse(bool.TrueString);

    And I'm sure someone creative enough could come up with something worst yet.


    oh go on then

    bool memberHasFingerprint = (bool.Parse(bool.TrueString) == !bool.Parse(bool.TrueString))

    (i can feel the slippery slope coming on)
  • luis.espinal 2010-12-20 11:41
    Aaron's code comment feel deja vu to me from one project I endured many moons ago... like man, it does speak to me, like, literally!
  • boog 2010-12-20 11:42

    /*
    * See, this is why I hate my job. We start out doing some magical end-all solution for a may be customer, the
    * "XML Engine" hazily devised by IT iliterate decision makers without a clue what it's should do or who wants it. Ignore
    * that the codebase as is needs refactoring and fixing, let's ignore that we have a todo list a mile long, let's make
    * up requirements on top of that! Then, when reality kicks in and the may be customer isn't, we have semi-finished
    * shit clogging up all code arteries with poison. But noooo, don't clean it up, let's hack something else together
    * like this cover control thing, blah blah boohoo blah...
    */

    Sounds like this crap should be in his journal. Or if you check there maybe you'll find useful comments about the code?
  • Gary 2010-12-20 11:48
    trwtf:

    for (var i:int = 0; i < Math.random() * 100; i++){
    var rand:int = Math.random() * 6;
    }
    SoundHandler.playExternalSounds(["positive_override" + rand]);



    The loop makes it more random, you see...


    FTFY. Even more random now.
  • ShatteredArm 2010-12-20 11:49
    if (oneHundred == 100) {
    
    oneHundred /= 2;
    }


    Looks like oneHundred can be anything except 100.
  • digitalwitch 2010-12-20 11:49
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"


    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    There is something to be said for readability. Just because you can do something in one line doesn't mean you should.
  • Anything you can do, I can do worse 2010-12-20 11:51
    bool memberHasFingerprint = true; // set fingerprint presence to false...
  • Honest Guy 2010-12-20 11:53
    The Article:

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }

    public static bool IsRealString(object s)
    {
    return s // removed crap I don't understand, for readability
    }
  • Jellineck 2010-12-20 11:53
    digitalwitch:
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"


    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    There is something to be said for readability. Just because you can do something in one line doesn't mean you should.


    He just learned the coalesce operator and he wants to use it everywhere.
  • Rand Dumm 2010-12-20 11:54
    trwtf:

    for (var i:int = 0; i < 100; i++){
    var rand:int = Math.random() * 6;
    }
    SoundHandler.playExternalSounds(["positive_override" + rand]);

    The loop makes it more random, you see...
    Shouldn't you loop a random number of times, so you don't get the same result every time you run it?
  • Anon 2010-12-20 11:56
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }



    Why test if an empty string is empty (if s is null)? Seem like inlining the code from the original functions would be better. Which is probably what the compiler does anyway. And it's more readable. Once again the suggested fix is TRWTF.
  • Dazed 2010-12-20 11:58
    Well, I'm all in favour of comments which explain why code was written in a particular way. Aaron's predecessor's comment isn't quite what I usually have in mind, but at least it heads off all the folks around here who cry "what the hell were they thinking?"
  • Bosshog 2010-12-20 11:59

    if (oneHundred == 100) {
    oneHundred /= 2;
    }

    In Soviet Russia, Integer divides *you*.
  • Bobrot 2010-12-20 12:01
    DOA:
    unless custId is 1521.
    The one constant in every software development department.


    I remember that one. French guy had to see the site in English. (some sort of language preference was just too easy)
  • Ikkonoishi 2010-12-20 12:05
    tim:

    oh go on then

    bool memberHasFingerprint = (bool.Parse(bool.TrueString) == !bool.Parse(bool.TrueString))

    (i can feel the slippery slope coming on)

    bool memberHasFingerprint;
    WebClient wc = new WebClient();
    string[] fs = wc.DownloadString("http://msdn.microsoft.com/en-us/library/system.boolean.truestring.aspx").Split("\"",3000);
    foreach (string fss in fs)
    {
    if (s == bool.TrueString) memberHasFingerprint = !bool.Parse(fss);
    }
  • kastein 2010-12-20 12:07
    NotFirst:
    bool memberHasFirstComment = bool.Parse(bool.FalseString);


    bool memberHasFirstComment = bool.Parse(bool.FalseString);

    users.NotFirst.comment = bool.Parse(memberHasFirstComment);
  • Patrek 2010-12-20 12:09
    Got that in code I had to maintain (another language, but still):
    boolean isVerified = temp.equalsIgnoreCase("yes") ? new Boolean(true).booleanValue() : new Boolean(false).booleanValue(); 

  • Timmorn 2010-12-20 12:10
    Honest Guy:

    public static bool IsRealString(object s)

    {
    return s; // removed crap I don't understand, for readability
    // The colon is very important. DO NOT TOUCH.
    }


    Fixed it for you
  • RBiter 2010-12-20 12:13
    .. whew! cuz I thought it was from someone in my place. I certainly recognize that number!
    ;
  • Pyrexkidd 2010-12-20 12:16
    Wormlore:
    That is not the worst way to set a boolean to False.
    Something like this would have been "less good"

    bool memberHasFingerprint = !bool.Parse(bool.TrueString);

    And I'm sure someone creative enough could come up with something worst yet.




    unless ($five_thousand != m//){
    open $FHIN, '<', "list_of_bool_values.file";
    foreach(<$FHIN>){
    &return_false;
    if ($five_thousand != $five_thousand){
    $five_thousand = "false";
    } else {
    $five_thousand = "true";
    }
    $five_thousand ? s/true//g : s/false//g;

    }

    sub return_false($){
    #So it MIGHT look like
    #this sub doesn't do anything;
    #well, actually you're right
    # but that's ok, because I checked it
    #in and our of source control for every line.
    return;
    }
  • Ancient Greek Guy 2010-12-20 12:17

    if(person.age>18 || person.gender == female)
    {
    ewww();
    }
    else
    {
    touchColon();
    }
  • ContraCorners 2010-12-20 12:18
    But, FnPtrToLong neither accepts nor a returns a long. Both are integers, no?

    Or was that the WTF?
  • Anon 2010-12-20 12:39
    Ancient Greek Guy:

    if(person.age>18 || person.gender == female)
    {
    ewww();
    }
    else
    {
    touchColon();
    }


    Priest function?
  • Bob 2010-12-20 12:39
    "[D]evised by IT iliterate[sic] decision makers without a clue what it's[sic] should do or who wants it."

    Was he being ironic?
  • forgottenlord 2010-12-20 12:50

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    Ok, I've never seen this operator before. Yes, it is a flash of ignorance on my part, though a quick check through the code base of my company's code (and there have been a fair number of C# developers here) I can't find a single instance of it being used. Why, we just didn't, collectively, know it. Mind you, most of us got our degrees while programming in Java or C/C++ so maybe it is just that it wasn't part of those languages. Either way, it's not really a WTF. It's a failure of knowledge rather than technique.
  • the beholder 2010-12-20 13:07
    frits:
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    Nevermind the fact that this fix is as least as dumb as the original. At least.
    See, our store is having this great sale on sarcasm detectors...
  • NOT an ancient Greek guy 2010-12-20 13:14
    Anon:
    Ancient Greek Guy:

    if(person.age>18 || person.gender == female)
    {
    ewww();
    }
    else
    {
    touchColon();
    }


    Priest function?


    Nah, he's just an ancient Greek. It's cool. They touch the colons of boys all the time.
  • Andrew 2010-12-20 13:18
    ContraCorners:
    But, FnPtrToLong neither accepts nor a returns a long. Both are integers, no?

    Or was that the WTF?

    It looks like RealBasic to me. RB allows mixing and matching of numeric datatypes through implicit coercion so that you can pass a 64 bit signed number (Long) to a function that accepts 32 bit signed numbers (Integer), return an Integer and treat it like a Long.
  • frits 2010-12-20 13:22
    the beholder:
    frits:
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    Nevermind the fact that this fix is as least as dumb as the original. At least.
    See, our store is having this great sale on sarcasm detectors...


    Yeah I don't think so. Sarcasm involves intentional irony and humor. Show me those two elements.
  • Mordred 2010-12-20 13:43
    What we are looking at here folks are samples from the pioneers of coding. If it weren't for these idiots, why we wouldn't have the super idiots we have today.
  • Coyne 2010-12-20 13:44
    Actually, it turns out that the longer version of the IsNullOrEmpty() test that Anthony Arnold reported was needed in earlier versions of .NET. See:

    DANGER ! String.IsNullOrEmpty can lead to runtime Null exceptions !!

    So which is the bigger WTF here: Writing it this way? Or having to write it this way because your compiler doesn't optimize right?

    P.S. ...and, to top it all off, Anthony might be doing the wrong thing. Let's hope his compiler works right.
  • Anon 2010-12-20 13:47
    forgottenlord:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    Ok, I've never seen this operator before. Yes, it is a flash of ignorance on my part, though a quick check through the code base of my company's code (and there have been a fair number of C# developers here) I can't find a single instance of it being used. Why, we just didn't, collectively, know it. Mind you, most of us got our degrees while programming in Java or C/C++ so maybe it is just that it wasn't part of those languages. Either way, it's not really a WTF. It's a failure of knowledge rather than technique.


    I don't think it existed before the introduction of nullable types in C#. I wasn't familiar with it either having start with .NET 1.0.
  • frits 2010-12-20 13:56
    Coyne:
    Actually, it turns out that the longer version of the IsNullOrEmpty() test that Anthony Arnold reported was needed in earlier versions of .NET. See:

    DANGER ! String.IsNullOrEmpty can lead to runtime Null exceptions !!

    So which is the bigger WTF here: Writing it this way? Or having to write it this way because your compiler doesn't optimize right?

    P.S. ...and, to top it all off, Anthony might be doing the wrong thing. Let's hope his compiler works right.


    Anthony's method is functionally equivalent as far as null checking goes. TRWTF is having a method called "IsRealString" that checks an object instead of a string. In other words, the call to .ToString() is the fly in the ointment here.

  • boog 2010-12-20 14:01
    frits:
    Yeah I don't think so. Sarcasm involves intentional irony and humor. Show me those two elements.

    Not an easy task. Sure, one can show humor simply by laughing (ha), and it's clear that the "fix" was ironically as bad or worse than the original (you've admitted that yourself). However, the challenge lies in proving that these traits were intentional. Certainly the reader inferring the submitter's intentions would be subjective, and therefore worthless. What we need is some form of empirical evidence proving that the submitter intended to be ironic and humorous, or that said irony/humor was purely accidental. This may take a while.

    Oh, wait. This is a forum on the internet, so no one cares.

    My mistake.
  • ÃÆâ€â„ 2010-12-20 14:03
    What, so you guys don't touch your colons? Boy, are you missing out.
  • Two 2010-12-20 14:12
    DOA:
    unless custId is 1521.
    The one constant in every software development department.


    oracleDbPortNum = 1521
  • yetihehe 2010-12-20 14:15
    <?php include sitename(__COMMENT__).'/../../../omgponies.com/public_html/comment_view.php'; ?>

    on the other hand, they could do it like this:
    eval(file_get_contents('othersite'));
  • Two 2010-12-20 14:15
    ShatteredArm:
    if (oneHundred == 100) {
    
    oneHundred /= 2;
    }


    Looks like oneHundred can be anything except 100.


    Unless it starts out at 200 ...
  • unekdoud 2010-12-20 14:16
    Not random enough!

    for (var i:int = Math.random(); i < ((Math.random()+Math.random()+Math.random()+Math.random()+Math.random())*
    (Math.random()+Math.random()+Math.random()+Math.random()+Math.random()*
    (Math.random()+Math.random()+Math.random()+Math.random()+Math.random()*
    (Math.random()+Math.random()+Math.random()+Math.random()+Math.random());
    i += Math.random()*Math.random()*Math.random()){

    var rand:int = Math.random() * 6;

    }

    SoundHandler.playExternalSounds(["positive_override" + rand]);


    Or perhaps I misread the code and the numbers 0 and 100 are generated by fair dice roll.
  • better wtfs 2010-12-20 14:17
    I first read it as

    for (var i:int = 0; i < 100; i++){
    var rand:int = Math.random() * 6;
    SoundHandler.playExternalSounds(["positive_override" + rand]);
    }

    which would have been much funnier
  • apaq11 2010-12-20 14:24
    This one is scattered through one of our product's code base.

    bool someVar = thisVar ? false : thisVar;

  • boog 2010-12-20 14:26
    Two:
    ShatteredArm:
    if (oneHundred == 100) {
    
    oneHundred /= 2;
    }


    Looks like oneHundred can be anything except 100.


    Unless it starts out at 200 ...

    So you believe that 200 == 100 then, do you?

    Interesting...
  • webrunner 2010-12-20 14:29
    I think a certain dev heard "You should leave comments in the code" and kind of misunderstood what was meant by "comment".
  • frits 2010-12-20 14:32
    frits:
    the beholder:
    frits:
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    Nevermind the fact that this fix is as least as dumb as the original. At least.
    See, our store is having this great sale on sarcasm detectors...


    Yeah I don't think so. Sarcasm involves intentional irony and humor. Show me those two elements.

    Your so dumb I'm ashamed to be you're fake double. You obviously have no clue what "irony" is. Something I would expect from someone who doesn't know where to put the comma.
    Good enough?
  • Scott 2010-12-20 14:47
    What language is number 2?
  • false 2010-12-20 15:05


    The colon is very important. DO NOT TOUCH!
  • bluesman 2010-12-20 15:13
    I've touched your colon. Pray I don't...

    Wait... Blech... Never mind.
  • daily 2010-12-20 15:13

    /*
    * See, this is why I hate my job. We start out doing some magical end-all solution for a may be customer, the
    * "XML Engine" hazily devised by IT iliterate decision makers without a clue what it's should do or who wants it. Ignore
    * that the codebase as is needs refactoring and fixing, let's ignore that we have a todo list a mile long, let's make
    * up requirements on top of that! Then, when reality kicks in and the may be customer isn't, we have semi-finished
    * shit clogging up all code arteries with poison. But noooo, don't clean it up, let's hack something else together
    * like this cover control thing, sort of based on what would have been the "XML Engine" (TM) with no clear requirements.
    * Then, let's not do anything about it for a year, and when another customer wants something similar, let's make
    * someone else program something from scratch, and hey, could we also make sure not to have this programmer coordinate
    * with the other programmer? Just to make sure that we don't do anything right? And, when the time comes that a third
    * client wants something in-between what these two programmers were forced to crap out, could we ask them to hack
    * something different together real quick to make absolutely sure that we're living on a pile of code shit, and also
    * top it off by "agreeing" to do that on a meeting that's supposedly "Scrum" planning, except we skip each and every
    * bit that would actually make it scrum and instead have the überboss jot in "agreements" and "deadlines" in an Excel
    * sheet?
    *
    * Sure thing, that's how we roll, baby! Let's do the third thing, unless custId is 1521. DB is in another script
    * altogether, so we don't need to worry about that.
    */

    * See, this is why I hate this site. People write bullshit in the comments.
  • Simon 2010-12-20 15:36
    frits:
    Really? Replace them when you see them? You would think there would be an automated way to "find and replace" such "atrocities" with such a useful "fix". Nevermind the fact that this fix is as least as dumb as the original. At least.


    More so. The function is poorly named, certainly, but the code in my workplace is riddled with similar calls. And for good reason - it's amazing how many developers can stuff up something as straightforward as:

      string != null && !"".equals(string)


    In contrast, a call to isNotEmpty(string) is almost impossible to get wrong, and is actually somewhat easier to read at a glance. A fix for the deficiencies of the language, granted, but still useful.
  • ÃÆâ€â„ 2010-12-20 15:41
    bluesman:
    I've touched your colon. Pray I don't...

    Wait... Blech... Never mind.


    Don't stop, Darth bluesman.

    Captcha: transverbero - when you put a colon in front of a verb
  • Jallopy 2010-12-20 15:59
    forgottenlord:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    Ok, I've never seen this operator before. Yes, it is a flash of ignorance on my part, though a quick check through the code base of my company's code (and there have been a fair number of C# developers here) I can't find a single instance of it being used. Why, we just didn't, collectively, know it. Mind you, most of us got our degrees while programming in Java or C/C++ so maybe it is just that it wasn't part of those languages. Either way, it's not really a WTF. It's a failure of knowledge rather than technique.


    Which Operator? ?? ?
  • JamesCurran 2010-12-20 16:04
    Hmmm... It seems that folks are missing the WTFs here.

    for (var i:int = 0; i < 100; i++){
    var rand:int = Math.random() * 6;
    }
    SoundHandler.playExternalSounds(["positive_override" + rand]);


    I don't recognize that specific language, so I can't say for sure, but in C/C++/C#/Java, the variable rand set inside the loop is out of scope when used in playExternalSounds(). Some other "rand" defined elsewhere is being used. So, not only are they trying to make it pointlessly "very random", a flaw is preventing it from doing anything at all.


    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    Here, the code is actually not that bad, and the real WTF is that apparently no one on this forum can look at a fragment of code and figure out it's purpose.

    Clearly, at some point they have an object, which may or may not be a string, and they have to determine if it is.
    String.IsNullOrEmpty() can't do that by itself, as it takes string, not objects. So, he calls ToString() to convert the object into string (if it's already a string, ToString is a NOP). But, if the object is null, ToString() will throw a NullReferenceException, so it added a separate null check at the start.

    So, the only real problem is that ToString will always return a valid string, so this will only return false if the object is null.

    So, the real correct version:

    public static bool IsRealString(object s)
    
    {
    return !String.IsNullOrEmpty(s as string);
    }


    (for those tht don't know C#, "(s as string)" is an expression of type string, if s is a string; or null, if s is any other type.)
  • Jallopy 2010-12-20 16:05
    Coyne:
    Actually, it turns out that the longer version of the IsNullOrEmpty() test that Anthony Arnold reported was needed in earlier versions of .NET. See:

    DANGER ! String.IsNullOrEmpty can lead to runtime Null exceptions !!

    So which is the bigger WTF here: Writing it this way? Or having to write it this way because your compiler doesn't optimize right?

    P.S. ...and, to top it all off, Anthony might be doing the wrong thing. Let's hope his compiler works right.


    We should also point out that he is passing an Object not a String.

    What is the result of passing 's' (without ToString()) to IsNullOrEmpty ?

    What is the result of passing s.ToString() in the case where s is null?

    I think what he was doing here is not quite as stupid as some people seem to think.....

    <disclaimer> I am fairly new to c#, but I assume that passing a non-String object to a method that expects a String (IsNullOrEmpty) is a no-no, and that we can't do NULL.ToString();
  • Bligglydosh 2010-12-20 16:07
    boog:
    frits:
    Yeah I don't think so. Sarcasm involves intentional irony and humor. Show me those two elements.

    Not an easy task. Sure, one can show humor simply by laughing (ha), and it's clear that the "fix" was ironically as bad or worse than the original (you've admitted that yourself). However, the challenge lies in proving that these traits were intentional. Certainly the reader inferring the submitter's intentions would be subjective, and therefore worthless. What we need is some form of empirical evidence proving that the submitter intended to be ironic and humorous, or that said irony/humor was purely accidental. This may take a while.

    Oh, wait. This is a forum on the internet, so no one cares.

    My mistake.


    I wonder how many times the humour/irony/sarcasm debate will return...

    (I wouldn't have thouoght sarcasm needs necessarily to involve humour...)
  • JJ 2010-12-20 16:25
    For those who are interested, the VB function that does nothing (and is incorrectly declared to take and return Integer when it should take and return Long) is a (moderately) well-known workaround. If you ever need to get the address of a procedure, for example, to pass to a Windows API function, you can't do it directly. VB has an AddressOf operator, but it's only usable as a parameter to a procedure.

    In other words, you can't do

    myProcAddress = AddressOf SomeProcedureName

    but you CAN do this

    myProcAddress = FnPtrToLong(AddressOf SomeProcedureName)

    assuming it were declared correctly.

    So now you can make the tired "TRWTF is VB" comment and, in this case, be right.
  • Trerro 2010-12-20 16:26
    I can actually understand the logic on the PHP one at the end. It's still very much a WTF, but here's my take on it:

    Apparently he used the same script on 2 completely different websites, with different domains, but hosted on the same machine. It's not at all uncommon for a bunch of small sites to be on the same machine, using a fairly standard directory structure of something like /home/username/public_html/domain/subdirectory/scriptname.php.

    In an effort to ensure updating the script on either would update both, he used some Directory Fu to go so far up on the directory tree that he left the site he's doing the include from entirely, and then down into the other domain to include the script from there. PHP won't reject this, because you haven't left the machine, and of course, it has no way of knowing that you're pointing it at a completely different site - there's no formal standard for how to structure a directory tree for websites, just some common sense in organizing it logically and intelligently.

    So it'll work... and it'll do what the guy intended... but this is still colossally stupid, and for far more reasons than the clusterfuck of an include statement he ended up with. There's a good chance that other site will grow large enough to need its own machine, or that the sites will later change enough that the exact same script can no longer be used. When this happens years from now, with a completely different coder involved, the new guy is going to wonder why the site is suddenly throwing all kinds of errors, get stuck digging through the code, and then realize that not only is it trying to include a file that's no longer on that machine, but he doesn't have access to wherever that other site went, leaving a gaping hole in the site, and likely days of downtime as they explain why they need code from a completely unrelated site. Even worse, if they SOLD that other site, they're just plain shit out of luck, and are going to have to play the "guess everything that script did, and rebuild it" game.

    So yeah, MAJOR WTF, but unlike the weird bool stuff, there was at least some semblance of logic involved.

  • jpaull 2010-12-20 16:29
    Did anyone else notice the "(TM)" in the rant comment?

    At least he is respectful of the copyright laws...
  • frits 2010-12-20 16:35
    Jallopy:
    forgottenlord:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    Ok, I've never seen this operator before. Yes, it is a flash of ignorance on my part, though a quick check through the code base of my company's code (and there have been a fair number of C# developers here) I can't find a single instance of it being used. Why, we just didn't, collectively, know it. Mind you, most of us got our degrees while programming in Java or C/C++ so maybe it is just that it wasn't part of those languages. Either way, it's not really a WTF. It's a failure of knowledge rather than technique.


    Which Operator? ?? ?


    Awesome comment! +1 for you.
  • da Doctah 2010-12-20 16:42

    /*
    * See, this is why I hate my job. We start out doing some magical end-all solution for a may be customer, the
    * "XML Engine" hazily devised by IT iliterate decision makers without a clue what it's should do or who wants it. Ignore
    * that the codebase as is needs refactoring and fixing, let's ignore that we have a todo list a mile long, let's make
    * up requirements on top of that! Then, when reality kicks in and the may be customer isn't, we have semi-finished
    * shit clogging up all code arteries with poison. But noooo, don't clean it up, let's hack something else together
    * like this cover control thing, sort of based on what would have been the "XML Engine" (TM) with no clear requirements.
    * Then, let's not do anything about it for a year, and when another customer wants something similar, let's make
    * someone else program something from scratch, and hey, could we also make sure not to have this programmer coordinate
    * with the other programmer? Just to make sure that we don't do anything right? And, when the time comes that a third
    * client wants something in-between what these two programmers were forced to crap out, could we ask them to hack
    * something different together real quick to make absolutely sure that we're living on a pile of code shit, and also
    * top it off by "agreeing" to do that on a meeting that's supposedly "Scrum" planning, except we skip each and every
    * bit that would actually make it scrum and instead have the überboss jot in "agreements" and "deadlines" in an Excel
    * sheet?
    *
    * Sure thing, that's how we roll, baby! Let's do the third thing, unless custId is 1521. DB is in another script
    * altogether, so we don't need to worry about that.
    */


    I love it. Reads a little like the obligatory bit in a 19th-century adventure novel where the hero's in some remote jungle and doesn't know if he'll ever make it out alive, but he leaves this elaborate letter explaining his predicament for whomever, if anyone, happens to find it.
  • Pedro 2010-12-20 16:43

    for (var i:int = 0; i < 100; i++){
    var rand:int = Math.random() * 6;
    }
    SoundHandler.playExternalSounds(["positive_override" + rand]);



    Does this even compile? Variable scope?
    Unless "rand" already exists outside... and then the loop is really useless.
  • Gunslinger 2010-12-20 16:48
    Two:
    ShatteredArm:
    if (oneHundred == 100) {
    
    oneHundred /= 2;
    }


    Looks like oneHundred can be anything except 100.


    Unless it starts out at 200 ...


    In that case, it would remain at 200.
  • Ryan 2010-12-20 17:27
    JamesCurran:

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    So, the real correct version:

    public static bool IsRealString(object s)
    
    {
    return !String.IsNullOrEmpty(s as string);
    }



    Yes, this is most likely the intended purpose of IsRealString(), but you have changed the behavior slightly. If s is a non-string object that implements ToString(), the original IsRealString() may return true, whereas yours will always return false. Again, this is probably a bug in the original, but who can tell for sure?
  • pbean 2010-12-20 17:48
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }



    I really feel that Alex, or perhaps Anthony, is trolling us. Becuase the suggested "fix" isn't better, and it doesn't even really do the same (it has the same end-result, but does it in a less efficient way). Also it's way less readable.

    Why doesn't Anthony give us hints as to why his solution is supposed to be better, and then we'll talk again?
  • CrushU 2010-12-20 18:10
    Could've sworn there was a way to tell if something was a String built into the language...

    Generally, though, if you're needing to specify whether something is or isn't a class, something's Bad-Wrong with your design.
  • Luiz Felipe 2010-12-20 19:19
    this shit
    Private Function FnPtrToLong.....

    was from vb6, and converted do vbnet.

    Private Function FnPtrToLong(lngFnPtr As Integer) As Long
    ' Given a function pointer as a Long, return a Long.
    ' Sure looks like this function isn't doing anything,
    ' and in reality, it's not.
    FnPtrToLong = lngFnPtr
    End Function

    it is used to call a C Dll function, passing a pointer to vb function. it isnot useless, i has a purpose

    public sub Main()
    Dim P as Long
    P = FnPtrToLong( AddressOf callback )
    CallCFunctionPassFunctionPointer(P)
    end sub
    public sub callback(byref p as long) as long
    'pointer to function, dah
    end sub
  • K 2010-12-20 19:37
    Rand Dumm:
    trwtf:

    for (var i:int = 0; i < 100; i++){
    var rand:int = Math.random() * 6;
    }
    SoundHandler.playExternalSounds(["positive_override" + rand]);

    The loop makes it more random, you see...
    Shouldn't you loop a random number of times, so you don't get the same result every time you run it?
    Looping a random number of times actually makes it less random. There is a finite number of possible internal states of the random number generator. You will eventually end up in a loop through some subset of the possible states (some generators are guaranteed to loop through all states, so the subset could be the whole thing). Choosing the number of itterations based on which state you are in when this function is called means that you are causing at least some input states to collide and produce the same output states. So, you have just reduced the number of possible states your random number generator can be in at the end of the function.

    If the designer of the random number function was really bright, you may not have broken it totally, but surely it doesn't improve randomness.

    This may be obvious to some people in here, but I guess not everybody in here realizes, that using a random number of itterations like that can actually reduce randomness.
  • Simon 2010-12-20 19:54
    <?php include dirname(__FILE__).'/../../../otherdomain.com/public_html/file.php'; ?>


    This isn't that much of a WTF. It's a bit dangerous is all. Assuming that include is a common config file with e.g. database credentials which are shared between several sites, it would be better to put the file higher up in the directory structure, at or above the otherdomain.dom level, assuming they're actually separate domains. If this file exists in e.g. a subdomain (many hosts set up subdomains as if they were separate domains, so sub.otherdomain.com would be a directory at the same level as otherdomain.com) then pulling in a config file from the main directory is quite possibly the correct thing to do, so it can be changed once in the main domain and any subdomains will also pick up the change. Ideally he should also be using require or ideally require_once, because require will terminate the script if it couldn't pull in the file, where include will only throw a warning (which in a production environment could be suppressed).
  • da Doctah 2010-12-20 19:58
    K:
    This may be obvious to some people in here, but I guess not everybody in here realizes, that using a random number of itterations like that can actually reduce randomness.


    Maybe a scaled-down illustration is in order. Pick a number. Any number. It can be a positive integer or something like "the fifth root of 1,627,803.4".

    Spell that number out using the normal rules of spelling out numbers. Count the number of letters in the spelling, and use that number in the next step.

    Spell that number normally. (By normally, I mean if you get sixteen letters, don't get cute and spell it as "the age I was when I lost my virginity"; just spell out the number like a civilized human being.) Count the number of letters in that spelling, and repeat until you get tired.

    Your final answer is "four".
  • djhayman 2010-12-20 21:04
    The Article:
    !String.IsNullOrEmpty((s ?? "").ToString())


    Seeing as you're already checking for a null object with "??" (and changing it to an empty string), why bother with string.IsNullOrEmpty?

    public static bool IsRealString(object s)
    
    {
    return (s ?? "").ToString() != "";
    }
  • lomendil 2010-12-20 21:24
    da Doctah:


    ..snip..

    Your final answer is "four".


    Is this because "four" is the only fixed point (and number n tends to have < n letters), or is there a deeper thing at work?
  • da Doctah 2010-12-20 22:33
    lomendil:
    da Doctah:


    ..snip..

    Your final answer is "four".


    Is this because "four" is the only fixed point (and number n tends to have < n letters), or is there a deeper thing at work?


    It's because "four" is an attractor, but I'll only certify that in English. In some other languages you end up with things like endless cycles between the equivalents of "three" and "five".

    A more complex sequence of numbers involves two operations. Beginning with any number n:

    o If n is even, divide by two.
    o If n is odd, multiply by three and add one.

    then repeat.

    At present, every case that anyone has tried has eventually converged to n=1 (followed by n=4, n=2, and then repeat the cycle).

    They've been trying to prove this since 1937, and so far all they've managed to do is establish that if there is a starting number that doesn't converge to this cycle, it's larger than 20×2^58. But it works for every number they've tried so far.
  • ContraCorners 2010-12-20 23:33
    boog:
    Two:
    ShatteredArm:
    if (oneHundred == 100) {
    
    oneHundred /= 2;
    }


    Looks like oneHundred can be anything except 100.


    Unless it starts out at 200 ...

    So you believe that 200 == 100 then, do you?

    Interesting...
    Puhleeze. Everyone knows 200 equals twice 100.
  • Ben 2010-12-21 00:40
    Jallopy:

    return s != null && !String.IsNullOrEmpty(s.ToString());


    We should also point out that he is passing an Object not a String.

    What is the result of passing 's' (without ToString()) to IsNullOrEmpty ?

    What is the result of passing s.ToString() in the case where s is null?

    I think what he was doing here is not quite as stupid as some people seem to think.....

    <disclaimer> I am fairly new to c#, but I assume that passing a non-String object to a method that expects a String (IsNullOrEmpty) is a no-no, and that we can't do NULL.ToString();


    Agreed:

    If s is null, execution will do the s != null bit, see the && symbol, and not even test the rest of the code, because the condition (s != null) is false. Why should you test something after an && operator when the first bit is false? You don't need to, and neither does the compiler/justintimeexecutor.

    So this function:
    a) Won't throw an error.
    b) Is more readable.

    TRWTF is the person who didn't understand why the function was there in the first place...
  • oheso 2010-12-21 01:32
    Ben:
    If s is null, execution will do the s != null bit, see the && symbol, and not even test the rest of the code, because the condition (s != null) is false.


    You'd think, huh? Either VB (.asp) or VB.NET (.aspx) will test the rest. (Not sure at the moment, but I know I've encountered that in one of those two situations.)
  • Jan 2010-12-21 02:40
    Not really, your way tries to execute the output of the php script, most of the time, HTML, that wouldn't work.
  • Matt Westwood 2010-12-21 03:01
    DOA:
    unless custId is 1521.
    The one constant in every software development department.


    SOP in most companies, I thik you'll find.

    "Aaargh! Customer 1521 won't eat his rice pudding!"

    "So fix it so he doesn't *get* rice pudding."

    "But - but - but we have no *concept* of not giving rice pudding! *Everybody* loves rice pudding! It'll take *months* to program an option in: "Do you want rice pudding?" and think of the DBA work needed ..."

    "Bah. Put in a bodge for now. We'll address the Generalized Rice Pudding Option later. Oh by the way, when did you say your last day was?"
  • Matt Westwood 2010-12-21 03:03
    frits:
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    .

    Really? Replace them when you see them? You would think there would be an automated way to "find and replace" such "atrocities" with such a useful "fix". Nevermind the fact that this fix is as least as dumb as the original. At least.

    Yes, he's forgotten to put in a try/catch for a class cast exception to counter the possibility that s isn't actually a string.
  • Matt Westwood 2010-12-21 03:49
    K:
    Rand Dumm:
    trwtf:

    for (var i:int = 0; i < 100; i++){
    var rand:int = Math.random() * 6;
    }
    SoundHandler.playExternalSounds(["positive_override" + rand]);

    The loop makes it more random, you see...
    Shouldn't you loop a random number of times, so you don't get the same result every time you run it?
    Looping a random number of times actually makes it less random. There is a finite number of possible internal states of the random number generator. You will eventually end up in a loop through some subset of the possible states (some generators are guaranteed to loop through all states, so the subset could be the whole thing). Choosing the number of itterations based on which state you are in when this function is called means that you are causing at least some input states to collide and produce the same output states. So, you have just reduced the number of possible states your random number generator can be in at the end of the function.

    If the designer of the random number function was really bright, you may not have broken it totally, but surely it doesn't improve randomness.

    This may be obvious to some people in here, but I guess not everybody in here realizes, that using a random number of itterations like that can actually reduce randomness.


    +1. Read the first chapter of Knuth's TAOCP Volume II for a truly awe-inspiring foul-up of a random number generator which by a bizarre series of coincidences *isn't*. Essential reading for anyone who wants to use random numbers in anger.
  • Matt Westwood 2010-12-21 03:54
    lomendil:
    da Doctah:


    ..snip..

    Your final answer is "four".


    Is this because "four" is the only fixed point (and number n tends to have < n letters), or is there a deeper thing at work?


    Try it in different languages. The same principle applies, except you'll probably end up on a different number (e.g. Russian: 3) may get into a loop (e.g. French: 5-4-6-3-5-4-6-3 ...) and it is possible you will end up with more than one attractor (e.g. if there were a language that had 4 = "fawr" and 5 = "fiyev" and 6 = "sickss" or whatever - there may a language with such a property but without investigating in detail I don't know).
  • IMil 2010-12-21 03:58
    JamesCurran:

    So, the only real problem is that ToString will always return a valid string, so this will only return false if the object is null.

    So, the real correct version:

    public static bool IsRealString(object s)
    
    {
    return !String.IsNullOrEmpty(s as string);
    }


    Actually, the original code will return false for any object x where x.ToString() returns "". The common case is DBNull.Value.

    I believe this method in its original form may be useful when working with untyped DataTables, while your "correct" version will break behaviour.
  • Matt Westwood 2010-12-21 03:58
    Matt Westwood:
    lomendil:
    da Doctah:


    ..snip..

    Your final answer is "four".


    Is this because "four" is the only fixed point (and number n tends to have < n letters), or is there a deeper thing at work?


    Try it in different languages. The same principle applies, except you'll probably end up on a different number (e.g. Russian: 3) may get into a loop (e.g. French: 5-4-6-3-5-4-6-3 ...) and it is possible you will end up with more than one attractor (e.g. if there were a language that had 4 = "fawr" and 5 = "fiyev" and 6 = "sickss" or whatever - there may a language with such a property but without investigating in detail I don't know).


    Sorry, Russian ends up in a loop that goes 4-6-5-4-6-5 except for 2 and 3 which end up as 3. Sorry, forgot that 7 has an extra silent letter at the end.
  • experimental 2010-12-21 04:21
    da Doctah:
    K:
    This may be obvious to some people in here, but I guess not everybody in here realizes, that using a random number of itterations like that can actually reduce randomness.


    Maybe a scaled-down illustration is in order. Pick a number. Any number. It can be a positive integer or something like "the fifth root of 1,627,803.4".

    Spell that number out using the normal rules of spelling out numbers. Count the number of letters in the spelling, and use that number in the next step.

    Spell that number normally. (By normally, I mean if you get sixteen letters, don't get cute and spell it as "the age I was when I lost my virginity"; just spell out the number like a civilized human being.) Count the number of letters in that spelling, and repeat until you get tired.

    Your final answer is "four".


    Why did you lose your virginity at the age of 16? Are you a 50 year old or something?
  • zirias 2010-12-21 04:58
    djhayman:
    Seeing as you're already checking for a null object with "??" (and changing it to an empty string), why bother with string.IsNullOrEmpty?

    public static bool IsRealString(object s)
    
    {
    return (s ?? "").ToString() != "";
    }


    Bad idea to create a new string object, just for detecting an empty string -- better check the length of the original string:

    (s ?? "").ToString().Length > 0
  • F 2010-12-21 05:29
    da Doctah:
    K:
    This may be obvious to some people in here, but I guess not everybody in here realizes, that using a random number of itterations like that can actually reduce randomness.


    Maybe a scaled-down illustration is in order. Pick a number. Any number. It can be a positive integer or something like "the fifth root of 1,627,803.4".

    Spell that number out using the normal rules of spelling out numbers. Count the number of letters in the spelling, and use that number in the next step.

    Spell that number normally. (By normally, I mean if you get sixteen letters, don't get cute and spell it as "the age I was when I lost my virginity"; just spell out the number like a civilized human being.) Count the number of letters in that spelling, and repeat until you get tired.

    Your final answer is "four".


    No. My final answer is "five". Now if you'd said "...until you get a repeated number" you'd be right, but I get tired easily.
  • My Name 2010-12-21 06:05
    da Doctah:
    K:
    This may be obvious to some people in here, but I guess not everybody in here realizes, that using a random number of itterations like that can actually reduce randomness.


    Maybe a scaled-down illustration is in order. Pick a number. Any number. It can be a positive integer or something like "the fifth root of 1,627,803.4".

    Spell that number out using the normal rules of spelling out numbers. Count the number of letters in the spelling, and use that number in the next step.

    Spell that number normally. (By normally, I mean if you get sixteen letters, don't get cute and spell it as "the age I was when I lost my virginity"; just spell out the number like a civilized human being.) Count the number of letters in that spelling, and repeat until you get tired.

    Your final answer is "four".


    I'd like to use the square root of 2. How do I get to the point where I start counting letters?
  • Jeremy 2010-12-21 06:56
    da Doctah:
    Your final answer is "four".


    Yo conseguí "cinco".
    それから私は"一"を得た。
    κατόπιν πήρα πέντε πάλι.
    Et finalement je me suis coincé dans une boucle entre trois, cinq, quatre, et six…
  • the beholder 2010-12-21 07:02
    daily:

    /*
    * See, this is why I hate my job. We start out doing some magical end-all solution for a may be customer, the
    * "XML Engine" hazily devised by IT iliterate decision makers without a clue what it's should do or who wants it. Ignore
    * that the codebase as is needs refactoring and fixing, let's ignore that we have a todo list a mile long, let's make
    * up requirements on top of that! Then, when reality kicks in and the may be customer isn't, we have semi-finished
    * shit clogging up all code arteries with poison. But noooo, don't clean it up, let's hack something else together
    * like this cover control thing, sort of based on what would have been the "XML Engine" (TM) with no clear requirements.
    * Then, let's not do anything about it for a year, and when another customer wants something similar, let's make
    * someone else program something from scratch, and hey, could we also make sure not to have this programmer coordinate
    * with the other programmer? Just to make sure that we don't do anything right? And, when the time comes that a third
    * client wants something in-between what these two programmers were forced to crap out, could we ask them to hack
    * something different together real quick to make absolutely sure that we're living on a pile of code shit, and also
    * top it off by "agreeing" to do that on a meeting that's supposedly "Scrum" planning, except we skip each and every
    * bit that would actually make it scrum and instead have the überboss jot in "agreements" and "deadlines" in an Excel
    * sheet?
    *
    * Sure thing, that's how we roll, baby! Let's do the third thing, unless custId is 1521. DB is in another script
    * altogether, so we don't need to worry about that.
    */

    * See, this is why I hate this site. People write bullshit in the comments.
    - Only one way to solve it then. Quick, enter youtube right away.

    - Wait, what? If I do it I'll see smart comments? Are you insane?

    - Of course not. If you do it TDWTF's commenters will start to look bright by comparison.
  • experimental 2010-12-21 07:08
    the beholder:
    daily:
    * See, this is why I hate this site. People write bullshit in the comments.
    - Only one way to solve it then. Quick, enter youtube right away.

    - Wait, what? If I do it I'll see smart comments? Are you insane?

    - Of course not. If you do it TDWTF's commenters will start to look bright by comparison.


    You so totally didn't get what he was saying! He was talking about comments in source code, and not about TDWTF comments! Learn to read!
  • Matt Westwood 2010-12-21 07:24
    My Name:
    da Doctah:
    K:
    This may be obvious to some people in here, but I guess not everybody in here realizes, that using a random number of itterations like that can actually reduce randomness.


    Maybe a scaled-down illustration is in order. Pick a number. Any number. It can be a positive integer or something like "the fifth root of 1,627,803.4".

    Spell that number out using the normal rules of spelling out numbers. Count the number of letters in the spelling, and use that number in the next step.

    Spell that number normally. (By normally, I mean if you get sixteen letters, don't get cute and spell it as "the age I was when I lost my virginity"; just spell out the number like a civilized human being.) Count the number of letters in that spelling, and repeat until you get tired.

    Your final answer is "four".


    I'd like to use the square root of 2. How do I get to the point where I start counting letters?


    Du-uh. "The square root of two" -> "eighteen" -> "eight" -> "five" -> "four", you dummy.
  • Anon Too 2010-12-21 08:15
    "for (var i:int = 0; i < 100; i++){
    var rand:int = Math.random() * 6;
    }
    SoundHandler.playExternalSounds(["positive_override" + rand]);
    "

    I found the addition of the loop in this the be extremely exquisite. And by exquisite I mean painful...
  • My Name 2010-12-21 08:23
    Matt Westwood:
    My Name:
    da Doctah:
    K:
    This may be obvious to some people in here, but I guess not everybody in here realizes, that using a random number of itterations like that can actually reduce randomness.


    Maybe a scaled-down illustration is in order. Pick a number. Any number. It can be a positive integer or something like "the fifth root of 1,627,803.4".

    Spell that number out using the normal rules of spelling out numbers. Count the number of letters in the spelling, and use that number in the next step.

    Spell that number normally. (By normally, I mean if you get sixteen letters, don't get cute and spell it as "the age I was when I lost my virginity"; just spell out the number like a civilized human being.) Count the number of letters in that spelling, and repeat until you get tired.

    Your final answer is "four".


    I'd like to use the square root of 2. How do I get to the point where I start counting letters?


    Du-uh. "The square root of two" -> "eighteen" -> "eight" -> "five" -> "four", you dummy.


    And just like that, you destroyed another mysterious wonder of this world.
  • Ge 2010-12-21 08:33
    Here's one from my previous gig

    boolean[] booleans = new boolean[] { Boolean.valueOf(Boolean.TRUE, Boolean.valueOf(Boolean.FALSE) };

    I'm not making it up
  • Ge 2010-12-21 08:37
    Anon:
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }



    Why test if an empty string is empty (if s is null)? Seem like inlining the code from the original functions would be better. Which is probably what the compiler does anyway. And it's more readable. Once again the suggested fix is TRWTF.


    Who cares what the compiler does? This source code is here for US to read. If you want to follow that to its logical conclusion, throw the programming language away, and write opcodes directly to disc. That's what the compiler does.....
  • Ge 2010-12-21 08:41
    Ge:
    Here's one from my previous gig

    boolean[] booleans = new boolean[] { Boolean.valueOf(Boolean.TRUE, Boolean.valueOf(Boolean.FALSE) };

    I'm not making it up


    Apart from the missed closing bracket, of course
  • weazel 2010-12-21 09:05
    The string check should be: !string.IsNullOrEmpty(s as string)
    Period.
    Anthony's version is TRWTF and I would probably replace it if I found something like that in our code.

    I've seen few other developers use the ??-operator and you can certainly live a happy and fulfilled life without it (and especially if you don't use Linq). I mainly use it for instantiating backing fields that require parameters, like:

    DelegateCommand _cmd;

    public ICommand BlahCommand {
    get { return _cmd ?? (_cmd = new DelegateCommand(this.DoStuff)); }
    }

    void DoStuff() { }

  • Andy Holyer 2010-12-21 09:09
    ShatteredArm:
    if (oneHundred == 100) {
    
    oneHundred /= 2;
    }


    Looks like oneHundred can be anything except 100.


    Way, way back some early fortran compilers had the common integers predefined as variables whose values were themselves

    (that is, '5' was a variable whose value was 0x05 binary).

    Once, I sabotaged a "friend"s coding coursework by slipping in a header file which contained:

    LET 1 = 3

    The compile swallowed it without a complaint. However it does make debugging almost impossible until you track it down...
  • Matt Westwood 2010-12-21 09:23
    Andy Holyer:
    ShatteredArm:
    if (oneHundred == 100) {
    
    oneHundred /= 2;
    }


    Looks like oneHundred can be anything except 100.


    Way, way back some early fortran compilers had the common integers predefined as variables whose values were themselves

    (that is, '5' was a variable whose value was 0x05 binary).

    Once, I sabotaged a "friend"s coding coursework by slipping in a header file which contained:

    LET 1 = 3

    The compile swallowed it without a complaint. However it does make debugging almost impossible until you track it down...


    Argh - you sadist! Happy birthday.
  • undefined 2010-12-21 09:24
    In Russian "not" is "не", it can be transliterated as "ne".
  • Anon 2010-12-21 09:39
    Ge:
    Anon:
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }



    Why test if an empty string is empty (if s is null)? Seem like inlining the code from the original functions would be better. Which is probably what the compiler does anyway. And it's more readable. Once again the suggested fix is TRWTF.


    Who cares what the compiler does? This source code is here for US to read. If you want to follow that to its logical conclusion, throw the programming language away, and write opcodes directly to disc. That's what the compiler does.....


    I think you completely missed my point. The point is that since the compiler will inline the function, there is NO POINT in doing it yourself. I was proposing that you leave it as it was (using the original function call - perhaps fixing the parameter type) instead of replacing it with some unreadable monstrosity.
  • Medinoc 2010-12-21 09:40
    weazel:
    The string check should be: !string.IsNullOrEmpty(s as string)
    Period.

    Only if that's really what someone wants to test.

    If we actually want to test that any random object's ToString() override returns neither null nor an empty string, the original code is correct.
  • Jake 2010-12-21 09:44
    Wormlore:
    That is not the worst way to set a boolean to False.
    Something like this would have been "less good"

    bool memberHasFingerprint = !bool.Parse(bool.TrueString);

    And I'm sure someone creative enough could come up with something worst yet.



    bool memberHasFingerprint = !bool.Parse(!((bool.TrueString == "True") || (bool.TrueString == "true") || (bool.TrueString == "TRUE") || (bool.TrueString == "T")) == true);

    Like this?

    captcha: persto - a quick pesto sauce
  • dgvid 2010-12-21 09:47
    The name CompareObjectAsIAlertDocumentOrNullIfNotCastable was probably written by a frustrated, sarcastic programmer whose co-workers don't, and apparently cannot be made to, understand that the as operator yields null on conversion failure.

    I'm not saying I would do this myself, but I sympathize. Our code has as-abuse scattered throughout.

    The RTWF is C#'s as operator.
  • Anon 2010-12-21 09:47
    Ryan:
    JamesCurran:

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    So, the real correct version:

    public static bool IsRealString(object s)
    
    {
    return !String.IsNullOrEmpty(s as string);
    }



    Yes, this is most likely the intended purpose of IsRealString(), but you have changed the behavior slightly. If s is a non-string object that implements ToString(), the original IsRealString() may return true, whereas yours will always return false. Again, this is probably a bug in the original, but who can tell for sure?


    All objects implement ToString() because object (the base class of all objects in .NET) implements ToString() (the base implementation just returns the type name). The only exception would be if you deliberately overrode ToString() to throw a NotImplementedException or similar (which would be a little perverse).
    It's not clear if the original author really intended to use object as the parameter type. It's a little messy, but if your objects override ToString() to return something meaningful (for example, a Person object might return the Name member from ToString()), then checking if that string is empty might be a valid (but awkward) way to check if the object has a particular state (maybe ToString will return an empty string until the object is initialized). It would, of course, be better just to check the object directly with either an IsInitialized property of a member function.
  • weazel 2010-12-21 09:51
    Medinoc:
    weazel:
    The string check should be: !string.IsNullOrEmpty(s as string)
    Period.

    Only if that's really what someone wants to test.

    If we actually want to test that any random object's ToString() override returns neither null nor an empty string, the original code is correct.


    You're absolutely right, I didn't think of the case where using ToString() is actually a requirement...
  • golddog 2010-12-21 10:29
    oheso:
    Ben:
    If s is null, execution will do the s != null bit, see the && symbol, and not even test the rest of the code, because the condition (s != null) is false.


    You'd think, huh? Either VB (.asp) or VB.NET (.aspx) will test the rest. (Not sure at the moment, but I know I've encountered that in one of those two situations.)


    .NET (at least) allows to code the condition as "AndAlso" (Or "OrElse", for or) which tells the compiler to use boolean shortcuts.

    That's right, you have to manually instruct the language to use the more efficient mechanism which is the default in every other language.

    Man, I hope that position in C# comes through... ;-)
  • boog 2010-12-21 10:56
    pbean:
    I really feel that Alex, or perhaps Anthony, is trolling us. Becuase the suggested "fix" isn't better, and it doesn't even really do the same (it has the same end-result, but does it in a less efficient way). Also it's way less readable.

    It seems to me that you are the one trolling.

    I could be mistaken though. Did you really not get that he was joking about the "fix" (to be fair though, neither Alex nor Anthony ever called it a "fix")?
  • gilhad 2010-12-21 11:21
    Matt Westwood:
    My Name:


    I'd like to use the square root of 2. How do I get to the point where I start counting letters?


    Du-uh. "The square root of two" -> "eighteen" -> "eight" -> "five" -> "four", you dummy.


    For trolls: "The square root of two" -> "lot" -> "lot" ...

    For more matematically endowed: "lot" -> "few" -> "few" ...
  • Arvind 2010-12-21 11:37
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"


    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }



    Consider this:

    if(IsRealString(foo))
    [/cpde]
    against this:
    [code]
    if(!String.IsNullOrEmpty((foo ?? "").ToString()))

    Given that you did not care to specify the language in which this was written, I would not know what the latter does, whereas the former is at least understandable by someone with a little common sense.

    There are several cases when you do not really want to know how the code works, but just want to know what it does. That is precisely why your so-called better solution is wrong.

    TRWTF is that this submission was published.

    Remember this: Code is written once, but read multiple times. By majority rule, readability wins!
  • stefan 2010-12-21 12:29
    trwtf:

    for (var i:int = 0; i < 100; i++){
    var rand:int = Math.random() * 6;
    }
    SoundHandler.playExternalSounds(["positive_override" + rand]);



    The loop makes it more random, you see...


    Actually, a long time ago, I've been using a random number generator that always returned 0 in the first invocation after seeding it. For that one, calling random() and ignoring the result would indeed make the final result more random. However, ignoring one random value would be enough, not 99.
  • Loren Pechtel 2010-12-21 12:33
    digitalwitch:
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"


    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    There is something to be said for readability. Just because you can do something in one line doesn't mean you should.


    Yes. Just because you can pile 100 operations into a single statement doesn't mean you should.

    Not only that but the alternative approach creates a heap item if S is null. I think the original form is better.

    Matt Westwood:
    frits:
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    .

    Really? Replace them when you see them? You would think there would be an automated way to "find and replace" such "atrocities" with such a useful "fix". Nevermind the fact that this fix is as least as dumb as the original. At least.

    Yes, he's forgotten to put in a try/catch for a class cast exception to counter the possibility that s isn't actually a string.


    s doesn't have to be a string, you can ToString() anything. This is a legitimate function--it returns true if s.ToString() actually returns text.

    Anon:
    It's not clear if the original author really intended to use object as the parameter type. It's a little messy, but if your objects override ToString() to return something meaningful (for example, a Person object might return the Name member from ToString()), then checking if that string is empty might be a valid (but awkward) way to check if the object has a particular state (maybe ToString will return an empty string until the object is initialized). It would, of course, be better just to check the object directly with either an IsInitialized property of a member function.


    And one should override ToString for anything non-trivial. It's a godsend when debugging.
  • methinks 2010-12-21 12:41
    Arvind:
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"


    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }



    Consider this:

    if(IsRealString(foo))
    [/cpde]
    against this:
    [code]
    if(!String.IsNullOrEmpty((foo ?? "").ToString()))

    Given that you did not care to specify the language in which this was written, I would not know what the latter does, whereas the former is at least understandable by someone with a little common sense.

    There are several cases when you do not really want to know how the code works, but just want to know what it does. That is precisely why your so-called better solution is wrong.

    TRWTF is that this submission was published.

    Remember this: Code is written once, but read multiple times. By majority rule, readability wins!


    Moreover, this is "inlining by hand", which should really always be left to the compiler.

    DRY - Don't Repeat Yourself!

    What if the expression changes, i.e. you want to check for something a little bit different or add something to the check?

    In the original, there is exactly one place to change and test it.

    In Anthony's version, you have to do a global search and replace - and either be sure (or more likely hope), that all instances of this expression are written *exactly* in the same way, or use a regular expression for the search (of course provided that you IDE supports this and you know what a regular expression is AND get it right...)
  • Foo 2010-12-21 13:12
    frits:
    Jallopy:
    forgottenlord:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    Ok, I've never seen this operator before. Yes, it is a flash of ignorance on my part, though a quick check through the code base of my company's code (and there have been a fair number of C# developers here) I can't find a single instance of it being used. Why, we just didn't, collectively, know it. Mind you, most of us got our degrees while programming in Java or C/C++ so maybe it is just that it wasn't part of those languages. Either way, it's not really a WTF. It's a failure of knowledge rather than technique.


    Which Operator? ?? ?


    Awesome comment! +1 for you.

    What's so funny about it? ? ?? ? ?
  • Jay 2010-12-21 14:38
    Oh, I see the problem.


    if (oneHundred==100)
    {
    oneHundred=50;
    }


    There, that should be more efficient.
  • SQLDave 2010-12-21 17:45
    In Alabama they'd have written:

    if (aHunnert == 100) {
    aHunnert /= 2;
    }
  • Ben 2010-12-21 20:43
    frits:
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }


    .

    Really? Replace them when you see them? You would think there would be an automated way to "find and replace" such "atrocities" with such a useful "fix". Nevermind the fact that this fix is as least as dumb as the original. At least.


    TRWTF is that all references or pointers in C, C++, Java, .NET, etc. are potentially null.
  • led 2010-12-21 22:17
    That number of character thing will only feels "OMG-marvelous!" to a natively-few-alphabet-character-minded person.
    Because, say, in Chinese, the word for 0 1 2 3 4 5 6 7 8 9 10 are 1 characters. 11 - 19: 2 characters, 20 - 99: 3 characters.
    So it's like it just goes to one one one one one, and it feels more like "wtf of course that will happen because the word has the same meaning as the character count"
  • Rhialto 2010-12-22 04:46
    Wormlore:
    That is not the worst way to set a boolean to False.
    Something like this would have been "less good"

    bool memberHasFingerprint = !bool.Parse(bool.TrueString);

    And I'm sure someone creative enough could come up with something worst [sic] yet.


    Of course:

    bool memberHasFingerprint = true;

    is a very bad way of setting it to false.
  • Randy Snicker 2010-12-22 07:47
    "Even if you don't know PHP," writes Jacob Mather, "there's only one reaction this code leaves you with!"
    <?php include dirname(__FILE__).'/../../../otherdomain.com/public_html/file.php'; ?>


    Yes, there is:
    "Awesome!"
  • Jaydee 2010-12-22 08:07
    Yup, I think many of the WTF's we see here could have the whole comment appended somewhere in the code.
  • Random 2010-12-22 15:34
    That number of character thing will only feels "OMG-marvelous!" to a natively-few-alphabet-character-minded person.
    Because, say, in Chinese, the word for 0 1 2 3 4 5 6 7 8 9 10 are 1 characters. 11 - 19: 2 characters, 20 - 99: 3 characters.
    So it's like it just goes to one one one one one, and it feels more like "wtf of course that will happen because the word has the same meaning as the character count"


    All alphabets have relatively few characters and use them to represent phonemes. You're perhaps thinking of logographies, which aren't alphabets.
  • hoodaticus 2010-12-22 15:39
    Private Function FnPtrToLong(ByVal lngFnPtr As Integer) As Integer
    
    ' Given a function pointer as a Long, return a Long.
    ' Sure looks like this function isn't doing anything,
    ' and in reality, it's not.
    FnPtrToLong = lngFnPtr
    End Function
    This is what happens when you give pointers to veebeeweenees.
  • hoodaticus 2010-12-22 15:41
    Bobbo:
    The Article:
    # The colon is very important. DO NOT TOUCH.


    throw new AccessViolationException("Ouch, that's cold");
    So did Remy tell you how to get into that new homosexual website? Just go to the address bar and press the following keys:

    :(Enter)#######
  • hoodaticus 2010-12-22 15:51
    Rhialto:
    Wormlore:
    That is not the worst way to set a boolean to False.
    Something like this would have been "less good"

    bool memberHasFingerprint = !bool.Parse(bool.TrueString);

    And I'm sure someone creative enough could come up with something worst [sic] yet.


    Of course:

    bool memberHasFingerprint = true;

    is a very bad way of setting it to false.
    Nice!

    May way isn't as bad as that, but would be slightly more successful:
    void setBooleanTrue(bool value){
    
    value=(String)dblIrrationalNumber.Substring(90,1)=="5";
    }
    since the result could be hardware specific.
  • dgatwood 2010-12-22 22:07
    Anon:
    The Article:

    "This is used all over our app," writes Anthony Arnold, "I get rid of them when I see them. What's wrong with !String.IsNullOrEmpty((s ?? "").ToString())"

    public static bool IsRealString(object s)
    {
    return s != null && !String.IsNullOrEmpty(s.ToString());
    }



    Why test if an empty string is empty (if s is null)? Seem like inlining the code from the original functions would be better. Which is probably what the compiler does anyway. And it's more readable. Once again the suggested fix is TRWTF.


    Agreed about inlining it. Alternatively,

    s ? (!String.IsNullOrEmpty(s.ToString())) : false

    is equivalent without requiring any obscure C#-specific operators or calling a function unnecessarily to check the length of the empty string.
  • Berry 2010-12-23 06:11
    <?php include dirname(__FILE__).'/../../../otherdomain.com/public_html/file.php'; ?>

    Though obviously not a very good location to put a file that's used by multiple domains, I think the "WTF" in this is not in PHP, but with the server-admin. If the above is actually possible, the security issues are not caused by PHP itself.
  • Anonymously Yours 2010-12-23 15:13
    Matt Westwood:
    DOA:
    unless custId is 1521.
    The one constant in every software development department.


    SOP in most companies, I thik you'll find.

    "Aaargh! Customer 1521 won't eat his rice pudding!"

    "So fix it so he doesn't *get* rice pudding."

    "But - but - but we have no *concept* of not giving rice pudding! *Everybody* loves rice pudding! It'll take *months* to program an option in: "Do you want rice pudding?" and think of the DBA work needed ..."

    "Bah. Put in a bodge for now. We'll address the Generalized Rice Pudding Option later. Oh by the way, when did you say your last day was?"
    How can customer 1521 have any pudding if he won't eat his meat?

    Gah, this crap happens far too often. IT doesn't move at the speed of business unless your idea of quality is "the programmers told me it was done." People at the top who don't get that seem to excel at forcing their teams to produce crap and utterly fail at understanding why it keeps happening.

    The most disturbing two things about that comment rant, to me, are that at some point in the past I'm going to write an ill-conceived XML engine and, at some point in the future, I'm going to become a time traveler and not have the good sense to write down a winning lottery number to take with me.
  • Mr. Right 2010-12-23 19:29
    Ge:
    Ge:
    Here's one from my previous gig

    boolean[] booleans = new boolean[] { Boolean.valueOf(Boolean.TRUE, Boolean.valueOf(Boolean.FALSE) };

    I'm not making it up


    Apart from the missed closing bracket, of course

    I don't know what you're talking about but there's a closing parenthesis missing.
  • Mr. Right 2010-12-23 19:31
    Luiz Felipe:
    this shit
    Private Function FnPtrToLong.....

    was from vb6, and converted do vbnet.

    Private Function FnPtrToLong(lngFnPtr As Integer) As Long
    ' Given a function pointer as a Long, return a Long.
    ' Sure looks like this function isn't doing anything,
    ' and in reality, it's not.
    FnPtrToLong = lngFnPtr
    End Function

    it is used to call a C Dll function, passing a pointer to vb function. it isnot useless, i has a purpose

    public sub Main()
    Dim P as Long
    P = FnPtrToLong( AddressOf callback )
    CallCFunctionPassFunctionPointer(P)
    end sub
    public sub callback(byref p as long) as long
    'pointer to function, dah
    end sub


    public sub Main()
    CallCFunctionPassFunctionPointer(AddressOf callback)
    end sub
  • George 2010-12-23 21:40
    That should be

    #define TRUE 0;
    #define FALSE 1;

    bool memberHasFingerprint = TRUE; // set to false

  • muteKi 2010-12-23 22:19
    I can most certainly do worse -- though, admittedly, my example is based on Java.

    String falseString;
    ...
    falseString = "false";
    ...

    falseString = falseString.toUpperCase();

    boolean memberHasFingerprint;
    boolean tempBoolean = falseString.parseBoolean();

    if(falseString.getCharAt(0) != "A" && falseString.getCharAt(0) != "B" && falseString.getCharAt(0) != "C" && falseString.getCharAt(0) != "D" && falseString.getCharAt[0] != "E" && falseString.getCharAt(0) != "G" ...){ //make sure the first character isn't anything except F
    if(falseString.getCharAt[1] != "B" && falseString.getCharAt[1] != "C" && ...){ //make sure the second character isn't anything except A
    ...//do this sort of thing for L, S, and E -- getCharAt for 2-4 (edited here for readability)
    {
    memberHasFingerprint.parseBoolean(tempBoolean.toString());
    }}}}}//end if

    It can ALWAYS be worse!
  • muteKi 2010-12-23 22:24
    Oh, and of course this isn't actually based on any real code I've seen. It's just something I came up with to be an ass.

    I don't think anyone would be either so stupid or sadistic as to do something like that in production code.
  • DrJokepu 2010-12-23 23:40
    The null coalesce operator has been part of the C# language since its first version. It has nothing to do with nullable types, it returns the leftmost non-null value and it exists in many other programming languages.
  • Andy 2010-12-27 10:25
    tim:
    Actually I remember doing something like the 'pointer to long' in fortran on VMS once

    {snip}

    but of course if that example wasn't VMS fortran then it is a WTF ;-)

    But if it's VBA it's quite possible that this is a work around a strange behaviour in Word 11.0.4928.3000
  • idshiuhi 2010-12-28 01:40
    D-Bass melodious music to create an elegant and stylish space, seafood杭州广告伞|杭州伞厂 stalls, barbecue stalls, Cantonese-style roast meat lo, West 杭州装潢公司|杭州装潢Point files, dessert stalls, juice drinks are national hotel ... restaurant ... more than 100 dazzling array of sumptuous feast to It! Seafood杭州别墅装修|下沙装修公司 Festival Autumn crabs fresh curtain has been 杭州搬家|杭州下城区搬家公司disclosed, swimming crab, a variety of small Zhoushan seafood, oysters, salmon, prawns, scallops everything, so you enjoy 杭州江干区搬家公司|杭州江干区搬家smooth delicious seafood gluttony
  • jofdjoidf 2010-12-28 01:41
    In addition, the barbecue is delicious steak, lamb chops, pork, fresh squid interpretation. Tiramisu, 杭州管道疏通|杭州开荒 fruit, fishing, mango coolmore杭州地暖公司|杭州地暖|杭州中央空调销售公司 than 100 kinds of Chinese and Western杭州搬家公司 cuisine Enjoy unlimited,
  • Diego 2010-12-29 23:30
    You can do better:

    public static class ObjectExtensions
    {
    public static bool IsRealString(this object instance)
    {
    return !string.IsNullOrEmpty((instance ?? "").ToString());
    }
    }

    and use it like:

    if (obj.IsRealString())
  • shoefish 2011-01-10 09:53
    Rhialto:
    Wormlore:
    That is not the worst way to set a boolean to False.
    Something like this would have been "less good"

    bool memberHasFingerprint = !bool.Parse(bool.TrueString);

    And I'm sure someone creative enough could come up with something worst [sic] yet.


    Of course:

    bool memberHasFingerprint = true;

    is a very bad way of setting it to false.


    Nice, but we can do so much worse. (please forgive my pseudocode)

    memberHasFingerprint = no_duplicates_random_complex_number_generator.all? do |number|
    s * 6 #Jaybob: make it more random
    #Bobjay: more efficent. offset added since all nontrivial zeros are on the critical line below 2.4 trillion
    s = number + NOT_A_MAGIC_NUMBER #Bobjay: NOT_A_MAGIC_NUMBER is not a magic number
    root = zeta(s) == 0
    trivial = s <0 && s % 2 == 0
    critical = s.real == 0.5
    #Yobboj: change to !root || !(...) if proved
    !root || (IsRealString(root) && (critical || trivial)) #Bayjob: fixed by commenting out triviality check.
    #Jabboy: triviality check is very important, DO NOT TOUCH.
    end
  • Miral 2011-01-13 01:58
    dgatwood:
    Agreed about inlining it. Alternatively,

    s ? (!String.IsNullOrEmpty(s.ToString())) : false

    is equivalent without requiring any obscure C#-specific operators or calling a function unnecessarily to check the length of the empty string.

    Actually, no, because "s" (of type object) is not a valid boolean expression in C# -- to get it to compile you *must* write "s != null". So the above would be:

    (s != null) ? !String.IsNullOrEmpty(s.ToString()) : false

    Which can be simplified to:

    (s != null) && !String.IsNullOrEmpty(s.ToString())

    Which looks very familiar. (And yes, I think keeping this function as is makes far more sense than trying to inline it, particularly with the proposed monstrosity.)
  • anonymous 2013-05-20 10:23
    boog:
    Two:
    ShatteredArm:
    if (oneHundred == 100) {
    
    oneHundred /= 2;
    }


    Looks like oneHundred can be anything except 100.


    Unless it starts out at 200 ...

    So you believe that 200 == 100 then, do you?

    Interesting...

    //increase customer limit from 100 to 200
    
    #define 100 200
    .
    .
    .
    int oneHundred = 100;
    //DO NOT DELETE. oneHundred really needs to be 100 and for some reason it's printing 200.
    if (oneHundred == 100) {
    oneHundred /= 2;
    }

    //printf("%i", oneHundred);