• unekdoud (unregistered)

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

    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

  • (cs) in reply to Wormlore

    This one is scattered through one of our product's code base.

    bool someVar = thisVar ? false : thisVar;

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

  • (cs)

    I think a certain dev heard "You should leave comments in the code" and kind of misunderstood what was meant by "comment".

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

    What language is number 2?

  • false (unregistered)
    [image]

    The colon is very important. DO NOT TOUCH!

  • bluesman (unregistered)

    I've touched your colon. Pray I don't...

    Wait... Blech... Never mind.

  • (cs)
    /*
    * 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 (unregistered) in reply to frits
    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.

  • ÃÆâ€â„ (unregistered) in reply to bluesman
    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 (unregistered) in reply to forgottenlord
    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? ?? ?

  • (cs)

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

    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 (unregistered)

    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.

  • (cs)

    Did anyone else notice the "(TM)" in the rant comment?

    At least he is respectful of the copyright laws...

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

  • (cs)
    /* * 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 (unregistered) in reply to trwtf
    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 (unregistered) in reply to Two
    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 (unregistered) in reply to JamesCurran
    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?

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

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

    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 (unregistered)

    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 (unregistered) in reply to Rand Dumm
    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 (unregistered)
    <?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).

  • (cs) in reply to K
    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 (unregistered)
    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 (unregistered) in reply to da Doctah
    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?

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

  • (cs) 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...

    Puhleeze. Everyone knows 200 equals twice 100.

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

    Not really, your way tries to execute the output of the php script, most of the time, HTML, that wouldn't work.

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

    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 (unregistered) in reply to K
    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 (unregistered) in reply to lomendil
    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).

  • (cs) in reply to JamesCurran
    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 (unregistered) in reply to Matt Westwood
    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 (unregistered) in reply to da Doctah
    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 (unregistered) in reply to djhayman
    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 (unregistered) in reply to da Doctah
    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 (unregistered) in reply to da Doctah
    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 (unregistered) in reply to da Doctah
    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 (unregistered) in reply to daily
    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 (unregistered) in reply to the beholder
    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!

Leave a comment on “CompareObjectAsIAlertDocumentOrNullIfNotCastable and More”

Log In or post as a guest

Replying to comment #:

« Return to Article