• dmu (unregistered)

    public class types { public enum bool {

       TRUE, FALSE, UNDEF, SIM
    

    } }

    Almost like nullable bool in C#

  • Java? (unregistered)

    Java??? with colons for types and "function" keywords??

    TRWTF: faking code?

  • (cs)

    That's not Java.

  • Warren (unregistered)

    For anyone struggling with the Javascript === operator, it seems to mean "the same and of the same type". Any time it's true, a == test will be too.

    Apparently it's a faster test. But not if it's performed only where a == one returns false, I'm guessing....

  • fanguad (unregistered)

    That second example isn't Java.

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered)
    public class types {   public enum bool   {       TRUE, FALSE, UNDEF, SIM, FILE_NOT_FOUND   } }
    Fixed.
  • ab (unregistered)

    But how can you really check if the result of the isTrue() function is really true?

    Oh, I get it!

    if (BooleanUtilities.isTrue(BooleanUtilities.isTrue($val))) ...

  • (cs)

    Ah, the age old problem...

    "Pilate saith unto him, What is truth? And when he had said this, he went out again unto the Jews, and saith unto them, I find in him no file at all."

  • Honnza (unregistered)

    The second example looks like TypeScript. Not many languages have colon-delimited types.

  • (cs)
    Each time this program calls new BooleanUtilities().isTrue(val) a baby lemur cries.

    That is not true. David Attenborough would have told us.

  • (cs) in reply to renewest
    Each time this program calls new BooleanUtilities().isTrue(val) a baby lemur cries.

    That is not true. David Attenborough would have told us.

    TRWTF is the delete button right here !

  • BBCode Okay (unregistered)

    The "java" code is actionscript

  • David (unregistered)

    That other example isn't Java... its Adobe ActionScript.

    It follows this format

    variable:DataType

    function funcName(arg1:DataType, argN:DataType):returnDataType{ //contents... }

  • Herwig (unregistered)

    This was my favorite:

    #define true 0

    ...the original author works now as chief developer for an Austrian company which codes software for medical healthcare...

  • (cs) in reply to Herwig
    Herwig:
    This was my favorite:
    #define true 0
    ...the original author works now as chief developer for an Austrian company which codes software for medical healthcare...
    I'm sure that the principal reason was that no-one would ever be able to use C's standard truthiness. You would just have to write if (b == true), or else your code would fail, thus making the programmer pay more attention and resulting in better code. Really, I don't see the WTF.
  • C-Derb (unregistered) in reply to Warren
    Warren:
    For anyone struggling with the Javascript === operator, it seems to mean "the same and of the same type". Any time it's true, a == test will be too.

    Apparently it's a faster test. But not if it's performed only where a == one returns false, I'm guessing....

    It's just a prototype. Once they get the production version up and running, I'm sure they'll switch the order and do === first.

  • Decius (unregistered)

    In before FILE_NOT_FOUND = FALSE

  • (cs) in reply to Warren
    Warren:
    For anyone struggling with the Javascript === operator, it seems to mean "the same and of the same type". Any time it's true, a == test will be too.

    Apparently it's a faster test. But not if it's performed only where a == one returns false, I'm guessing....

    The difference is == allows for type conversions while determining equality. === does not. Speed isn't a main reason for using it, it's based on whether or not you want to allow a true result if both sides are different types but with the same content.

    Eg "0", 0, false, null, undefined are all ==, but not ===.

    This only applies to primatives, classes (like Arrays and Objects and so forth) are judged on equality by reference only so there's no difference between == and === in those cases.

  • DonaldK (unregistered)

    "Sim" is "Yes" in Portuguese.

    Pronounced, it sounds close to the word "sing" in English.

    All that said, it still doesn't make sense.

  • (cs)

    Functions of the form:

    public function isTrue(arg:Boolean):Boolean public function isFalse(arg:Boolean):Boolean

    do server a useful purpose - you can use them as functors, delegates, etc. a veritable slew of cases where one needs to be able to invoke (explicitly or under the covers).

    Now having the if statement inside is wonky, but it does provide a place to put a breakpoint.

  • Nappy (unregistered)

    This would make Yoda's head explode

  • firsttodye (unregistered)

    Not a programmer here; could someone please explain to me what the thought process may have been to create a true/false test for a true/false test? I thought that was the whole deal for boolean logic?

  • Swedish tard (unregistered)

    I've noticed a very common trait in developers not beinga ble to do boolean stuff... The most striking example I've found myself was a block of code with 3 variables that were checked in all manner of combinations through several ifs and && and ||, the result saved in a fourth variable that was then returned. I Was struck by how opaque the code looked when I was just passing by following a call herarchy, so I stopped and figured out what that whole mess actually produced... Which then made me replace the whole thing with return boolean1 == boolean2;

    But there are pretty much something strange with booleans every week when I'm digging around in code.

    Personally I think that being able to handle boolean logic should be a very lowest expectation of someone that is supposed to create software... No wonder every piece of software is crap and bug ridden, because if someone cant handle something as simple as booleans, how the fucking fuckety fuck are they supposed to deal with anything even remotely complex?

  • (cs)

    Just last week I found a tri-state boolean managed in our application database. If you put true as the value, the code does a check on some subsequent fields. Put false and it doesn't check, but it writes a log entry. Put null and it does nothing. It's mapped to a string property using NHibernate and the getter calls .ToUpper(). There will be blood.

  • golddog (unregistered) in reply to Swedish tard
    Swedish tard:
    I've noticed a very common trait in developers not beinga ble to do boolean stuff... The most striking example I've found myself was a block of code with 3 variables that were checked in all manner of combinations through several ifs and && and ||, the result saved in a fourth variable that was then returned. I Was struck by how opaque the code looked when I was just passing by following a call herarchy, so I stopped and figured out what that whole mess actually produced... Which then made me replace the whole thing with return boolean1 == boolean2;

    But there are pretty much something strange with booleans every week when I'm digging around in code.

    Personally I think that being able to handle boolean logic should be a very lowest expectation of someone that is supposed to create software... No wonder every piece of software is crap and bug ridden, because if someone cant handle something as simple as booleans, how the fucking fuckety fuck are they supposed to deal with anything even remotely complex?

    Pretty much the first thing I do when evaluating software (whether it's a code review sort of thing or third-party) is to try to look at the small things.

    Through many years in this industry, I've found that when people can't get the little things right, it's very unlikely they get the big things right.

  • Trevel (unregistered) in reply to firsttodye
    firsttodye:
    Not a programmer here; could someone please explain to me what the thought process may have been to create a true/false test for a true/false test? I thought that was the whole deal for boolean logic?

    I would assume the logic is that "if (X)" might be confusing to read where "if istrue(X)" isn't. I can read either with relative ease, but someone new to programming might find the latter helpful.

    A nullable bool might be useful when, to pick an example, processing a true/false set of questions. You will need to deal with the difference between True, False, and Did Not Answer The Question. Assuming a default of 'false' would skew the results.

    My personal favourite of these sorts is the classic

    if (x == false) {x = true};

  • Watson (unregistered) in reply to golddog
    Swedish tard:
    I've noticed a very common trait in developers not beinga ble to do boolean stuff... The most striking example I've found myself was a block of code with 3 variables that were checked in all manner of combinations through several ifs and && and ||, the result saved in a fourth variable that was then returned. I Was struck by how opaque the code looked when I was just passing by following a call herarchy, so I stopped and figured out what that whole mess actually produced... Which then made me replace the whole thing with return boolean1 == boolean2;

    In a similar vein, can anyone explain why

    (booleanExpression1 && booleanExpression2) || (!booleanExpression1 && !booleanExpression2)
    couldn't just be written as
    (booleanExpression1 == booleanExpression2)
    ? Because I see the former (and its disjunctive version) too often for it to be an accident.

  • Swedish tard (unregistered) in reply to Watson
    Watson:
    Swedish tard:
    I've noticed a very common trait in developers not beinga ble to do boolean stuff... The most striking example I've found myself was a block of code with 3 variables that were checked in all manner of combinations through several ifs and && and ||, the result saved in a fourth variable that was then returned. I Was struck by how opaque the code looked when I was just passing by following a call herarchy, so I stopped and figured out what that whole mess actually produced... Which then made me replace the whole thing with return boolean1 == boolean2;

    In a similar vein, can anyone explain why

    (booleanExpression1 && booleanExpression2) || (!booleanExpression1 && !booleanExpression2)
    couldn't just be written as
    (booleanExpression1 == booleanExpression2)
    ? Because I see the former (and its disjunctive version) too often for it to be an accident.

    Because booleans are too damn hard? XD I get those a lot too... And another common ugly boolean construction I see is:

    if(boolean == true) return true; else if(boolean == false) return false;

    ... So much fail.

  • sambista (unregistered)

    There's something missing:

    public class types
    {
       public enum bool
       {
           TRUE, FALSE, UNDEF, SIM, NÃO
       }
    }
    
  • Scott (unregistered) in reply to Watson

    It depends on whether or not booleanExpression* variables are boolean expressions. In perl, let's say $val1 is the number of files found in directory1, and $val2 is the number of files found in directory2

    We want to execute this code if both directories are empty,

    or if both directories have files, but not if only one

    directory has files.

    if ( ($val1 && $val2) || (!$val1 && ! $val2) ) { ... }

    In this case, $val1 might be 3, and $val2 might be 5. They're both boolean true, but they're not numerically equal.

  • (cs)

    I just took the submitter at face value and assumed one of the many changes in Java syntax had tried to make more convenient parameter passing or something.

  • (cs)
    Adam:
    shares this JavaScript helper function:
    Boolean.prototype.isTrue = function () {
      if (this == true) {
         return true;
      } else if (this === true) {
         return true;
      } else {
         return false;
      }
    }
    This isn't a WTF, in fact it's mandatory to be ISO 13485 / ISO 14971 compliant: Each decision that may affect a user or a patient has to be double checked.
  • Billy (unregistered)

    As Jesus said after healing the insane man, go forth and SIM no more.

  • (cs)

    I guess you can say that ActionScript is Java, in the same sense that JavaScript is. (ActionScript is based on ECMAScript, which JavaScript is an implementation of.)

    Now then again ActionScript isn't exactly server-side, unless there's a big WTF I don't know about. (To the best of my knowledge, it's only implemented in Flash and Air.)

    (Yeah, JavaScript is to Java as Car is to Whatever I've heard it a million times.)

  • (cs) in reply to MiffTheFox

    Unfortunately, there are server-side Flash technologies. Ugh, Flex.

  • Geoff (unregistered) in reply to Swedish tard

    if(boolean == true) return true; else if(boolean == false) return false;

    is prefectly reasonable to do in some languages. I am thing object basic dialects for example. Its actually one of the faster and more clear ways to normalize return codes, in cases where boolean is not actually of type bool but will evaluate to true or false in the expected way. But yes in C,C++,Java its WTF.

  • Earnest (unregistered)

    Programmers need to learn to ask themselves "Am I truly the first person on the planet to encounter this problem?" And if "this problem" is "determine the truthiness of a boolean" and you aren't the language's author, you might want to explore the possibility that something to do that is already built in.

  • bv (unregistered)

    Our units of temporal measurement, from seconds on up to months, are so complicated, asymmetrical and disjunctive so as to make coherent mental reckoning in time all but impossible. Indeed, had some tyrannical god contrived to enslave our minds to time, to make it all but impossible for us to escape subjection to sodden routines and unpleasant surprises, he could hardly have done better than handing down our present system. It is like a set of trapezoidal building blocks, with no vertical or horizontal surfaces, like a language in which the simplest thought demands ornate constructions, useless particles and lengthy circumlocutions. Unlike the more successful patterns of language and science, which enable us to face experience boldly or at least level-headedly, our system of temporal calculation silently and persistently encourages our terror of time. ...

    It is as though architects had to measure length in feet, width in meters and height in ells; as though basic instruction manuals demanded a knowledge of five different languages. It is no wonder then that we often look into our own immediate past or future, last Tuesday or a week from Sunday, with feelings of helpless confusion. ...

    — Robert Grudin, Time and the Art of Living.

    (Quoted in the GNU Coreutils info pages: https://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html )

  • (cs) in reply to Nappy
    Nappy:
    This would make Yoda's head explode
    FTFY: This Yoda's head would make explode.
  • Whining Pride (unregistered) in reply to Swedish tard
    Swedish tard:
    if someone cant handle something as simple as booleans, how the fucking fuckety fuck are they supposed to deal with anything even remotely complex?
    But, but... booleans aren't intuitive and I've been assured that I'm just as good as any computer user even though I'm too lazy to learn anything. Indeed, I've seen several forums where my ignorance is praised and encouraged! If the person doesn't understand the computer, it is always the computer's fault.
  • Jack (unregistered) in reply to Swedish tard
    Swedish tard:
    And another common ugly boolean construction I see is:

    if(boolean == true) return true; else if(boolean == false) return false;

    else universe.Reboot();

    FTFY

  • Larry (unregistered) in reply to Earnest
    Earnest:
    Programmers need to learn to ask themselves "Am I truly the first person on the planet to encounter this problem?" And if "this problem" is "determine the truthiness of a boolean" and you aren't the language's author, you might want to explore the possibility that something to do that is already built in.
    The problem is that if it is the obvious way to do something, somebody has already patented it. To stay out of legal trouble, you need to invent something strange enough to be unique. Then, of course, go patent that.

    If you're a programmer, you need two patent lawyers perched on your shoulder. One to look for existing patents on each line you write, and the other to patent anything the first one doesn't delete.

    (This comment patent pending. Go write your own.)

  • (cs) in reply to Larry

    Authors of dictionaries/thesauruses "poison" their work with fictitious words so that copies are easily spotted. This could be an equivalent behavior among coders :)

  • Captcha:suscipere (unregistered) in reply to Earnest
    Earnest:
    Programmers need to learn to ask themselves "Am I truly the first person on the planet to encounter this problem?" And if "this problem" is "determine the truthiness of a boolean" and you aren't the language's author, you might want to explore the possibility that something to do that is already built in.
    Unfortunately, if there is an immediate method to achieve, it must already have been patented. To avoid legal inconveniences, the recommended way is to create a method that's strange enough that nobody has used it before. Of course, immediately afterwards, you patent it.

    If you're programming, you need the supervision of two patent lawyers. One to check if your written code is patented, and the other to patent anything remaining from the first one.

    (Comment made in PRC)

  • (cs)

    More boolean weirdness... seen that once:

    boolean foo=Boolean.TRUE.booleanValue();

  • suis (unregistered) in reply to xenoid
    xenoid:
    boolean temp_bool=Boolean.TRUE.booleanValue(); boolean foo=(new BooleanUtilities().isFalse(temp_bool) == false);
    Enterprised that for you (now it handles the case when Boolean.TRUE.booleanValue() returns FILE_NOT_FOUND correctly).
  • Michael (unregistered)

    I would really like to start a competition on here to see who can make the LEAST efficient re-implementation of boolean logic. I'm sure we could get some intriguing entries.

  • Xavier (unregistered) in reply to Michael
    Michael:
    I would really like to start a competition on here to see who can make the LEAST efficient re-implementation of boolean logic. I'm sure we could get some intriguing entries.
    Easy. XML. It makes everything easy.
  • Darth Paul (unregistered) in reply to bv
    bv:
    Our units of temporal measurement, from seconds on up to months, are so complicated, asymmetrical and disjunctive so as to make coherent mental reckoning in time all but impossible... — Robert Grudin, Time and the Art of Living.

    (Quoted in the GNU Coreutils info pages: https://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html )

    One thing that is still missing from most implementations: catering for incomplete date times, which is necessary in real world systems.

    Often you have a date that is YM only (no D), or simply a Y (no MD). But how best to handle it when the programming language or database cannot (as incomplete dates must seamlessly query, calculate and sort correctly against complete dates)?

    Anything that is real world historical data will more often than not have this problem (date a photo was taken, date of birth are obvious examples). You can cludge it, but the cludge will always leave a gotcha in the data model.

  • F (unregistered) in reply to shinobu
    shinobu:
    Adam:
    shares this JavaScript helper function:
    Boolean.prototype.isTrue = function () {
      if (this == true) {
         return true;
      } else if (this === true) {
         return true;
      } else {
         return false;
      }
    }
    This isn't a WTF, in fact it's mandatory to be ISO 13485 / ISO 14971 compliant: Each decision that may affect a user or a patient has to be double checked.

    In which case it should be if (this == true) { return true; } else if (this === true) { return true; } else if (! this == true) { return false; } else { return false; }

Leave a comment on “Truth or Sim”

Log In or post as a guest

Replying to comment #:

« Return to Article