• Paine (unregistered) in reply to PRMan
    PRMan:
    No, making fun of Christians seems to be OK for whatever reason. (It shouldn't be.)

    If he made fun of Jews, he would have been fired.

    If he made fun of Muslims, he would have been killed.

    He should be punished, regardless.

    Why do you hate our freedoms?

  • Indigo (unregistered)

    Perhaps some of the people who defended the rewrite of the PHP date function would like to stand up for this one? After all, it's not broken, so we shouldn't need to fix it, right?

  • Duke of New York (unregistered)

    hubbard help us if this guy ever has to convert between characters and their codes

  • (cs) in reply to Zylon
    Zylon:
    If I'm testing for truth, I'll do "if (value)", but for the opposite, yeah, I'll do "if (value == false)", simply because it makes the code easier to read than using the ! operator.
    TRWTF.

    One of the most common conditions you have to test for in any high-level language is null-inequality. Are you saying that every single time you do this, you'll waste time trying to "refactor" code that's perfectly fine, or change it into an if-then-else with an empty if block?

  • Gumpy Guss (unregistered) in reply to C

    Not that it matters at all. The "bool" type is built-in. Care to bet how many different values can it actually accept? :P

    I meant some shaky non-Java foreign place like from some C code. That could pass along any value.

  • Ouch! (unregistered) in reply to Aaron
    Aaron:
    Zylon:
    If I'm testing for truth, I'll do "if (value)", but for the opposite, yeah, I'll do "if (value == false)", simply because it makes the code easier to read than using the ! operator.
    TRWTF.

    One of the most common conditions you have to test for in any high-level language is null-inequality. Are you saying that every single time you do this, you'll waste time trying to "refactor" code that's perfectly fine, or change it into an if-then-else with an empty if block?

    if (value != 0) should be fine. The problem is (I think) that in if (!x), the '!' may be too easily overlooked. That isn't so for " != ".

  • (cs)

    I see the point, the code actually is too inaccurate. A much better function:

    /// 
    /// Turns true into false and false into true
    ///   -- similar to the church of scientology.
    /// <param name="_booInpt">True of false</param>
    /// <returns>False or true</returns>
    private bool trueandorfalse(String_booInpt)
    {
        // I'm quite sure though there is a very 
        // clever C# standard command doing this, 
        // I just can't find it right now ...
    
            Regex r1 = new Regex("^\\s*(T|t)(R|u)(U|u)(E|e)\\s*$");
            Regex r2 = new Regex("^\\s*(F|f)(A|a)(L|l)(S|s)(E|e)\\s*$");
            Bool result;
            if (r1.IsMatch(_booInpt)) {
                result = Boolean.Parse(r1.Replace(_booInpt, "false"));
            }
            else if (r2.IsMatch(_booInpt))
            {
                result = Boolean.Parse(r2.Replace(_booInpt, "true"));
            }
            else {
                result = FILE_NOT_FOUND;
            }
    
    
    }
  • SkUrRiEr (unregistered) in reply to Jay
    Jay:
    I have frequently seen code that is clearing trying to initialize a flag that looks like this:

    if (flag==true) flag=false;

    I've seen this from multiple programmers at different companies, like they must either teach this in school somewhere or it's a common form of mental illness. What, you think that it will take the computer longer to set the flag to false when it's already false then it would to first check if it's true? Actually the reverse is almost certainly the case. Or are you just being careful not to set it to false when it's currently FILE_NOT_FOUND?

    Ditto on:

    if (amount1!=0) total=total+amount1;

    Yeah, we want to save the computer from having to add the two numbers together if one of them is zero. Except, the "if" almost surely takes longer than the plus, so if it's not zero, the "if" is completely superfluous wasted time, and if it is zero, you've still taken longer than just adding it in.

    That's nothing, the coders who originally wrote the software I'm hacking have an insane love for code that looks like this:

    $variable = $_REQUEST["param"]?$_REQUEST["param"]:0;

    to implement default values for variables. They also use many other variants including random combinations of isset() and !, sometimes, just to spice it up, they use different superglobals in the test and assignment. Spot the bugs!

    They also have an incomprehensible love for code that looks like this:

    $a = FormatData($data["Address"], "address");
    $p = FormatData($data["Phone"], "phone");
    $p2 = FormatData($data["Phone2"], "phone");
    // Snip another 5-10 of the same
    
    if( $a || $p || $p2 /* snip more, sigh! */ ) {
        $out = "";
        if( $a )
            $out = $a;
    
        if( $p )
            $out .= " Phone: ".$p;
    
        // Snip more, you get the idea.
    }

    The Goggles, they do nothing!!!

  • (cs) in reply to Mike Caron
    Mike Caron:
    grg:
    Well, actually, it DOES do something more than the NOT operator (!) does.

    It maps values that are EXACTLY equal to "true" to false, everything else maps to true.

    If we assume that the incoming value might have come from an unsafe source, and might contain any random value, then it does do something slightly different than (!)

    Not that that makes it any better.

    Er, in C#, a bool only HAS two values -- it can't be anything other than true or false.

    If you're concerned about that, just throw in a guard:

    if(val != true && val != false)
      throw new BooleanIsNeitherTrueNorFalseException(val);

    I'm not sure about C#, but in VB.NET, I once encountered some code which had used some interop to cast a byte that had been read from a file to bool. The result was a boolean value which was neither true nor false. So...

    If val = True Then
       msg = "val = true"
    Else If val = False Then
       msg = "val = false"
    Else If val then
       msg = "We end up here"
    End If

    This took a while to figure out. In the debugger, if you hovered over the val, the tool-tip said it was True. But then if you stepped, it compare to True. It turned out that internally it was 255 or something.

  • (cs)

    I don't know about C#, but I've used a lot of other languages. A declaration of 'bool' means that the variable is supposed to have only two values, true and false. In some languages it could be null, which IMHO counts as a third value. In all languages variables are memory locations that can contain garbage, and the run-time stack will happily pass that garbage on to the subroutine. In theory a bool variable could be a single bit, but I've never seen a language that implements 'bool' that way. By trusting that the value is only true or false you are implicitly trusting the entire rest of the program.

    Variables inside a function can be trusted; parameters should not be trusted and global variables should never be trusted.

  • (cs) in reply to Aaron
    Aaron:
    Zylon:
    If I'm testing for truth, I'll do "if (value)", but for the opposite, yeah, I'll do "if (value == false)", simply because it makes the code easier to read than using the ! operator.
    TRWTF.

    One of the most common conditions you have to test for in any high-level language is null-inequality. Are you saying that every single time you do this, you'll waste time trying to "refactor" code that's perfectly fine, or change it into an if-then-else with an empty if block?

    I'm not testing for "null-inequality", you trolling halfwit, I'm testing for FALSE. It's a boolean, gettit?

  • ClaudeSuck.de (unregistered) in reply to Shredder
    Shredder:
    XML is a good idea for EVERYTHING.

    I need to remeike my bathruem. Pls send me teh codez.

  • methinks (unregistered) in reply to KD
    KD:
    The real WTF is when a decent compiler doesn't turn this method call into a simple ! operation.

    The compiler is there to optimize, not to work around absolute idiocy... ;oP

  • ClaudeSuck.de (unregistered) in reply to Jay
    Jay:
    I have frequently seen code that is clearing trying to initialize a flag that looks like this:

    if (flag==true) flag=false;

    I've seen this from multiple programmers at different companies, like they must either teach this in school somewhere or it's a common form of mental illness. What, you think that it will take the computer longer to set the flag to false when it's already false then it would to first check if it's true? Actually the reverse is almost certainly the case. Or are you just being careful not to set it to false when it's currently FILE_NOT_FOUND?

    Ditto on:

    if (amount1!=0) total=total+amount1;

    Yeah, we want to save the computer from having to add the two numbers together if one of them is zero. Except, the "if" almost surely takes longer than the plus, so if it's not zero, the "if" is completely superfluous wasted time, and if it is zero, you've still taken longer than just adding it in.

    It's because you're writing bad code! This should be: if (flag==true) flag=false else flag=true;

    if (amount1!=0) total=total+amount1 else total=total+amount1;

    CAPTHA: ratis - must have something to do with "ratio"

  • ClaudeSuck.de (unregistered) in reply to ClaudeSuck.de
    ClaudeSuck.de:
    It's because you're writing bad code! This should be: if (flag==true) flag=false else flag=true;

    if (amount1!=0) total=total+amount1 else total=total+amount1;

    BTW, could be better: if (flag==true) flag=true else flag=false;

    at least you take a decision, like an adult

  • Borat (unregistered)

    this.Suit.Color != Colors.Black

  • (cs) in reply to silent d
    silent d:
    From now on, I'm outsourcing all my development work to the Church of Scientology. I mean, at least they admit their Book was written by a science fiction author.
    I'll outsource all my I.T. needs to the Church of the Evolved Lamb. They admit that their Book was written by a drunken scam artist, and they're quite excellent in the field of I.T. also.
  • flabdablet (unregistered) in reply to highphilosopher

    Yeah, that seems a bit half hearted. Better:

    if((!shouldContinue) == false) { } else { goto skip; }

    // blah....

    skip:

  • md5sum (unregistered) in reply to highphilosopher

    I remember that one! among MANY, MANY others...

  • (cs) in reply to PRMan
    PRMan:
    No, making fun of Christians seems to be OK for whatever reason. (It shouldn't be.)

    If he made fun of Jews, he would have been fired.

    If he made fun of Muslims, he would have been killed.

    He should be punished, regardless.

    Bollocks. Making fun of anyone is OK, we have this thing called freedom of speech.

    Most Christians and Muslims can take a joke too. And Jewish humour is legendary for its self-deprecating nature.

    It's only saddos like you who go around saying people "should be punished" for not thinking the exact same way as you do.

  • Borat (unregistered) in reply to Borat
    Borat:
    this.Suit.Color != Colors.Black
    %Suit = ();
    $Suit{"Color"} = !"Black";
    print $Suit{"Color"};
    
    Valid Perl Code

    Captcha: damnum "Damn. Um...."

  • (cs) in reply to Zylon
    Zylon:
    Wheaties:
    I've seen this before unfortunately. Only it's been 1 to 0 and 0 to 1 instead of using the built in boolean of the language.
    And even then, trivial to invert with "value = 1 - value". You used to see that a lot in old BASIC programs.
    Mostly broken ones, I would suspect, since in most of the old BASICs "true" was numerically -1 rather than 1. Though how a result of 2 was interpreted was probably variable.

    I remember working out expressions I could use to set something according to the result of a comparison without using an if statement, because it would be too long to fit on one line as an if statement. Now that we have multi-line if statements and arbitrary line lengths this is only useful for obfuscation :)

  • Capulet (unregistered) in reply to SkUrRiEr
    SkUrRiEr:
    That's nothing, the coders who originally wrote the software I'm hacking have an insane love for code that looks like this:
    $variable = $_REQUEST["param"]?$_REQUEST["param"]:0;
    What is so insane about that? I've looked through your original post backwards and forward, and I can't figure out why this is biting your arse. Do you have a problem with ternary operations?
  • Anonymouse (unregistered)

    The Clever Coder probably didn't get that job at Sunbelt Software; it's full of Scientologists, from Ekleberry on down.

  • Lobe (unregistered) in reply to Capulet
    Capulet:
    SkUrRiEr:
    That's nothing, the coders who originally wrote the software I'm hacking have an insane love for code that looks like this:
    $variable = $_REQUEST["param"]?$_REQUEST["param"]:0;
    What is so insane about that? I've looked through your original post backwards and forward, and I can't figure out why this is biting your arse. Do you have a problem with ternary operations?
    Possibly it should be:
    $variable = array_key_exists("param", $_REQUEST)?$_REQUEST["param"]:0;
    Either that or he doesn't like the way that 0 is being used as the default FALSE value. I can think of plenty of resons to do that, and not to do it as well, but he doesn't tell us that much.

    It looks like another of those comments where they don't tell you quite enough for you to figure out what their problem is.

  • (cs) in reply to Scarlet Manuka
    Scarlet Manuka:
    Zylon:
    Wheaties:
    I've seen this before unfortunately. Only it's been 1 to 0 and 0 to 1 instead of using the built in boolean of the language.
    And even then, trivial to invert with "value = 1 - value". You used to see that a lot in old BASIC programs.
    Mostly broken ones, I would suspect, since in most of the old BASICs "true" was numerically -1 rather than 1. Though how a result of 2 was interpreted was probably variable.
    The old BASICs didn't have a boolean type, so TRUE was whatever the hell you wanted it to be. So sensible coders made TRUE=1 and FALSE=0. -1 is just retarded.
  • Boss (unregistered) in reply to nitehawk
    nitehawk:
    If it wasnt for the amusing "similar to the church of scientology" text, I would fire this person on the spot.
    Like a Boss

    (Ahem. The whole barbershop now. "Spam, spam, it comes in a can, it's spam, it's spam, it's spam! Spaaaaaaammmmmmmm.")

  • Geoffey Sturdy (unregistered)

    DaveK

    "Bollocks. Making fun of anyone is OK, we have this thing called freedom of speech.

    Most Christians and Muslims can take a joke too. And Jewish humour is legendary for its self-deprecating nature.

    It's only saddos like you who go around saying people "should be punished" for not thinking the exact same way as you do"

    Not in the UK You can be arrested for "hate crinmes" for making jokes about Blacks Gays Muslims

    but not apparently Christians or Jews in a country where a mother wih a disabled daughter can commit suicide after bieng terrorised by thugs and the police simply saying "close your curtains and pretend they arn't there" and yet a Christian couple can be arrested for Arguing with amuslim about religion .

    Thr British "justice" system - the Ultimate WTF

  • Lee K-T (unregistered) in reply to Daid
    Daid:
    highphilosopher:
    reminds me of a

    if((!shouldContinue) == false) {

    // blah....

    }

    I saw one time. Suddenly the death penalty seems sort of reasonable in extreme situations.

    I have seen worse:

    if((!notShouldContinue) == false)

    Good luck.

    This is not a copy-past so it might not be 100% the same (I think one of the cases was missing actually, lol). Anyway here's what I've found:

    bool var1 = ...; bool var2;

    if (true == true) { if (var1 == true) { var2 = true; } else if (var1 == false) { var2 = false; } } else if (false == false) { if (var1 == false) { var2 = false; } else if (var1 == true) { var2 = true; } }

    And then when I tried to explain to the 2-4 YEARS EXPERIENCED .Net EXPERT that maybe... there... might... exist a way to slightly improve the way he handles booleans (say var2=var1), he asked me what I meant by "boolean"!?! And this guy has the same job as me and therefore probably earns the same thing at the end of the month...

  • No Particular Order (unregistered)

    Billant ... NOT

  • ratis (unregistered) in reply to evilspoons
    evilspoons:
    I don't understand why it's OK to make fun of Scientologists just because their religion is "new" or whatever. I'm sure this guy would've been reprimanded or even fired if the same comment was put there about Christianity, Judaism, or whatever and someone actually read it. (I'd have listed more religions but my brain appears to have blown a fuse). I can list just as many bizarre things in the "old" religions as in Scientology.

    On another note, it is my personal opinion that L. Ron Hubbard was either a nutcase (please note I am not a fan of any religion, mainstream or otherwise) or a genius. I believe he made a comment sometime before Scientology appeared about how 'if you really want to make money you'd get into religion' (or something, I've botched the quote) and then tada, he starts his own religion and becomes massively rich before he dies.

    It's OK to make fun of scientology since its OK to make fun of every religion. Scientology is just a very easy victim since its (surprisingly) even MORE far fetched than the other big religions. And that is quite a feat and deserves ridicule!

  • Vollhorst (unregistered) in reply to Ouch!
    Ouch!:
    Aaron:
    Zylon:
    If I'm testing for truth, I'll do "if (value)", but for the opposite, yeah, I'll do "if (value == false)", simply because it makes the code easier to read than using the ! operator.
    TRWTF.

    One of the most common conditions you have to test for in any high-level language is null-inequality. Are you saying that every single time you do this, you'll waste time trying to "refactor" code that's perfectly fine, or change it into an if-then-else with an empty if block?

    if (value != 0) should be fine. The problem is (I think) that in if (!x), the '!' may be too easily overlooked. That isn't so for " != ".
    How about "if (not value)" or "if (value not_eq true)"?

    Or "if (value ^ !(--(int*(&value))))"? And why the fuck is the function not static?

  • hambai (unregistered)

    This reminds me of my favorite php function ever :)

    function checkifyes($pArg) {
       if ($pArg = 'yes') {
          return true;
       } else {
          return false;
       }
    }
    

    Notice the single equal sign in the expression. A classic WTF :)

  • prionic6 (unregistered) in reply to highphilosopher

    Often, when I see code like that, it is a result of someone doing refactoring and inlining a variable that is now constant.

  • prionic6 (unregistered)
    highphilosopher:
    reminds me of a

    if((!shouldContinue) == false) {

    // blah....

    }

    I saw one time. Suddenly the death penalty seems sort of reasonable in extreme situations.

    Often, when I see code like that, it is a result of someone doing refactoring and inlining a variable that is now constant.

  • (cs) in reply to Zylon
    Zylon:
    The old BASICs didn't have a boolean type, so TRUE was whatever the hell you wanted it to be. So sensible coders made TRUE=1 and FALSE=0. -1 is just retarded.
    Actually the -1 was due to performance reasons. Think CPU (neg-flag).

    And somebody mentioned COBOL. No, it's no problem testing on booleans in COBOL (and COBOL-like languages) without saying 'if blabla = true'.

  • Jasper (unregistered)

    How do people who write code like that ever get a job as a programmer? People who write code like that should be fired immediately.

    Did they get a serious job interview, or are they the CEO's nephew or something?

    Suppose a carpenter comes to work on your house, and the carpenter doesn't know which side is up on a hammer. Would you allow him to do the work?

  • anonymous coward (unregistered) in reply to Anon

    WTF #1 is not knowing the ! operator.

    This is the wtf of course but...

    WTF #2 is not knowing that the logical operation you are doing is called "not".

    ... is even more horrible. Programmers are supposed to have studied maths; and especially boolean maths. It's like this guy didnt go to highschool.

  • (cs) in reply to Gerrit
    Gerrit:
    Or they learned the trade using COBOL or some other language very unlike C. In some languages boolean operators are only used within the context of statements like if and while (or their equivalents).

    If that is your background it takes some getting used to the idea that a boolean is a first-class object, just like someone with a background in Java or C# will need to get used to a language where classes, methods and functions are first-class objects.

    Since when was bool(ean) a 'first-class' type in C??

  • (cs) in reply to ClaudeSuck.de
    ClaudeSuck.de:
    Jay:
    I have frequently seen code that is clearing trying to initialize a flag that looks like this:

    if (flag==true) flag=false; ...

    It's because you're writing bad code! This should be: if (flag==true) flag=false else flag=true; ...

    No no no you've both got it all wrong. The most efficient way is clearly:

    flag = (flag==true) ? trueandorfalse(flag) : flag;
  • refoveoman (unregistered) in reply to lawlsci
    lawlsci:
    Tom Cruise:
    SurfMan:
    At least it's well documented, and even has a touch of humor (Scientology wtf?)
    I'm a Scientologist, you insensitive clod!

    Calm down, don't go all Sci-Fi on him!

    Yeah, Battlefield Earth was quite enough.

  • finntroll (unregistered) in reply to Zylon
    Zylon:
    Anon:
    We now have Scientologist trolls?
    You're just being glib. All Scientologists are trolls.
    Heyheyhey, let's not get all speciesist here.
  • Alberto (unregistered) in reply to T $

    Still not good enough:

    T $:
    The fool! He needs another if!

    ///

    /// Turns true into false and false into true /// -- similar to the church of scientology. /// <param name="_booInpt">True of false</param> /// <returns>False or true</returns> private bool trueandorfalse(bool _booInpt) { // I'm quite sure though there is a very // clever C# standard command doing this, // I just can't find it right now ... if (_booInpt == true) return false; if (_booInpt == false) return true;

    return FILE_NOT_FOUND }
  • Lee K-T (unregistered) in reply to finntroll
    finntroll:
    Zylon:
    Anon:
    We now have Scientologist trolls?
    You're just being glib. All Scientologists are trolls.
    Heyheyhey, let's not get all speciesist here.

    He's not. He didn't say that all Trolls are Scientologists!

  • H2 (unregistered)

    Hey, this reminds me of a german phrase:

    "Man darf ruhig dumm sein, man muss sich nur zu helfen wissen." "You are allowed to be stupid, you just have to find a way to help yourself."

    P.S.: I hope I translated it correctly and it hasn't lost it's meaning.

  • El Dorko (unregistered) in reply to NightDweller

    "Personally i find this (value==false) to be aesthetically unappealing."

    Personally I find snot-nose attitude like that soon to become aesthetically unappealing, right after my fist meets that nose.

    No offense intended to you personally, I've just had my share of "boo hoo I want to spend time refactoring this code because it doesn't match my style" whining. If it works, don't touch it. Shut up.

    There, I feel better now. Thanks for listening - or not.

  • Anonymous (unregistered) in reply to El Dorko
    El Dorko:
    "Personally i find this (value==false) to be aesthetically unappealing."

    Personally I find snot-nose attitude like that soon to become aesthetically unappealing, right after my fist meets that nose.

    No offense intended to you personally, I've just had my share of "boo hoo I want to spend time refactoring this code because it doesn't match my style" whining. If it works, don't touch it. Shut up.

    There, I feel better now. Thanks for listening - or not.

    Wow, what a complete dorko.

  • St Mary & Sir Galahad (unregistered) in reply to PRMan

    Uhh, Scientology... is a joke.

  • bob (unregistered)
    Wow, what a complete dorko.

    I've never felt compelled to comment before but I have to agree.

    What a complete dorko.

  • ih8u (unregistered) in reply to RHuckster
    RHuckster:
    The lawyers at the Church of Scientology have been notified and will sue the pants off of Alex, the original author of this posting, and the original author of the code.

    Addendum (2009-10-07 11:21): The lawyers at the Church of Scientology have been notified and will sue the pants off of Alex, the original author of this posting, and the original author of the code. Katie Holmes will represent the church in court and will appoint Tom Cruise as the judge. If you accuse them of bias by attempting to appoint a fellow follower as the judge, they shall sue you a second time.

    The joke is on them. Alex lost his pants a while ago at your mom's house. He just never bothered to go get them.

    CAPTCHA: abigo -- Alex wishes.

Leave a comment on “The Clever Coder”

Log In or post as a guest

Replying to comment #:

« Return to Article