• Alexandru Savu (unregistered)

    Way funny! Incredible :))

  • @Deprecated (unregistered)

    The name trueandorfalse is just dumb. Are those supposed to be boolean operations applied to the input or something?

    I think a much better name would be boolean todayIsBackwardsDay(boolean input) ...

  • Robb (unregistered)

    booInpt?

    As in trying to spook the input?

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

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

  • Anon (unregistered) in reply to Tom Cruise
    Tom Cruise:
    I'm a Scientologist, you insensitive clod!
    There's help for you, Tom. Call 866-XSEA-ORG. You can still get out. David Miscavige physically beats his subordinates.

    http://www.tampabay.com/news/article1012148.ece

  • Anon (unregistered) in reply to NightDweller
    NightDweller:
    Anon:
    NightDweller:
    trueandorfalse(its) only that the coder trueandorfalse(does) know the basic operands, but he also feels he trueandorfalse(could) be bothered to look for them at the moment.

    but he is somehow capable of endless trueandorfalse(wit) in his comments.

    You fail on your last use of trueandorfalse.

    wit not? not wit? trueandorfalse(does) make sense.

    That one was intended as a "...endless wit (not!) .." sort of thing.

    Ah, so it's a formatting problem. Clearly we need an overloaded method that takes an IFormatProvider.

    Then we can do trueandorfalse(wit,new EncloseInBracketsProviderAndAddExclamationPointFormatProvider());

  • Mike Caron (unregistered) in reply to grg
    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);
  • (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);

    Are you seriously suggesting NOT sanitizing your Boolean inputs? WTF?

  • Justin (unregistered) in reply to Buddy
    Buddy:
    // converts true to false and false to true
    // extra ! are to make sure it's absolutely, positively,
    // unambiguously, categorically, unconditionally, decidedly,
    // unquestionably and definitely inverted
    // unless I counted wrong
    bool invert(bool b)
    {
        return !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!b;
    }
    
    Extra credit to those who actually counted!

    there, ftfy

  • bool (unregistered)

    Where do people learn that they should compare booleans to the value of true.

    I see people around me doing it. I don't get it. I've never compare a boolean, only test it.

  • (cs) in reply to bool
    bool:
    Where do people learn that they should compare booleans to the value of true.

    I see people around me doing it. I don't get it. I've never compare a boolean, only test it.

    qft

    why the hell do we see "if (value == true) " instead of "if (value)"

    i hate that, especially with a well chosen boolean name it reads so much easier to test for it instead of comparing

    it's also less confusing if you are testing for empty arrays or whatever, then they aren't really true or false, just empty

  • Anon (unregistered) in reply to bool
    bool:
    Where do people learn that they should compare booleans to the value of true.

    I see people around me doing it. I don't get it. I've never compare a boolean, only test it.

    In C# if you are using a bool? (nullable bool), you would need to compare it to true since it could be true, false or null.

    i.e.

    if (nullableBool)

    doesn't compile because nullableBool isn't a bool.

    Of course, this isn't the case here, but it could be a habit.

  • bool (unregistered)

    After writing that last comment about comparing booleans. I think I realized why.

    In undergrad university I took lots of math (including sets), plus some philosophy (including logic). Maybe that's why I've always programmed with booleans as abstract logical values. Of course it helps if you maintain and study good code from other good programmers.

    Those who program with booleans as just another base type do have to compare to 'true' as the test.

    Sound reasonable ?

  • magical truth values (unregistered)

    Maybe they have been using the following header:

    #define true 0 #define false 1 #define maybe 9

  • (cs) in reply to Anon
    Anon:
    NightDweller:
    Anon:
    NightDweller:
    trueandorfalse(its) only that the coder trueandorfalse(does) know the basic operands, but he also feels he trueandorfalse(could) be bothered to look for them at the moment.

    but he is somehow capable of endless trueandorfalse(wit) in his comments.

    You fail on your last use of trueandorfalse.

    wit not? not wit? trueandorfalse(does) make sense.

    That one was intended as a "...endless wit (not!) .." sort of thing.

    Ah, so it's a formatting problem. Clearly we need an overloaded method that takes an IFormatProvider.

    Then we can do trueandorfalse(wit,new EncloseInBracketsProviderAndAddExclamationPointFormatProvider());

    im sure you mean: "..encloseinbracketsproviderandaddexclamationpointformatprovider.."

    Obviously the author of trueandorfalse adheres to very strict coding standards. he'd be most upset if you were to introduce all these strange looking characters in the middle of the method name.

  • tB (unregistered) in reply to Mike Caron

    Are you sure that the C# bool does not provide for FILE_NOT_FOUND? If that's the case then nobody should ever use C# ever again.

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

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

    Jeez. C'mon. We all know it's 3!

    True, False, File_Not_Found

  • Gerrit (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.

    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.

    I wouldn't call it a mental illness unless people stubbornly keep failing to pick it up, and even then I've seen worse things.

    Note to self: time to start learning Lisp

  • Jef Claes (unregistered)

    You have to give him credit for the awesome comments tho :D

  • Sylver (unregistered) in reply to Lisa McPherson
    Lisa McPherson:
    WTF:
    /// -- similar to the church of scientology.
    The Church of Scientology is a very dangerous organization.

    http://en.wikipedia.org/wiki/Lisa_mcpherson

    http://en.wikipedia.org/wiki/Operation_Freakout

    http://en.wikipedia.org/wiki/Operation_Snow_White

    Be very careful how you decide to engage them.

    Lame and uninformed. There is an other WTF.

  • LO (unregistered)

    I hate how the method name is spelled (No capitals for Camel-style), I hate underscore as argument name and I hate whole method reason to exist as all people above mentioned already...

    And I love comment about scientology, hke, hke..

  • Anon (unregistered) in reply to t-bone

    I usually write it as "if (value === true)" in Javascript, because

    1. Javascript is dynamically typed
    2. I don't ever trust Javascript to implicitly do what I expect.

    For C# and other statically typed languages I agree with you.

  • (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.
    Oh man, this comment deserves to be blue. Well done sir.
  • bramster (unregistered) in reply to SurfMan
    SurfMan:
    At least it's well documented, and even has a touch of humor (Scientology wtf?)

    Yeah. How do comment a "!" ?

  • (cs)

    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.

    First though, I'll try to refactor so that I don't have to test a boolean for falsehood. This is something one of my old college instructors drilled into us. Seems like an insignificant thing, but it really can make it easier to get a handle on code you haven't looked at for ages. Probably because it more closely mirrors human thought processes. Start throwing in negatives, and, well... confusion ensues.

  • RBoy (unregistered) in reply to @Deprecated
    @Deprecated:
    The name trueandorfalse is just dumb. Are those supposed to be boolean operations applied to the input or something?

    I think a much better name would be boolean todayIsBackwardsDay(boolean input) ...

    But if today really was backwards day, then it would leave the output the same as the input...

  • Jedi Knight (unregistered) in reply to Sylver
    Sylver:
    There is an other WTF.

    In my head, why do I hear this in Yoda's voice?

  • !? (unregistered) in reply to Sylver
    Sylver:
    Lisa McPherson:
    WTF:
    /// -- similar to the church of scientology.
    The Church of Scientology is a very dangerous organization.

    http://en.wikipedia.org/wiki/Lisa_mcpherson

    http://en.wikipedia.org/wiki/Operation_Freakout

    http://en.wikipedia.org/wiki/Operation_Snow_White

    Be very careful how you decide to engage them.

    Lame and uninformed. There is an other WTF.

    People here usually say "this is TRWTF". Hm, suspicious.

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

    First though, I'll try to refactor so that I don't have to test a boolean for falsehood. This is something one of my old college instructors drilled into us. Seems like an insignificant thing, but it really can make it easier to get a handle on code you haven't looked at for ages. Probably because it more closely mirrors human thought processes. Start throwing in negatives, and, well... confusion ensues.

    Personally i find this (value==false) to be aesthetically unappealing. its a worthwhile habit to have if you code in c/c++ where the if checks against zero values. in which case it would probably be a good idea to also do the (value==true) side.

    In other languages i prefer using meaningful variable names. (i.e. isSomethingOrOther).

  • (cs) in reply to Anonymous
    Anonymous:
    Why is it called trueandorfalse() ?

    I guess its because he's "clever". Based on the name, I would expect it to be like this:

    /// Returns true if the input is true and/or false
    private bool trueandorfalse(bool _booInpt)
    {
        return true;
    }
    
    

    Now, that would be an undisputable WTF.

  • Anon (unregistered) in reply to RayMarron
    RayMarron:
    This comment is NOT! clever..

    ftfy... HIGH FIVE!

  • Rob (unregistered)

    So, someone tells this guy there is a ! operator. He quickly realize his mistake and corrects the code like this:

    ///

    /// 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) { return !_booInput; }

  • Anon (unregistered) in reply to NightDweller
    NightDweller:
    In other languages i prefer using meaningful variable names. (i.e. isSomethingOrOther).

    See, I'd use an enum there with possible values of "Something" and "Other". If you use a bool, does a value of true mean "Something" or does it mean "Other"? Alternatively, use a bool isSomething where it is implied that if isSomething is false, then it must be other.

  • Anon (unregistered) in reply to Sylver
    Sylver:
    Lisa McPherson:
    WTF:
    /// -- similar to the church of scientology.
    The Church of Scientology is a very dangerous organization.

    http://en.wikipedia.org/wiki/Lisa_mcpherson

    http://en.wikipedia.org/wiki/Operation_Freakout

    http://en.wikipedia.org/wiki/Operation_Snow_White

    Be very careful how you decide to engage them.

    Lame and uninformed. There is an other WTF.

    We now have Scientologist trolls?

  • (cs) in reply to Anon
    Anon:
    We now have Scientologist trolls?
    You're just being glib. All Scientologists are trolls.
  • (cs)

    Not!

  • (cs) in reply to Tom Cruise
    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!
    Hey! I resemble that accusation! I'm a clod, you insensitive Scientologist!
  • (cs)

    Clearly the entire purpose of this function is to sneak in a Scientology joke.

  • TheCPUWizard (unregistered) in reply to OutlawProgrammer
    OutlawProgrammer:
    TRWTF is Microsoft thinking that using XML for comments was a good idea.

    Have you ever even used SandCastle (or equivilant) to generate complete documentation [the equivilany format and content of MSDN for example] for your code??????

    Having the documentation close to the source dramatically improves the chance that it will be maintained.

    If you are against XML per-se as the syntax, then what would YOU recommend to place: code, parameters cross- references, examples, summary information, additional remarks, etc. etc. inline with the code?????

    Also what tool would use use to validate that the information was well formed???

    While many people only use the be anything that follows this schema:

    <?xml version="1.0" encoding="utf-8" ?>
    • <XMLDocCommentSchema>
    • <CodeElement type="Module">
    • <Template> <remarks /> </Template>
    • <CompletionList> <include file="" path="" /> <permission cref="" /> <remarks /> </CompletionList> </CodeElement>
    • <CodeElement type="Class">
    • <Template> <remarks /> </Template>
    • <CompletionList> <include file="" path="" /> <permission cref="" /> <remarks /> </CompletionList> </CodeElement>
    • <CodeElement type="Structure">
    • <Template> <remarks /> </Template>
    • <CompletionList> <include file="" path="" /> <permission cref="" /> <remarks /> </CompletionList> </CodeElement>
    • <CodeElement type="Interface">
    • <Template> <remarks /> </Template>
    • <CompletionList> <include file="" path="" /> <permission cref="" /> <remarks /> </CompletionList> </CodeElement>
    • <CodeElement type="Enum">
    • <Template> <remarks /> </Template>
    • <CompletionList> <include file="" path="" /> <permission cref="" /> <remarks /> </CompletionList> </CodeElement>
    • <CodeElement type="Property">
    • <Template> <param /> <value /> <remarks /> </Template>
    • <CompletionList> <exception cref="" /> <include file="" path="" /> <param name="" /> <permission cref="" /> <remarks /> <value /> </CompletionList> </CodeElement>
    • <CodeElement type="Sub">
    • <Template> <param /> <remarks /> </Template>
    • <CompletionList> <exception cref="" /> <include file="" path="" /> <param name="" /> <permission cref="" /> <remarks /> </CompletionList> </CodeElement>
    • <CodeElement type="Function">
    • <Template> <developer /> <param /> <returns /> <remarks /> </Template>
    • <CompletionList> <exception cref="" /> <include file="" path="" /> <param name="" /> <permission cref="" /> <remarks /> <returns /> <developer /> </CompletionList> </CodeElement>
    • <CodeElement type="Operator">
    • <Template> <param /> <returns /> <remarks /> </Template>
    • <CompletionList> <exception cref="" /> <include file="" path="" /> <param name="" /> <permission cref="" /> <remarks /> <returns /> </CompletionList> </CodeElement>
    • <CodeElement type="Declare">
    • <Template> <param /> <returns /> <remarks /> </Template>
    • <CompletionList> <exception cref="" /> <include file="" path="" /> <param name="" /> <permission cref="" /> <remarks /> <returns /> </CompletionList> </CodeElement>
    • <CodeElement type="Field">
    • <Template> <remarks /> </Template>
    • <CompletionList> <include file="" path="" /> <permission cref="" /> <remarks /> </CompletionList> </CodeElement>
    • <CodeElement type="Delegate">
    • <Template> <param /> <returns /> <remarks /> </Template>
    • <CompletionList> <include file="" path="" /> <param name="" /> <permission cref="" /> <remarks /> <returns /> </CompletionList> </CodeElement>
    • <CodeElement type="Event">
    • <Template> <param /> <remarks /> </Template>
    • <CompletionList> <include file="" path="" /> <param name="" /> <permission cref="" /> <remarks /> </CompletionList> </CodeElement>
    • <ChildCompletionList> <c /> <example />
    • <list type="">
    • <listheader> <term /> <description /> </listheader> </list> <para /> <paramref name="" /> <see cref="" /> <seealso cref="" /> </ChildCompletionList> </XMLDocCommentSchema>
  • (cs)

    _booInpt has got to be the worst name for a variable ever. Might as well just hit random keys.

  • (cs)

    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.

  • Johnny (unregistered)

    It shold look like this:

    /// 
    /// 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 == true)
    return true;
    } 
    
  • Anonymous Cowherd (unregistered) in reply to Anon
    Anon:
    NightDweller:
    trueandorfalse(its) only that the coder trueandorfalse(does) know the basic operands, but he also feels he trueandorfalse(could) be bothered to look for them at the moment.

    but he is somehow capable of endless trueandorfalse(wit) in his comments.

    You fail on your last use of trueandorfalse.

    wit not? not wit? trueandorfalse(does) make sense.

    (Attempt #3)

    "Witn't"

    Captcha: "augue" v. to engage in a verbal disagueement.

  • (cs) in reply to bramster
    bramster:
    SurfMan:
    At least it's well documented, and even has a touch of humor (Scientology wtf?)
    Yeah. How do comment a "!" ?
    It can be done, but you have to be careful not to do it emphatically and use another exclamation point or you'll negate your entire comment.

    L. Ron Hubbard taught me that.

  • (cs) 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.
    It's got nothing to do with their religion being "new" and everything to do with it being quackery blatantly fabricated as a pyramid marketing scam by a notorious liar, charlatan and psychotic, which has over the years degenerated into gangsterism and bunker-mentality despotism presided over by a bunch of thugs and crooks who on occasion even manage to pose a significant threat to the freedom and security of civil society. They believe they are above the law and have special rights and privileges over the rest of us.

    That's what it's about.

    FYI.

  • (cs) in reply to Anonymous
    Anonymous:
    Why is it called trueandorfalse() ?
    Because he didn't read the Chicago Manual of Style, which says you should avoid "and/or" and write "A, or B, or both"; hence it should be named trueorfalseorboth(). (Chicago doesn't have advice for case or spacing in code, so you choose.)
  • (cs) in reply to NightDweller
    NightDweller:
    (i.e. isSomethingOrOther).
    You mean isSomethingAndOrOther.
  • Xenu (unregistered) in reply to DaveK
    DaveK:
    evilspoons:
    I don't understand why it's OK to make fun of Scientologists just because their religion is "new" or whatever.
    It's got nothing to do with their religion being "new" and everything to do with it being quackery blatantly fabricated as a pyramid marketing scam by a notorious liar, charlatan and psychotic, which has over the years degenerated into gangsterism and bunker-mentality despotism presided over by a bunch of thugs and crooks who on occasion even manage to pose a significant threat to the freedom and security of civil society. They believe they are above the law and have special rights and privileges over the rest of us.

    That's what it's about.

    FYI.

    This and after giving the CoS $150,000 USD, you too can discover that it's just a UFO cult.

    http://www.cs.cmu.edu/~dst/OTIII/spaink-ot3.html

    Anybody suckered into paying $150,000 to learn about Galactic Overlord Xenu, has bigger problems than a couple of people "making fun" of their "religion" on some random IT/software message board.

  • PRMan (unregistered) in reply to evilspoons

    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.

  • J. Random PMP (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.

    Don't be hating! They're just doing the needful!

    CAPTCHA:ullamcorper...see, they're even taking care of the captchas!

Leave a comment on “The Clever Coder”

Log In or post as a guest

Replying to comment #:

« Return to Article