• (cs)

    priceless...[B]

  • (cs)

    What a dork. He's supposed to use bitfields. What happens tomorrow when they need to cover the case of applying the adjustment to only aggregates?

    Doesn't he know what BOOL means? Bitfield Object Operating as Long.

    --Rank

     

  • Handkor (unregistered) in reply to res2

    I guess his binary looks like this 11011012.

    I can understand having more states than true and false like if I was working on software used for circuit design I could have a function IsConnected returning {true, false, HI_Z} but I would create a enum for this not put BOOL ret = 2.

  • (cs) in reply to Handkor

    And there was me, innocently thinking it was going to be another SQL WTF to do with tri-state logic.

    Nice.

    Very, very, nice. I bow to obviously superior code-fu.

    Simon

  • (cs)
    Okay . . . 

    #define TRUE_TWO 2

    // check if adjustment should be applied to aggregates as well if ( IsAdministrative == TRUE_TWO )
    {
    // ... }
    Better?

  • (cs)

    Pesky booleans.  Just a special case of an enum.

    Could've been worse... he could've quantized the values between 0 and
    1 on a float.

    #define FALSE 0.0f
    #define ALMOST_FALSE 0.1f
    #define NOT_QUITE_FALSE 0.2f
    #define COIN_FLIP 0.5f
    #define MAYBE_TRUE 0.6f
    #define PROBABLY_TRUE 0.7f
    #define ALMOST_CERTAINLY_TRUE 0.8f
    #define TRUE 1.0f

  • (cs)

    All the above posts are all TWO_TRUE.

  • Paul (unregistered)

    A friend put together an application that, at one point, asked the user:

    Delete the User: J Smith

    [Yes]  [No]  [Maybe]

    .... gotta love programmers with a sense of humour

  • (cs) in reply to Paul
    Anonymous:
    A friend put together an application that, at one point, asked the user:

    Delete the User: J Smith

    [Yes]  [No]  [Maybe]

    .... gotta love programmers with a sense of humour


    Delete the User: J Smith

    [Yes] [No] [Who?]
  • (cs) in reply to Paul

    What did the [Maybe] button do?  A true Maybe button would use a random number generator and work 50% of the time.

  • (cs) in reply to sinistral
    sinistral:
    What did the [Maybe] button do?


    Pops up another dialog:

    Are you sure?
    [ Yes ] [ No ]
  • (cs)

    A similar but different problem I always hate in a lot of languages is just deciding whether something will be true or false.

    For example, in Perl, you so often see just "if ($foo)" to check if the variable is defined and not null.  The same thing happens in a lot of languages, but these vague statements can have bad effects, like when 0 or the emptry string becomes a valid value for $foo.  When there is a built-in defined() function (same thing in PHP...isset() built-in) or when you could just check != null), I amaze even myself when I do the same thing of just putting "if ($foo)".  I only change it when it comes back to bite me.

    FWIW, please let the language war begin just because I mentioned the two P languages...we all already know that it wouldn't be a problem with a stricter-typed language and therefore all scripting languages suck...and we all already know that stricter-typed languages are cumbersome with too much typing and so all scripting languages rock.

    WTFever...and BTW someone tell this guy to get an enum.

  • AaronStJ (unregistered)

    You know, this really isn't that bad.  He just extended the functionality of the function without correctly refactoring like he should have.  It's more of a comment on how C works than how the coder works.  Just make "BOOL IsAdministrative" into "int AdministrativeCode", and use 0 and 1 instead of TRUE and FALSE (or better yet, make new named constants).  A select instead of ifs would be more efficient, but that's nitpicking.  Could be much worse.

  • One Leg (unregistered) in reply to AaronStJ

    In quantum computing you need a "Yes And No" button.

  • Poppa Chubby (unregistered) in reply to loneprogrammer
    loneprogrammer:

    #define TRUE_TWO 2

    Shouldn't that be...
    #define TRUE_TOO  2
  • (cs)

    I love the smell of a Saturday, 0344 hack in the morning.
    It smells like...victorEEEEEeeeeeeeeeeeeeee!

  • Sean Connery (unregistered)
    Alex Papadimoulis:

    What happens when you want IsConnected() to return the string "I'll tell you, but it'll cost you a buck". 



    Use boost::tribool. The biggest WTF i've ever seen. I mean, why not just use enumerations.
  • (cs)

    In its simplest form this is a WTF, but if we dig a little deeper we will find that it was a simple copy/paste error where the programmer simply copied the wrong parameter from the function.

    observe the function declaration

    BOOL AcceptAdjustment( int AccountNumber, int AdjustmentCode, char* Comments, BOOL  IsAdministrative )

    Then, since the programmer did a nice job of commenting their code

     // check if adjustment should be applied to aggregates as well
    if ( IsAdministrative == 2 )
    {
    // ...
    }

    What they really meant was
    if ( AdjustmentCode == 2 )

    I think we can conclude that they simply used the wrong variable. So let's cut them some slack.
    They didn't really fail, they just had "deferred success"
    Haven't we all done this at least once in our coder careers?

  • (cs) in reply to richleick
    richleick:
    In its simplest form this is a WTF, but if we dig a little deeper we will find that it was a simple copy/paste error where the programmer simply copied the wrong parameter from the function.

    observe the function declaration
    BOOL AcceptAdjustment( int AccountNumber, int AdjustmentCode, char* Comments, BOOL  IsAdministrative )

    Then, since the programmer did a nice job of commenting their code

     // check if adjustment should be applied to aggregates as well
    if ( IsAdministrative == 2 )
    {
    // ...
    }

    What they really meant was
    if ( AdjustmentCode == 2 )

    I think we can conclude that they simply used the wrong variable. So let's cut them some slack.
    They didn't really fail, they just had "deferred success"
    Haven't we all done this at least once in our coder careers?

     

    ooh -- great point!  I think you are correct -- this is not a WTF, but rather a typo or a honest mistake in writing the code.  And, to be honest, it is well-commented and that helps us determine what the true intent was. 

    So, I think we definitely cannot consider this a WTF but rather a simple coding error, and we should give some props to the coder for good comments which helps someone who is trying to debug the code quickly identify the mistake.

     

  • (cs) in reply to Jeff S
    Jeff S:
    richleick:
    In its simplest form this is a WTF, but if we dig a little deeper we will find that it was a simple copy/paste error where the programmer simply copied the wrong parameter from the function.

    observe the function declaration
    BOOL AcceptAdjustment( int AccountNumber, int AdjustmentCode, char* Comments, BOOL  IsAdministrative )

    Then, since the programmer did a nice job of commenting their code

     // check if adjustment should be applied to aggregates as well
    if ( IsAdministrative == 2 )
    {
    // ...
    }

    What they really meant was
    if ( AdjustmentCode == 2 )

    I think we can conclude that they simply used the wrong variable. So let's cut them some slack.
    They didn't really fail, they just had "deferred success"
    Haven't we all done this at least once in our coder careers?

     

    ooh -- great point!  I think you are correct -- this is not a WTF, but rather a typo or a honest mistake in writing the code.  And, to be honest, it is well-commented and that helps us determine what the true intent was. 

    So, I think we definitely cannot consider this a WTF but rather a simple coding error, and we should give some props to the coder for good comments which helps someone who is trying to debug the code quickly identify the mistake.

     

    Sorry guys, that was my oversight. The original submission had nothing to do with accounts, adustments, etc. Everything to do, however, with a TRUE/FALSE/2 boolean tho ...

    But good find none the less.

  • (cs) in reply to Jeff S

    Even if it is a cut'n'paste the wrong variable error, they're still using TRUE, FALSE and 2.  maybe not a major WTF, but still very odd...

  • (cs) in reply to Jeff S
    Jeff S:
    ooh -- great point!  I think you are correct -- this is not a WTF, but rather a typo or a honest mistake in writing the code.

    You're right!  Not only was it an honest mistake, it was some of the most clever code I have seen in a long time.

  • (cs) in reply to Sean Connery
    Anonymous:

    Use boost::tribool. The biggest WTF i've ever seen. I mean, why not just use enumerations.


    There's nothing WTFery about tribool. You just need to know when to use it. The indeterminate value could, for example, mean "impossible to determine". Situation would be a generic stream, and you ask it if the next read for 100 bytes will block. Problem is, the stream is in reality a decompression wrapper, so it has no clue how many bytes are really needed, and therefore whether the read will block.
    Or it could mean "partially true", because not everything is black and white. Just look at the checkboxes in Windows - checked, not checked, or grey-checked (e.g. because only a part of the subfeatures will get installed.

    Sure, you can misuse it - but you can misuse normal booleans as well.
  • OneFactor (unregistered) in reply to loneprogrammer

    Ah, the wonderful world of tri-state booleans.

    In Java, you can have a java.lang.Boolean whose values are Boolean.TRUE, boolean.FALSE, and of course good old null.

    In SQL, you can have a bit field of size one with values: 0, 1, and good old null.

    In C# I even saw a third-party class called defaultable boolean. It was an enum with three values: True, False, and Default. I think it was for gui controls that were supposed to inherit their state from their container.

    Kind of reminds me of those trilogies with four books in them. Or of Indiana Jones: "I said NO camels! Can't you count?"

  • (cs) in reply to OneFactor
    Anonymous:
    Kind of reminds me of those trilogies with four books in them.


    I prefer my book trilogies in 5 parts, thank you very much.


  • (cs) in reply to JThelen

    And you probably know where your towel is.

    JThelen:
    Anonymous:
    Kind of reminds me of those trilogies with four books in them.


    I prefer my book trilogies in 5 parts, thank you very much.


  • (cs) in reply to Rick
    Rick:
    And you probably know where your towel is.
    JThelen:
    Anonymous:
    Kind of reminds me of those trilogies with four books in them.


    I prefer my book trilogies in 5 parts, thank you very much.




    I have indeed been referred to as a 'Hoopy Frood'.
  • Fregas (unregistered) in reply to Ross Day

    Ross Day:
    A similar but different problem I always hate in a lot of languages is just deciding whether something will be true or false.

    For example, in Perl, you so often see just "if ($foo)" to check if the variable is defined and not null.  The same thing happens in a lot of languages, but these vague statements can have bad effects, like when 0 or the emptry string becomes a valid value for $foo.  When there is a built-in defined() function (same thing in PHP...isset() built-in) or when you could just check != null), I amaze even myself when I do the same thing of just putting "if ($foo)".  I only change it when it comes back to bite me.

    FWIW, please let the language war begin just because I mentioned the two P languages...we all already know that it wouldn't be a problem with a stricter-typed language and therefore all scripting languages suck...and we all already know that stricter-typed languages are cumbersome with too much typing and so all scripting languages rock.

    WTFever...and BTW someone tell this guy to get an enum.

    Ok. I'll bite.

    This is in fact a great example of the downsides to loosely typed scripting languages, because of the weird side-effects you mention.  I've had the same problems in VB, Javascript, VBScript and Coldfusion.  There are definite down-sides to strictly typed languages as well, but its usally easier to convey your exact intentions to the runtime in a strongly typed language.

    So when using a loosely typed lanuage, I discipline myself and DON'T do things like the above.  I treat the language as if its strongly typed unless i really need something flexible.  Heck, I hate how most of the strongly typed languages let you pass in null instead of a real object, rather than dictate if that's allowed in the method defiintion.

    Ding! Ding! Round 2...

  • Fregas (unregistered) in reply to OneFactor
    Anonymous:

    Ah, the wonderful world of tri-state booleans.

    In Java, you can have a java.lang.Boolean whose values are Boolean.TRUE, boolean.FALSE, and of course good old null.

    In SQL, you can have a bit field of size one with values: 0, 1, and good old null.

    In C# I even saw a third-party class called defaultable boolean. It was an enum with three values: True, False, and Default. I think it was for gui controls that were supposed to inherit their state from their container.

    Kind of reminds me of those trilogies with four books in them. Or of Indiana Jones: "I said NO camels! Can't you count?"

    Its amazing that this was the post today, and your response.  I JUST implemented an enumeration in C# that allowed True, False or "Not Applicable."  When saved to the sql server database, this comes out to a nullabel bit field (1, 0 or null.)

    Is that bad?  The business requirements had to allow some bit fields to remain null, or even revert back to null if they edited the record later.

  • Hank Miller (unregistered) in reply to JThelen

    Come to think of it, I don't think I've ever read a trilogy that had other than 5 book.   I've read several series with 3 novels, but they were not called trilogies by anyone I can determine.   I've read several trilogies that contain 5 novels.   (not just the obvious one)

    Unfortunatly I'm the type of guy who can never find his towel, hence I've been stuck on this backwater planet for years.

  • Anonymous (unregistered) in reply to Hank Miller

    And a bonus WTF for today:

      <FONT style="BACKGROUND-COLOR: #ffffff"><FONT color=#0000ff>bool</FONT> HasDst = (tzi.DaylightDate.wMonth == 0) ? <FONT color=#0000ff>false</FONT> : <FONT color=#0000ff>true</FONT>;</FONT>

    Taken from http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21497706.html.

  • (cs) in reply to Anonymous
    Anonymous:

      <font style="background-color: rgb(255, 255, 255);"><font color="#0000ff">bool</font> HasDst = (tzi.DaylightDate.wMonth == 0) ? <font color="#0000ff">false</font> : <font color="#0000ff">true</font>;</font>


    That is simply redundant, but not wrong.

  • Peter Brodersen (unregistered)

    "Ones and zeroes everywhere... and I thought I saw a two"

  • OneFactor (unregistered) in reply to Fregas
    Fregas:
    OneFactor:

    Ah, the wonderful world of tri-state booleans.

    In Java, you can have a java.lang.Boolean whose values are Boolean.TRUE, boolean.FALSE, and of course good old null.

    In SQL, you can have a bit field of size one with values: 0, 1, and good old null.

    In C# I even saw a third-party class called defaultable boolean. It was an enum with three values: True, False, and Default. I think it was for gui controls that were supposed to inherit their state from their container.

    Kind of reminds me of those trilogies with four books in them. Or of Indiana Jones: "I said NO camels! Can't you count?"

    Its amazing that this was the post today, and your response.  I JUST implemented an enumeration in C# that allowed True, False or "Not Applicable."  When saved to the sql server database, this comes out to a nullabel bit field (1, 0 or null.)

    Is that bad?  The business requirements had to allow some bit fields to remain null, or even revert back to null if they edited the record later.

    I think there are valid usages of tristates. nullable bit field and a triple enum make a lot of sense for this. It just seems odd that the world tries so hard and so often to push you into that direction. I guess it is just hard in practice to constrain a field to two values.

  • (cs) in reply to Peter Brodersen
    Anonymous:
    "Ones and zeroes everywhere... and I thought I saw a two"

    Don't worry, Bender.  There's no such thing as two.

  • (cs) in reply to CornedBee
    CornedBee:

    Or it could mean "partially true", because not everything is black and white. Just look at the checkboxes in Windows - checked, not checked, or grey-checked


    Actually I've seen at least five checkbox states.

    checked
    unchecked

    checked and disabled (that is, grey with a check)
    unchecked and disabled (that is, grey without a check)

    greyed out (that is, enabled but in a filled-with-grey state)

    The last is usually the "third state" of a tri-state checkbox.
  • Anonymous (unregistered) in reply to loneprogrammer
    loneprogrammer:
    Anonymous:

      <FONT style="BACKGROUND-COLOR: rgb(255,255,255)"><FONT color=#0000ff>bool</FONT> HasDst = (tzi.DaylightDate.wMonth == 0) ? <FONT color=#0000ff>false</FONT> : <FONT color=#0000ff>true</FONT>;</FONT>


    That is simply redundant, but not wrong.

    Would you truly suggest that this line of code should not have been written as,

    <FONT color=#0000ff>   bool</FONT> HasDst = tzi.DaylightDate.wMonth!=0;

    ?

    That aside, since when do WTFs have to do with right and wrong?  If the code compiles, does that make it right?  If redundancies are no longer WTFs, maybe we should have Alex remove the post at http://www.thedailywtf.com/forums/32119/ShowPost.aspx, and a few others.

  • (cs) in reply to Anonymous
    Anonymous:
    Would you truly suggest that this line of code should not have been written as

    bool HasDst = tzi.DaylightDate.wMonth!=0;

    I'm not making a statement for or against that. Both ways do exactly the same thing and they are both one line of code. If that were the biggest "WTF" in my daily life, I would be happy.

    I would write it your way, but if someone told me it is more readable to use the "? true : false" method, I would not call the kode kops to have them taken away.

  • gcon (unregistered) in reply to OneFactor

    I know exactly which third party controls you are talking about...Infra...whatever you get the GIST. Regardless of whether tri-states are a WTF, the way they are implemented by this ISV is a WTF. In most circumstances, the enum for DefaultableBoolean is redeclared in every namespace, instead of being in some common namespace.

    For example, a control's property such as Namespace.Object1Namespace.Object1.Visible isn't just of type Namespace.DefaultableBoolean, it's of type Namespace.Object1Namespace.DefaultableBoolean. That way if you have Namespace.Object2Namespace.Object2.Visible, you need to use Namespace.Object2Namespace.DefaultableBoolean.

    Extreme WTFery with every control I have ever used w/ from vendor [but when you figure it all out (because there is no documentation) the controls look really pretty :P ].

  • Annonymous (unregistered) in reply to Maurits
    Maurits:
    CornedBee:

    Or it could mean "partially true", because not everything is black and white. Just look at the checkboxes in Windows - checked, not checked, or grey-checked


    Actually I've seen at least five checkbox states.

    checked
    unchecked

    checked and disabled (that is, grey with a check)
    unchecked and disabled (that is, grey without a check)

    greyed out (that is, enabled but in a filled-with-grey state)

    The last is usually the "third state" of a tri-state checkbox.


    Check/uncheck and enabled/disabled are two separate states, enabled/disabled belonging to the base "window" object and check/uncheck belonging to the checkbox object that is a child of window.

    Also the checkbox state is stored as an INT rather than a bool, thus allowing the tri-state check/uncheck/grey.
  • vhawk (unregistered) in reply to mizhi
    mizhi:
    Pesky booleans.  Just a special case of an enum.

    Could've been worse... he could've quantized the values between 0 and
    1 on a float.

    #define FALSE 0.0f
    #define ALMOST_FALSE 0.1f
    #define NOT_QUITE_FALSE 0.2f
    #define COIN_FLIP 0.5f
    #define MAYBE_TRUE 0.6f
    #define PROBABLY_TRUE 0.7f
    #define ALMOST_CERTAINLY_TRUE 0.8f
    #define TRUE 1.0f



    And don't forget

    #define A_DEFINITE_MAYBE 1.0f


  • (cs) in reply to vhawk

    At least with a tristate bool you can work around those pesky 'Assertion Failed' errors [;)]

    if (true)
       alert("Yes");
    else
       alert("No");
    otherwise
       alert("Dunno");

    Now that looks silly even to myself [:$]

    Drak

  • Phelyan Sanjoin (unregistered) in reply to Fregas

    Oh, don't get me started on Boolean objects in Java. How about this construct, then:

    try {
    if( testValue.equals( Boolean.TRUE ) ) {
    // something
    }
    else if( testValue.equals( Boolean.FALSE ) ) {
    // something else
    }
    }
    catch( NullPointerException npe ) {
    // something completely different
    }

    Doesn't that bring a tear to the eye? Fortunately I was able to stop the programmer in time.

  • (cs) in reply to Ross Day
    Ross Day:
    For example, in Perl, you so often see just if ($foo) to check if the variable is defined and not null.  The same thing happens in a lot of languages, but these vague statements can have bad effects, like when 0 or the emptry string becomes a valid value for $foo.  When there is a built-in defined() function (same thing in PHP...isset() built-in) or when you could just check != null), I amaze even myself when I do the same thing of just putting if ($foo). I only change it when it comes back to bite me.

    I consider overuse of defined and co to be a WTF. If you really mean to check whether a string contains anything, then yes, ( defined $str and length $str ) is the right conditional. But if $foo is a metasyntactic placeholder for $somebool in your example, then absolutely if( $somebool ) is the exact right thing to do.

    Perl has a slightly peculiar, but very clear definition of truth: in scalar context, anything is true other than undef, the empty string, a numeric zero, or a string consisting of single 0 character. Checking for only one of these things specifically is bound to eventually get you in trouble with other people’s code. Particularly because in list context, anything other than the empty list is true.

    A big WTF in Perl is saying return 0; to return a generic false. In context, that’s a list with a single element and actually means “true”. The right thing to do is to simply say return;, which will give the caller an undef in scalar context and an empty list in list context – both correctly false. You should only return 0; if you actually want to return a numeric zero.

    The funny thing about Perl is that generally, the less work you do, the more correct and general your code is. Unfortunately, many people insist on using it like an awkward, strongly typed language instead of an expressive, weakly typed language, thereby playing to its weakness instead of its strength.

  • (cs) in reply to Aristotle Pagaltzis
    Aristotle Pagaltzis:
    A big WTF in Perl is saying return 0; to return a generic false. In context, that’s a list with a single element and actually means “true”.

    That was meant to say “In context, that’s a list with a single element” – I wish we could actually edit our posts.

  • (cs) in reply to Aristotle Pagaltzis

    Err, “In list context, that’s a list with a single element,” goddammit.

  • (cs)

    I've seen this a lot actually, that's because a BOOL is an integer, not a real boolean.  Even the bool in MFC isn't a real bool.  I once searched a whole day why

    if(somebool == true){
      // code here
    }

    else{
      // code here
    }

    kept going in the else even when somebool in the quickwatch gave true.  Seemed that even the bool type could have a tri-state. [^o)]
    When I did

    if(somebool){
      // code here
    }

    else{
      // code here
    }

  • Justin (unregistered) in reply to AaronStJ
    Anonymous:
    You know, this really isn't that bad.  He just extended the functionality of the function without correctly refactoring like he should have.  It's more of a comment on how C works than how the coder works.  Just make "BOOL IsAdministrative" into "int AdministrativeCode", and use 0 and 1 instead of TRUE and FALSE (or better yet, make new named constants).  A select instead of ifs would be more efficient, but that's nitpicking.  Could be much worse.


    No, no, no, no, no! 

    This is a simple case of not understanding your own data relationships.  He does not have one datum here, he has two data which he has wrongly amalgamated into one, thus losing orthogonality.  Just because only threads for administrators will ever need to consider adding aggregates, he has treated them as a special type of administrator.

    The correct answer is a pair of booleans.  By all means stick them in a bitfield, but then write a proper set of functions by checking each bit value rather than by checking for equality against values.  In other words...
    If bit0 is the administrator flag, then bitwise-and with 1 and check for non-zero in whatever language you choose.
    If bit1 is the administrator flag, then bitwise-and with 2 and check for non-zero in whatever language you choose.

    Justin.
    Oracle and Java Guru who really should get a login here.
  • (cs) in reply to Hank Miller
    Anonymous:
    Come to think of it, I don't think I've ever read a trilogy that had other than 5 book.   I've read several series with 3 novels, but they were not called trilogies by anyone I can determine.   I've read several trilogies that contain 5 novels.   (not just the obvious one)

    Unfortunatly I'm the type of guy who can never find his towel, hence I've been stuck on this backwater planet for years.

    Every hack fantasy series is either a trilogy or a double trilogy. (Trilogy of trilogies are reserved for the esteemed L. Ron.) It's book publishers' weapon against good writing: drown a little quality in a lot of quantity and hope people keep paying for it.

    I was really disappointed that this code did not end with isAdministrative == YELLOW. I'd have paid good money to see a code snippet like that. (If it walks like a wtf and quacks like a wtf... maybe it's a TRUE2.)

    I guess you could define true as GREEN and false as RED if you wanted to put it in a framework that made a goofy sort of sense... but wouldn't it be so much more surreal to spot a YELLOW out of nowhere in a couple of source files with no comment and no obvious definition? HELL YES.

    Alex, your title has finally inspired me to create code that will have my corporate descendants upping their medication levels. Score!
  • (cs) in reply to Rank Amateur
    Rank Amateur:

    What a dork. He's supposed to use bitfields. What happens tomorrow when they need to cover the case of applying the adjustment to only aggregates?

    Doesn't he know what BOOL means? Bitfield Object Operating as Long.

    --Rank

    What?

    You do know he's supposed to use XML, throw in some Javascript and then, using an XSLT needs to validate it with some Instr, Left$, Right$ and Mid$ don't you? Tsssssk, developers these days... always looking for an easy way out.

Leave a comment on “True, False, or Yellow”

Log In or post as a guest

Replying to comment #:

« Return to Article