• (disco)

    "management had removed cubicle walls (to "facilitate communication")"

    TRWTF

    TWTF from which all other WTFs flow.

  • (disco) in reply to JBert
    JBert:
    If that's correct, if admins have the userCanDownload boolean set to true and lazy evaluation rules are used, the whole statement should immediately evaluate to false for admins. If
    You probably meant short circuit evaluation? In either case, it wouldn't change the result of the evaluation, only the side effects (which there are none).
  • (disco)
    if(userCanDownload != true && file != null || userCanDownload != false)
    

    I... I just.... I can't even comprehend how someone produces this...

  • (disco)

    I think I can help with this: if(userCanDownload != true && file != null || userCanDownload != false) is the same as if( ( ! userCanDownload && file != null ) || userCanDownload) in English... if ( ( user not allowed to download and file is there ) or (OK to download) )

    Soooooooo.... If the user is NOT allowed to download, and the file is there, then the button is ON and they ARE allowed to download it.

    (And if they do have the authority to download the file, then it doesn't matter if a file is there or not, the download button is also shown.)

    .

    But what I really wanted to know was... Who put this crazy nonsense into the program?!?

  • (disco) in reply to TheCPUWizard
    TheCPUWizard:
    OK, there are minor WTF's with the semantics, and the logic is totally borked, but where is there a "tri-state-boolean"?

    The joke is that if we assume that the code make sense, then the boolean must be tri-state because otherwise testing it explicit for both true and false make no sense.

  • (disco) in reply to aliceif
    aliceif:
    In languages like JavaScript and Ruby, || works as follows:- If the left operand is truthy, return it.- Otherwise return the right operand.

    Shell script languages work similarly.

    (command1) || (command2) - if (command1) yields 0 (success), stop. Otherwise, execute (command2).

    (command1) && (command2) - if (command1) yields anything other than 0 (failure), stop. Otherwise, execute (command2).

    But it seems they don't have any precedence of && over ||. (I tried Linux bash and Windows cmd.exe)

  • (disco)
    if(userCanDownload != true && file != null || userCanDownload != false)
    {
    	EnableDownloadButton();
    }
    Else
    {
    	DisableDownloadButton();
    }
    Otherwise
    {
    	DisenhalfunableDownloadButton();
    }
    
  • (disco) in reply to Martin_Tilsted

    And of course, file == null is another way to say FILE_NOT_FOUND, so it's harkening back to the classic tri-state as well.

    I'm surprised nobody's found my hidden joke yet. I guess that means I win?

  • (disco)

    Word to the wise: Make a photocopy of page 53 of K&R, Table 2-1 and post it prominent place in your cubicle. It will serve you well. If you program in other languages, I am sure that they have similar tables.

  • (disco) in reply to herby

    It's not really a page long, but:

    Precedence    Operator
        5             *  /  %  <<  >>  &  &^
        4             +  -  |  ^
        3             ==  !=  <  <=  >  >=
        2             &&
        1             ||
    
    [image]
  • (disco)

    I just saw my reflection in my monitor while looking at this code. I saw myself making the WTF face from this site's logo. Now I can't stop laughing at it and myself.

  • (disco) in reply to Yamikuronue

    It wasn't a good joke, though.

  • (disco) in reply to aliceif

    Normally the preview of an article gives a clue whether it's worth reading or not. This one was:

    "Lindsay."

    It tells me nothing, almost like clickbait. I only read it to find WTF the WTF was about. So TRWTF is the article preview.

    (Shit. This was supposed to be a reply to the topic, not a comment.)

  • (disco) in reply to telemath
    telemath:
    > No, actually. A one-bit two's complement field holds two different values: 0 and -. (No, there is nothing missing between the - and the . I really mean it, although you could make a case that the two values are + and -, because there is only a sign bit...)

    That's one's complement. In one's complement, a byte ranges from -127 to +127, with the high bit storing the sign. A signed bit would range from -0 to +0. I honestly don't know why they still teach one's complement - processors stopped using it decades before I went to school decades ago.

    In two's complement, a byte ranges from -128 to +127. A signed bit would range from -1 to 0. (8 bits: -128 to +127, 7 bits: -64 to +63, 6 bits: -32 to +31, 5 bits: -16 to +15, 4 bits: -8 to 7, 3 bits: -4 to 3, 2 bits: -2 to 1, 1 bit: -1 to 0. One of my favorite bogus interview questions is "what's the range of a signed bit?" I throw it into conversations for fun, but I've never asked it in a serious interview, but one day.. one day...

    One's or two's complement doesn't matter. Even sign-and-magnitude has the same problem, when we talk about one-bit fields. A single bit cannot sensibly hold a signed value - there is room only for the sign bit. In one's complement, it can reasonably (up to a point) be said to hold +/-0, and the same can be said for sign-and-magnitude, but it isn't at all clear what we should say the magnitude of a two's complement one-bit signed field is, when the single bit is 1.

    Which brings us to an interesting question. Versions of C newer than C89 may have resolved this question, and if so, so much the better. What is the portable range of the member x in this struct?

    struct flaky
    {
      int x : 1;
    };

    And the answer is: [0,0] Why? (Hint: it has nothing to do with the question of one's versus two's versus s-and-m.)

    Re: One's complement architectures and their continued appearance in lectures on integer representations decades after decades after their disappearance. I was at university three decades ago, and yes, I used a one's complement machine at that time.

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

    And sign-and-magnitude is still worth studying, in the context of floating point representations, because that's what the mighty IEEE-754 uses for the mantissa. (IBM System/360 and successors use sign-and-magnitude as well, but hexadecimal rather than binary...)

  • (disco) in reply to Steve_The_Cynic
    Steve_The_Cynic:
    IBM System/360 and successors use sign-and-magnitude as well, but hexadecimal rather than binary...

    Since hexadecimal is just using 4 bits per hex digit, that's not strange at all. (I thought they used decimal, which is quite a bit stranger except when it comes to handling financial transactions…)

  • (disco) in reply to ben_lubar

    It is a bit larger than that. Personally I blow up the table to a full page, and it is visible from a distance. Something I need to accommodate my advancing age (SIGH).

  • (disco) in reply to dkf
    dkf:
    Since hexadecimal is just using 4 bits per hex digit, that's not strange at all. (I thought they used _decimal_, which is quite a bit stranger except when it comes to handling financial transactions…)
    It's strange because it is really, really a hexadecimal format. The base of the exponent is 16, not 2 (as in IEE-754). The exponent has less bits than the exponent in IEEE-754, but the maximum equivalent decimal exponent is twice as large.
  • (disco) in reply to telemath
    telemath:
    One of my favorite bogus interview questions is "what's the range of a signed bit?" I throw it into conversations for fun, but I've never asked it in a serious interview, but one day.. one day...
    My favored bogus question is on C++:
    Talk to me about ```delete this;```

    I have asked this one. It's good for getting to see if someone understands what goes on behind the scenes and what the issues are.

    (You could also, but not quite as valuably, ask why you should never throw exceptions in a C++ destructor...)

  • (disco) in reply to Planar

    You realise Wikipedia articles are worthless without citations? I think most of us will have seen wtfs in Wikipedia articles.

  • (disco) in reply to Bulb
    Bulb:
    It does, but not that way. ({0, 1}, 0, 1, ⊻, ∧) is a field just like ℤ or ℝ. But since ({0, 1}, 0, ∨) is not a group, only a monoid, and since all the two-operation algebras (ring, field) require group in the _first_ operation, ({0, 1}, 0, 1, ∨, ∧) is not any of them.
    1. You misattributed the quote.
    2. Pedantic dickweedery aside, || has additive flavor and && multiplicative, and (in most programming languages) it's reflected in their precedences. If you don't see that, you don't know the first thing about boolean algebras.
  • (disco) in reply to kupfernigk
    kupfernigk:
    You realise Wikipedia articles are worthless without citations? I think most of us will have seen wtfs in Wikipedia articles.

    They are far from worthless. You have to read them and understand them and then exercise your judgement, but that's true of every written word ever.

  • (disco) in reply to kupfernigk
    kupfernigk:
    You realise Wikipedia articles are worthless without citations?

    [Citation needed]

  • (disco) in reply to Dragnslcr
    Dragnslcr:
    And does that make me TRWTF?
    @trwtfbot @dragnslcr

    Filed Under: inb4 bots don't work on article topics

  • (disco) in reply to sloosecannon
    sloosecannon:
    bots don't work on article topics

    that.

  • (disco) in reply to aliceif
    aliceif:
    that.

    I'm aware. Just pretend @trwtfbot posted. Or don't if you don't like bots...

  • (disco) in reply to JBert

    Non-admins can download the file if it exists. Admins can download it whether it exists or not.

    Of course Admins can download any files that don't exist! Yesterday I downloaded a how-to book on tachyon propulsion systems.

  • (disco) in reply to DJSpudplucker
    DJSpudplucker:
    Of course Admins can download any files that don't exist!

    Hiere follows just the mandatory reminiscence of

    God, root, WTF is the difference?

    Edti: Maybe I could mention that Jabberwacky once answered this with

    The difference is love.

    Edti 2:

    DJSpudplucker:
    Yesterday I downloaded a how-to book on tachyon propulsion systems.
    Are you sure you willan donedn't download it tomorrow?

    Edti n+1:

    Planar:
    Pedantic dickweedery aside, || has additive flavor and && multiplicative, and (in most programming languages) it's reflected in their precedences. If you don't see that, you don't know the first thing about boolean algebras.

    But I've learned that Boolean algebras were symmetric (self-dual) under swapping truthiness and falsiness (or whatever you call them) and the operators that are used to be called && and || in programming.

    Edti n+2:

    Steve_The_Cynic:
    Talk to me about delete this;
    Where's the problem as long as you use it in the constructor?
  • (disco)

    If we're having tri-state booleans, which three states are we talking about? NY, NJ and Connecticut? Indiana, Illinois and Kentucky? California, Oregon and Nevada? According to Wikipedia, there are 62 of the silly things!

    http://en.wikipedia.org/wiki/Tri-state_area#Land

  • (disco) in reply to Steve_The_Cynic

    Which brings us to an interesting question. Versions of C newer than C89 may have resolved this question, and if so, so much the better. What is the portable range of the member x in this struct?

    struct flaky { int x : 1; }; And the answer is: [0,0] Why? (Hint: it has nothing to do with the question of one's versus two's versus s-and-m.)

    Have you tried it? Using your struct, I tried:

    Flaky flaky;
    
    int tester = 100;
    flaky.x = 0;
    tester *= flaky.x;
    printf("\nflaky.x = %i\n", flaky.x);
    printf("tester  = %i\n", tester);
    
    tester = 100;
    ++flaky.x;
    tester *= flaky.x;
    printf("\nflaky.x = %i\n", flaky.x);
    printf("tester  = %i\n", tester);
    

    Fun exercise. Thanks for the stimulating conversation.

  • (disco) in reply to dkf
    dkf:
    which three states are we talking about?

    Who says they're even states of the United States? India, Mexico, Brazil and probably other countries are also composed of subdivisions called "states" (or local-language equivalents, e.g., "estados").

  • (disco) in reply to antiquarian
    antiquarian:
    [Citation neededCITE YOUR SHIT]

    BRTFY

  • (disco) in reply to Arnold_Schwarzer
    Arnold_Schwarzer:
    && precedes || in all languages I know

    Hmm.

    1. True for Fortran (precedence: .NOT., .AND., .OR.) and Algol (precedence: not, and, or, implies, equivalent – a bit more complex) and their various siblings and offsprings.

    2. Not true for C and most of the modern languages introduced since the 1980s. These use "short circuit evaluation" rather than true Boolean algebra. Implementation: Evaluate from left to right. In case of or, return current left-hand value, if it evaluates to true, else proceed. In case of and, return current left-hand value, if it evaluates to false, else proceed. Return value of last element, if we have not returned earlier. (not always binds deeper.)

    Just because there is such a thing as Boolean algebra, it doesn't mean it's actually used by computer languages. Popular examples to the contrary: C, C++, JS, Perl, PHP, etc, etc, ... Most of the code actually run on a computer today doesn't adhere to it.

    [Edit:] It should be noted that with Fortran, Algol and the like the entire Boolean expression is always evaluated (no undefined states here), while in short-circuit evaluation the processing of the whole expression and all its terms is merely an edge-case (which actually allows for some kind of tristate logic as in undefined states in the parts that are not executed – these hidden tristate-like characteristics are also a major cause of failure). We may also note that in the original implementation of Fortran with arithmetic if being the only construct for branching, conditions were always of trinary logic (less than zero, zero, greater zero). True Boolean expressions – and Boolean algebra – were only introduced in Fortran IV.

  • (disco) in reply to noland
    noland:
    Not true for C and most of the modern languages introduced since the 1980s. These use "short circuit evaluation" rather than true Boolean algebra. Implementation: Evaluate from left to right. In case of or, return current left-hand value, if it evaluates to `true`, else proceed. In case of and, return current left-hand value, if it evaluates to `false`, else proceed. Return value of last element, if we have not returned earlier. (not always binds deeper.)

    Note that while many C-like languages return the actual left-hand or right-hand value (so you can do config['key'] || defaults['key'] in javascript) in C (or at least gcc) these operators always return 1 or 0.

  • (disco) in reply to PleegWat
    PleegWat:
    in C (or at least gcc) these operators always return 1 or 0.
    Someone should look up the ANSI standard for us ...
  • (disco) in reply to aliceif
    aliceif:
    Someone should look up the ANSI standard for us ...

    That sounds like work

  • (disco) in reply to aliceif
    aliceif:
    Someone should look up the ANSI standard for us ...

    http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf

    On page 89, in §6.5.14:

    6.5.14 Logical OR operator

    Syntax

    logical-OR-expression:      logical-AND-expression      logical-OR-expression || logical-AND-expression

    Constraints

    Each of the operands shall have scalar type.

    Semantics

    The || operator shall yield 1 if either of its operands compare unequal to 0; otherwise, it yields 0. The result has type int.

    Unlike the bitwise | operator, the || operator guarantees left-to-right evaluation; there is a sequence point after the evaluation of the first operand. If the first operand compares unequal to 0, the second operand is not evaluated.

    So yes, it's specified to return 0 or 1, and is pretty clear as these things go. (The && operator is similarly clear.)

  • (disco) in reply to telemath
    telemath:
    > Which brings us to an interesting question. Versions of C newer than C89 may have resolved this question, and if so, so much the better. What is the portable range of the member x in this struct?

    > struct flaky > { > int x : 1; > }; > And the answer is: [0,0] Why? (Hint: it has nothing to do with the question of one's versus two's versus s-and-m.)

    Have you tried it? Using your struct, I tried:

    > Flaky flaky;

    > int tester = 100; > flaky.x = 0; > tester *= flaky.x; > printf("\nflaky.x = %i\n", flaky.x); > printf("tester = %i\n", tester);

    > tester = 100; > ++flaky.x; > tester *= flaky.x; > printf("\nflaky.x = %i\n", flaky.x); > printf("tester = %i\n", tester);

    Fun exercise. Thanks for the stimulating conversation.

    So why is the ***portable*** range [0,0]? Any particular implementation will have an implementation-specific behaviour, but the question was "why is looking for / expecting any other value than 0 not portable?"

    A further hint: What is the type of int x:1?

  • (disco)

    By which, by the way, I mean "what is the fully-specified type, with no abbreviations allowed?"

    unsigned is an abbreviation of unsigned int, and short is an abbreviation for signed short int.

  • (disco) in reply to PWolff
    PWolff:
    Steve_The_Cynic:
    Talk to me about delete this;
    Where's the problem as long as you use it in the constructor?
    You'll have to explain why (1) it isn't a problem in the constructor and (2) it is a problem somewhere else.

    And whatever your explanation for (1), you're wrong. The constructor is just about the worst possible place to do it.

    And the salmon-coloured popup box can fuck the fucking fuck off.

  • (disco) in reply to Yamikuronue
    Yamikuronue:
    I'm surprised nobody's found my hidden joke yet. I guess that means I win?

    My sense of humour works at roughly a right angle to everyone else's. I have no way of knowing what's a joke, let alone what's hidden.

    I'm going to need your help to discover the secret joke.

    aliceif:
    It wasn't a good joke, though.

    Well now I really want to know. Help me stoke the fires of controversy.

  • (disco) in reply to Shoreline

    The only thing I noticed was an HTML comment (therefore hidden) that I guess was the "joke," but I didn't think was humorous ("Danger zone."). Huh? Maybe it's an allusion to something I don't get; otherwise, either Asher is in danger because Lindsay is now ticked-off, or looking at Asher's screen is dangerous to Lindsay. I guess?

  • (disco) in reply to HardwareGeek
    HardwareGeek:
    Maybe it's an allusion to something

    Yes

  • (disco) in reply to CoyneTheDup
    CoyneTheDup:
    numberone:
    Button availability is not so important, it's better to show button to everyone and fail due to permissions after clicking on it than allowing some hacker with a Web Development Console to download the file even with disabled button.

    Hear, hear!

    I think this is one of the most overlooked elements of web page security. Clients (browsers) are inherently insecure;

    I don't see how "measurably mediocre" security is that much of a step up from the naive sense of security an organization might get from relying upon browser security. In fact, it could be less secure when you have an unsophisticated user base (as might easily exist in this article) who wouldn't even think about fishing around for such information unless you actually smacked them on the head with it.

    If prices are such a sensitive issue, there shouldn't even be a pricelist button in the procurement site, let alone a button visible for one and all to see:

    • the vendor gains nothing from reminding its b2b customers to think about cost and alternatives
    • admins should be routed to a properly secured internal site to get the global pricelist
  • (disco) in reply to Crunger
    Crunger:
    unsophisticated user base (as might easily exist in this article) who wouldn't even think about fishing around for such information unless you actually smacked them on the head with it.

    I work at a healthcare organization which just suffered a data theft that affected tens of thousands of patient records--and that was carried out by a couple of those "unsophisticated users".

    Given sufficient nefarious motivation, some of those users can become startlingly sophisticated.

  • (disco) in reply to Steve_The_Cynic
    Steve_The_Cynic:
    So why is the ***portable*** range [0,0]? Any particular implementation will have an implementation-specific behaviour, but the question was "why is looking for / expecting any other value than 0 not portable?"

    A further hint: What is the type of int x:1?

    OK, as I read it, some time back, a bitfield of type ```int``` is of unspecified signedness, just like an undecorated ```char``` is. That is, the standard (C99 or later may have changed this) specifies that the implementation may make unspecified bitfields behave signed or unsigned, at its whim. So ```unsigned int x:1``` portably holds 0 or 1, and ```signed int x:1``` portably holds 0 or something else, normally either -0 or -1, but ```int x:1``` is (n)either of these, and can only portably hold the intersection of these ranges, that is, 0..0.
  • (disco) in reply to PleegWat

    You're right! Should have added some like, "Implementation details: Some languages (like C) will return normalized scalar values (1,0)."

  • (disco) in reply to aliceif

    Again, a bug caused by comparing booleans to constants with !=. Also, an unnecessarily complex expression.

    I imagine what is meant is

    if(file != null && userCanDownload) { 
      // the file is present, 
      // and they are allowed to see it, 
      // so show show the button
    }
    else {
      // the file is not present, 
      // or they don't have permission to see it
    }
    

    Anyone here want to tell me that adding an explicit comaprison to true would have any point whatever?

  • (disco) in reply to Paul_Murray

    Ideally, there'd be three states.

    1. User doesn't have permission to do this sort of download. No button present; no point in telling people about stuff that's none of their beeswax.
    2. User has permission, but there's no file. Button present but disabled.
    3. User has permission and the file's there. Button present and enabled.

    But that would be a sensible approach…

  • (disco) in reply to dkf

    now assign a label to each state:

    1. FALSE
    2. FILE_NOT_FOUND
    3. TRUE
  • (disco) in reply to Yamikuronue
    Yamikuronue:
    1. FALSE 2. FILE_NOT_FOUND 3. TRUE
    Wait… that actually makes sense… a TDWTF meme actually makes sense… \*splat* Excuse me a moment… \*gathers scattered pieces of brain to reassemble and reinstall*

Leave a comment on “Tri-State Boolean”

Log In or post as a guest

Replying to comment #:

« Return to Article