• (cs) in reply to JBL
    JBL:
    A paragon of maintainable, easy-to-understand code -- at least, until someone errs on a copy/paste and you get:

      psf Boolean X_TRUE = BASE_TRUE;
      psf Boolean X_FALSE = BASE_TRUE;

    That would be a fun little bug to track down. (Sadly, some ambitious IDE would probably give it away by displaying "Boolean.TRUE" when the debugging developer held the cursor over "X_FALSE.")


    No, the easy part is tracking it down to that mixup, that only takes a day or two. ;p The fun part is scanning and coming to grips with the entire codebase to try to ensure that it wasn't done that way on purpose, for fear of fixing it and generating new bugs. (In which case it would be easier to keep X_FALSE as true, and have a new X_FALSEFALSE (X_TRULYFALSE?) for false. Which is just going to make the migraine worse for the next maintainer. =DDD)
  • Eric (unregistered) in reply to ammoQ
    ammoQ:
    paid per LOC, i assume?

    The only additional lines are in the constants declaration, though.  By the KB?
  • Miles Archer (unregistered) in reply to Eric

    It's not really enterprise until it's nested more than three levels deep.

    Should really be:

    public static final Boolean ORG_HAS_CONTENT_TRUE = BASE_TRUE;
    <FONT size=+0>public static final Boolean</FONT> ORG_IS_NEW_TRUE = ORG_HAS_CONTENT_TRUE ;
    <FONT size=+0>public static final Boolean</FONT> ORG_ENABLED_TRUE = ORG_IS_NEW_TRUE ;

  • (cs)

    I can explain how this happened.

    The object in question works similar to another one in the system (implemented by said consultants) and it has a number of statuses that could be either on or off, just like this one.

    They were all stored in a bitmask field in the database, so the previous object had constants for all the bitmasks.

    When the new objects were created they were stored with booolean values in the DB, but the pattern of making a constant for every possible value of "ON" was carried through.

    Of course, why the data container dosn't have is....() methods to check the status bits is beyond me. The constants are defined in the data container and the business layer is doing the bitmask checks and boolean checks.

    I could probably keep the submission queue full all by myself with this project.

    Anybody want to see our 12,000 line classes that do nothing but transfer control to another layer? Hundreds of functions that do nothing but return the value of another function with the same signature.

  • (cs)

    This approach fails to take into consideration "truthiness".  Sure, something can BE true or false, but what about things that FEEL true or false?

  • Konrad Zielinski (unregistered)
    isn't thi missing
     
    BASE_UNKNOWN
     
    EVT_VERIFY_TRANSACTION_UNKNOWN
     
    etc
     
     
    If you can't verify the transaction then if follows that you do not know 
    which of true and false is correct.
     
  • (cs) in reply to Rain Dog

    Anonymous:
    I've submitted something similar to this (the irrational use of constants) and was pointing it out to someone how retarded it was to have these constants like that and they actually defended the practice.

    If the constants were "OrgChartEnabled = TRUE" or "OrgChartDisabled = FALSE" that is one thing. But "OrgChartEnableTrue = TRUE" and "OrgChartEnabledFalse = FALSE" Thats just cruel and unusual punishement for the keyboard and the disk drive write head.

  • (cs) in reply to Eric
    Anonymous:
    ammoQ:
    paid per LOC, i assume?

    The only additional lines are in the constants declaration, though.  By the KB?


    One would hope the Library of Congress uses better standards than that.
  • Anonymous (unregistered)

    Another possible reason for this WTF: they are future-proofing the code against the change of the variable's type. So they can, for instance, change it from a boolean to a three-valued type.

    captcha: salad

  • (cs) in reply to jbuist
    jbuist:
    I can explain how this happened. The object in question works similar to another one in the system (implemented by said consultants) and it has a number of statuses that could be either on or off, just like this one. They were all stored in a bitmask field in the database, so the previous object had constants for all the bitmasks. When the new objects were created they were stored with booolean values in the DB, but the pattern of making a constant for every possible value of "ON" was carried through.


    I am afraid to find myself thinking that this sounds like actually a quite reasonable explanation.


    Carrying on the tradition is a bit of a WTF I'd say... but if it was just ported to Java I could see that happening.

  • I'm Brillant (unregistered) in reply to Brendan Kidwell
    Brendan Kidwell:
    Alex Papadimoulis:
    evtProvider.VerifyTransaction = Truth.EVT_VERIFY_TRANSACTION_TRUE;
    transOrg.HasContent = Truth.ORG_HAS_CONTENT_FALSE;

    Aren't properties/members/objects in Java supposed to be named with initial lowercase letters, while classes and the like are named with initial uppercase letters? (By convention, not compiler rule.) So if this was an attempt at making code somehow more "readable", it completely missed the basic rules of Java readability.


     

    Yeah but the guy who wrote this is obviously a tool and probably has his own ideas about "convention"...I can see him arguing... I don't need no stinking "convention" this makes it more obviuous they are constant. It looks to me like he was a C programmer who has it in his head that these are #defines...

  • (cs)

    You do realise the guy who wrote this cannot be trusted? After all, his definition of truth can change at any time...

    Wait, maybe he's a former lawyer?

  • Dustman (unregistered) in reply to Anonymous
    Anonymous:
    Another possible reason for this WTF: they are future-proofing the code against the change of the variable's type. So they can, for instance, change it from a boolean to a three-valued type.

    captcha: salad

    Ok, I've done that. But then why not use a type beneath the "constants" that could actually have more than two states? Unless they were, for instance, planning on racking up even more billable hours/LsOC by having to go back and make them all, oh say, Ints?
  • wally (unregistered) in reply to NAME_ENABLED_FALSE

    hi guys I googled the wtf blog andf mine is under yours hehehe:)

  • (cs) in reply to NAME_ENABLED_FALSE
    Anonymous:
    This is either fake or however wrote this code was bored and trying to look busy, or maybe they just smoke a lot of crack.


    No, yes, yes, and yes.
  • ac (unregistered)

    Perhaps they did it because

    result = SomeFunc( organisation, ORG_HAS_CONTENT_TRUE, EVT_ACTION_REQUIRED_TRUE  );

    can be understood without context, cf

    result = SomeFunc( organisation, true, false );


  • 57451 (unregistered) in reply to ac
    Anonymous:
    Perhaps they did it because

    result = SomeFunc( organisation, ORG_HAS_CONTENT_TRUE, EVT_ACTION_REQUIRED_TRUE  );

    can be understood without context, cf

    result = SomeFunc( organisation, true, false );




    boolean isWTFAndEnterprisey = true;
    result = enterpriseObject.doWTF(organisation, isWTFAndEnterprisey);
  • hobbes (unregistered) in reply to ac

    even if that were the case, it'd be better to explain that by using comments ;)

  • (cs) in reply to hobbes

    This is still not properly enterprisey in one way..

    It requires actual effort of some form to redefine TRUE and FALSE..

    Surely they'd have better having a truth.properties where they define TRUE and FALSE appropriately.
    That way, they could easily fix any Bizarro-world incompatability without having to change any .javas or .classes.

    True flexibility.

    darj

  • tragomaskhalos (unregistered) in reply to mattnaik
    Anonymous:

    I've submitted something similar to this (the irrational use of constants) and was pointing it out to someone how retarded it was to have these constants like that and they actually defended the practice.

    Im curious to hear the argument they gave

    Surely we've all seen the (in)famous
    #define NUMBER_ONE 1
    #define NUMBER_ZERO 0
    and their ilk, so that the programmer can say "look ma, no magic numbers"

     

  • Jacques Chirac (unregistered) in reply to Disgruntled DBA
    Disgruntled DBA:
    You want the Truth.java?!  You can't handle the Truth.java!


    No they can't !!
    That's why The Truth had to be spin-doctored with few layers of redirection :) makes it easier to swallow
  • (cs) in reply to jbuist
    jbuist:
    Anybody want to see our 12,000 line classes that do nothing but transfer control to another layer? Hundreds of functions that do nothing but return the value of another function with the same signature.

    oooh yeah I want to see that one.
  • (cs) in reply to jbuist
    jbuist:
    Anybody want to see our 12,000 line classes that do nothing but transfer control to another layer? Hundreds of functions that do nothing but return the value of another function with the same signature.

    I hope that these 12,000 lines were made by a generator, not written by hand. But then, considering the circumstances, my hope is very slight.
  • (cs) in reply to Gene Wirchenko
    Gene Wirchenko:
    JBL:
    A paragon of maintainable, easy-to-understand code -- at least, until someone errs on a copy/paste and you get:

      psf Boolean X_TRUE = BASE_TRUE;
      psf Boolean X_FALSE = BASE_TRUE;

    That would be a fun little bug to track down. (Sadly, some ambitious IDE would probably give it away by displaying "Boolean.TRUE" when the debugging developer held the cursor over "X_FALSE.")


    Who would look?  "Obviously", the value is false.  (Yes, I hope people would get suspicious, but sometimes, that just does not happen.)

    Sincerely,

    Gene Wirchenko

    I would, of course.  Then again... I actually use a debugger, instead of guessing.
  • (cs) in reply to Jackal von ÖRF
    Jackal von ÖRF:
    Pilate said to him: “What is Truth.BASE_TRUE?”
    And after saying this, he went out again to the management and said to them: “I find no fault in this code.”

    - John 18:38, Enterprise Version

    Cracking :)
  • (cs) in reply to jbuist
    jbuist:
    ...booolean...

    That's 3VL, right?
  • (cs) in reply to pinguis
    pinguis:
    THE_TRUTH is out there...

    But seriously, why do people keep re-inventing the wheel???


    You mean, it should've been declared "external"? :)

    Anyway, this isn't the reinvention of the wheel, this is the reinvention of wood.


  • Rhialto (unregistered)

    I actually had a coworker who wrote things like

    #define SOME_OPTION_FALSE   0
    #define SOME_OPTION_TRUE   1

    #if SOME_OPTION == SOME_OPTION_TRUE
    ...
    #endif

    (Oh, and why is it that unregistered people such as myself apparently cannot post or reply to the sidebar but can reply here?)

  • (cs) in reply to mattnaik
    Anonymous:

    I've submitted something similar to this (the irrational use of constants) and was pointing it out to someone how retarded it was to have these constants like that and they actually defended the practice.

    Im curious to hear the argument they gave



    They call this pattern "Defensive Programming". They say it never hurts to be wary and your code has to be fool-proof. Just like this one:

    if( foo == true ) {...}
    else if ( foo == false ) {...}
    else {...}

    They are not happy to be informed that this code will only be fool-proof after they've lost write permission to the sourcebase.

  • (cs)

    Even though physical punishment is forbidden in todays schools and universities I reckon there are teachers and professors who would beat the s?*t out of their students for doing something stupid like this!

  • Tyler (unregistered) in reply to ac
    Anonymous:
    Perhaps they did it because

    result = SomeFunc( organisation, ORG_HAS_CONTENT_TRUE, EVT_ACTION_REQUIRED_TRUE  );

    can be understood without context, cf

    result = SomeFunc( organisation, true, false );




    someFunc should have parameter names that reflect what  true and false mean.  if it's unclear when the method is invoked add a line of comment. if the function does anything complex then it should always be taking some similar true and false (if not the same true and false).  another thing I wonder is... maybe they have ebject with really bad instance variable names.  for instance:
    foo = ORG_HAS_CONTENT_FALSE;
    bar = EVT_ACTION_REQUIRED_TRUE;
    instead of the better
    orgHasContent = false;
    evtActionRequired = true;
  • (cs) in reply to Tyler
    Anonymous:
    Anonymous:
    Perhaps they did it because

    result = SomeFunc( organisation, ORG_HAS_CONTENT_TRUE, EVT_ACTION_REQUIRED_TRUE  );

    can be understood without context, cf

    result = SomeFunc( organisation, true, false );




    someFunc should have parameter names that reflect what  true and false mean.  if it's unclear when the method is invoked add a line of comment. if the function does anything complex then it should always be taking some similar true and false (if not the same true and false).  another thing I wonder is... maybe they have ebject with really bad instance variable names.  for instance:
    foo = ORG_HAS_CONTENT_FALSE;
    bar = EVT_ACTION_REQUIRED_TRUE;
    instead of the better
    orgHasContent = false;
    evtActionRequired = true;


    It would be even better if Java supported named parameters:

    ob.someFunc( organisation : organisation, hasContent : true, actionRequired : true );



  • TC (unregistered) in reply to biziclop

    Defensive programming is often a good practice. For example, some of real code I wrote:

                while (j >= i && v[j] >= pivot) { j--; }
                /* if we do (v[i] <= pivot) then the sort isn't stable /
                while (j >= i && v[i] < pivot) { i++; }
                /
    i == j is actually impossible */
    //            if (i == j) { throw new Error(); }
                if (i > j) { break; }

    Ignore the first comment. My code has a lot of "throw new Error()"  or "throw new AssertionError()" (like errx(2,"error in algorithm!") in C). Some of them even pass a message ("this should be reasonably unreachable").

    It's good because it means when there's an error in my judgement or a typo, it's far easier to tell where it is (it's either in the function, or something not checked in the arguments to the function).

    For a simple (a) and (!a), it's stupid, because it's more copy-and-pasting, which means more code to change when you change variable names/whatever, and so on, which means more likely to have bugs.

    I'm also guilty of if (true) throw new Error() (or "the following code should be unreachable unless my reasoning is wrong, but I don't want to comment it out because comments don't nest, and I don't want to delete it because it might be reachable" - the if (true) is so Java doesn't force me to delete/comment out).

    I could just "assert false", but then I'd need to turn assertions on, and there's no enable-assertions-globally setting.

    Yes, I'm a hacker, but I aim for some sort of readability ;)

    captcha = china

  • Vasil (unregistered) in reply to NAME_ENABLED_FALSE

    In Java the constants are always inlined by the compiler so at the end we may even throw out the Truth class (we shoud've done it in the beginning however :) ).

    Perhaps the developer was paid per kByte or something like that.
    Still it looks impressive - adding hundrets of constants to make the code look complex and mystic.

  • (cs) in reply to Vasil

    Perhaps the author had some crazy reason to facilitate distinct Boolean objects.  IdentityHashMap, synchronized, ==, System.identityHashCode or whatever.  With the specified approach, it's easy to redefine a particular constant as a unique object.  Or maybe he's just a jackass.  Personally, I don't even think that Java should provide primitive wrapper object constructors.

  • (cs) in reply to jbuist
    jbuist:

    They were all stored in a bitmask field in the database, so the previous object had constants for all the bitmasks.



    But even then, wouldn't all the *_FALSE values be zero?  Or did these even exist?

  • (cs) in reply to TC

    Dear community server: You suck. Please stop failing when I use Opera. P.S: I banged your mom. Twice.

    TC said:

    I could just "assert false", but then I'd need to turn assertions on, and there's no enable-assertions-globally setting.

    According to http://java.sun.com/j2se/1.5.0/docs/guide/language/assert.html, the -ea flag w/o arguments enables assertions globally. Assertions are disabled by default.

    YOU LOSE, TREBEK.

  • (cs) in reply to Jackal von ÖRF

    Jackal von ÖRF:
    Pilate said to him: “What is Truth.BASE_TRUE?”
    And after saying this, he went out again to the management and said to them: “I find no fault in this code.”

    - John 18:38, Enterprise Version

     

    genuine, I must pick up that translation!!

  • Kevin (unregistered) in reply to John Smallberries

    John Smallberries:
    DiamondDave:
    Ha!! What's with the BASE_TRUE and BASE_FALSE?

    Some sort of Boolean inheritance?

    WTF?

    If those values got flipped, then the file would have to be renamed to NonTruth.java

    I prefer Lies.java.

    "All your BASE_TRUE are belong to us."

     

    Congress.java?

  • (cs)
    eddieboston:
    jbuist:

    They were all stored in a bitmask field in the database, so the previous object had constants for all the bitmasks.



    But even then, wouldn't all the *_FALSE values be zero?  Or did these even exist?



    No, it was a bitmask, not a bitfield.  One "status" column that held an integer.


    OPERATION_1 = 1;

    OPERATION_2 = 2;

    OPERATION_3 = 4;

    OPERATION_4 = 8;

    OPERATION_5 = 16;

    ....

    OPERATION_25 = 1677216;


    You add 'em all up, and shove them into the DB in one field.  then your checks look like


    if (status_bits & OPERATION_25) {

        //do stuff

    }


    In the old there is no constant for it being false.


    Oh, and this isn't "legacy" code either -- it's all 2001ish or newer.

  • (cs) in reply to biziclop
    biziclop:

    It would be even better if Java supported named parameters:


    ob.someFunc( organisation : organisation, hasContent : true, actionRequired : true );


    It almost did.  Java is based on Objective C far more than it's based on C++.  But it had to have a somewhat C++--ish syntax to lure C++ programmers in, or it would have died an immediate death back in the 90s.
  • Anita Tinkle (unregistered) in reply to John Smallberries

    Was this code written by an (ex) Enron employee?  No?  Maybe TYCO?

    Gives me the heebie jeebies that corporate programmers are so confused by truth.

  • (cs) in reply to mrsticks1982
    [image] Jackal von ÖRF wrote:
    Pilate said to him: “What is Truth.BASE_TRUE?”
    And after saying this, he went out again to the management and said to them: “I find no fault in this code.”

    - John 18:38, Enterprise Version

     

    genuine, I must pick up that translation!!

    ---

    And for multipying a fish and two pieces of bread, they called Him a pirate, and crucified them.
    Lucas 15:29, RIAA Version

  • (cs) in reply to I'm Brillant
    Anonymous:
    Brendan Kidwell:
    Alex Papadimoulis:
    evtProvider.VerifyTransaction = Truth.EVT_VERIFY_TRANSACTION_TRUE;
    transOrg.HasContent = Truth.ORG_HAS_CONTENT_FALSE;

    Aren't properties/members/objects in Java supposed to be named with initial lowercase letters, while classes and the like are named with initial uppercase letters? (By convention, not compiler rule.) So if this was an attempt at making code somehow more "readable", it completely missed the basic rules of Java readability.


     

    Yeah but the guy who wrote this is obviously a tool and probably has his own ideas about "convention"...I can see him arguing... I don't need no stinking "convention" this makes it more obviuous they are constant. It looks to me like he was a C programmer who has it in his head that these are #defines...

    Not true. Sun's Java coding conventions recommend using all-upper-case words separated by underscores for contants.

    http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html

  • (cs) in reply to Luuvitonen

    The real WTF is that java does not provide Boolean.UNKNOWN.  And that is the Boolean.TRUTH.

  • Stranger (unregistered) in reply to JBL

    JBL:
    smbell:
    JBL:
    kipthegreat:

    PS- I know about autoboxing in Java 5.0, which I think would make "HasContent = false" work correctly...


    Or just:   ! HasContent


    That can actually be a pretty bad idea.  There are cases where you would want to be setting the value to false.  You don't know what the current state is, and code like the following is pretty stupid:


    if(HasContent){
      HasContent = false;
    }


    Concur. My bad, I've got my monitor set to a bad setting for dev purposes and the = looked wider than it is. Setting the value and testing it are two entirely different things (usually).

    Hmmm...if you wanted to set HasContent (a boolean) to false, wouldn't you just simply go:

    [code]HasContent = false;

    ...and not even bother with the check before that???

  • Stranger (unregistered) in reply to Stranger

    'k...nvm...just reread the whole thing - also didn't realize the initial poster was doing an assignment, not a check...doh!

  • Yksi pieni mieli (unregistered) in reply to kipthegreat
    kipthegreat:
    GoatCheez:
    roflmao... I'm surprised they didn't use an integer type so that they could also define BASE_TRUE_AND_FALSE and BASE_NEITHER_TRUE_NOR_FALSE. Any BASE_TRUE enterprise system would have done it that way!


    They could have gotten away with one more value using Booleans:

    public static final Boolean BASE_NEITHER_TRUE_NOR_FALSE = null;


    Or they could had just used Enums. Perhaps even a custom Java compiler that autoboxes this particular enum type to basic booleans - of course that would require the enum to have a getTrue() method, and the code would not compile on any other compiler, but that is a small price to pay for a true type-safe multi-value boolean replacement.
  • / (unregistered)

    GREATER POOP: Is Eris true?
    MALACLYPSE THE YOUNGER: Everything is true.
    GP: Even false things?
    M2: Even false things are true.
    GP: How can that be?
    M2: I don't know man, I didn't do it.

  • eric (unregistered)

    I'de suggest the following improvement:

    public class Truth {

        static Boolean trueValue;
        static Boolean falseValue;
       
        { if (Math.random() > 0.5) trueValue = true;
            else trueValue = false; }
       
        { if (Math.random() > 0.5) falseValue = true;
            else falseValue = false; }
       
        public static final Boolean BASE_TRUE = trueValue;
        public static final Boolean BASE_FALSE = falseValue;
        /* ... /
        public static final Boolean EVT_VERIFY_TRANSACTION_TRUE = BASE_TRUE;
        public static final Boolean EVT_VERIFY_TRANSACTION_FALSE = BASE_FALSE;
        public static final Boolean EVT_ACTION_REQUIRED_TRUE = BASE_TRUE;
        public static final Boolean EVT_ACTION_REQUIRED_FALSE = BASE_FALSE;
        public static final Boolean EVT_TRANS_SETUP_TRUE = BASE_TRUE;
        public static final Boolean EVT_TRANS_SETUP_FALSE = BASE_FALSE;
        /
    ... */
        public static final Boolean ORG_HAS_CONTENT_TRUE = BASE_TRUE;
        public static final Boolean ORG_HAS_CONTENT_FALSE = BASE_FALSE;
        public static final Boolean ORG_IS_NEW_TRUE = BASE_TRUE;
        public static final Boolean ORG_IS_NEW_FALSE = BASE_FALSE;
        public static final Boolean ORG_ENABLED_TRUE = BASE_TRUE;
        public static final Boolean ORG_ENABLED_FALSE = BASE_FALSE;
       
       
    }

Leave a comment on “It Depends on Your Definition of True”

Log In or post as a guest

Replying to comment #:

« Return to Article