• Matt Westwood (unregistered) in reply to My Name
    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 (unregistered)

    "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 (unregistered) in reply to Matt Westwood
    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 (unregistered) in reply to Wormlore

    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 (unregistered) in reply to Anon
    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 (unregistered) in reply to 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

  • weazel (unregistered)

    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 (unregistered) in reply to ShatteredArm
    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 (unregistered) in reply to Andy Holyer
    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 (unregistered) in reply to ShatteredArm

    In Russian "not" is "не", it can be transliterated as "ne".

  • Anon (unregistered) in reply to Ge
    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 (unregistered) in reply to weazel
    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 (unregistered) in reply to Wormlore
    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

  • (cs)

    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 (unregistered) in reply to Ryan
    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 (unregistered) in reply to Medinoc
    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 (unregistered) in reply to oheso
    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... ;-)

  • (cs) in reply to pbean
    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 (unregistered) in reply to Matt Westwood
    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 (unregistered) in reply to 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());
    }
    

    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 (unregistered) in reply to trwtf
    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 (unregistered) in reply to digitalwitch
    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 (unregistered) in reply to Arvind
    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 (unregistered) in reply to frits
    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 (unregistered)

    Oh, I see the problem.

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

    There, that should be more efficient.

  • (cs)

    In Alabama they'd have written:

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

  • Ben (unregistered) in reply to frits
    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 (unregistered)

    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 (unregistered) in reply to Wormlore
    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 (unregistered)
    "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 (unregistered) in reply to DOA

    Yup, I think many of the WTF's we see here could have the whole comment appended somewhere in the code.

  • Random (unregistered) in reply to led
    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.

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

  • (cs) in reply to Rhialto
    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 (unregistered) in reply to Anon
    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 (unregistered)
    <?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 (unregistered) in reply to Matt Westwood
    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 (unregistered) in reply to Ge
    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 (unregistered) in reply to Luiz Felipe
    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 (unregistered) in reply to Anything you can do, I can do worse

    That should be

    #define TRUE 0; #define FALSE 1;

    bool memberHasFingerprint = TRUE; // set to false

  • muteKi (unregistered) in reply to Wormlore

    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 (unregistered) in reply to muteKi

    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 (unregistered) in reply to Anon

    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 (unregistered) in reply to tim
    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

  • Diego (unregistered) in reply to frits

    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 (unregistered) in reply to Rhialto
    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 (unregistered) in reply to dgatwood
    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 (unregistered) in reply to boog
    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);

Leave a comment on “CompareObjectAsIAlertDocumentOrNullIfNotCastable and More”

Log In or post as a guest

Replying to comment #:

« Return to Article