• yafake (unregistered)

    I still don't get... the only WTF here is a Refactoring tool going mad.

    You know:

    private int foo; public Object bar;

    -> add getters and setters for all field

    public int getFoo() { return foo; }

    public int setFoo(int newvalue) { int tmp = foo; foo = newvalue; return tmp; }

    etc.

    Now, you can imagine, it might have seen the true-literal somewhere, thought it was a variable, and added a getter function.

  • ben (unregistered)
    JOHN: The REAL WTF is stereotyping goths as "fat weirdos who worship satan".

    Yes, "pathetic humorless whiners" would have been more accurate.

  • (cs) in reply to ben
    ben:
    JOHN: The REAL WTF is stereotyping goths as "fat weirdos who worship satan".

    Yes, "pathetic humorless whiners" would have been more accurate.

    I'm into goth stuff, but I skimmed right over the comment.

    Frankly, I have more important things to get upset and worked up about. I've found that life is far less stressful if I don't give a damn about occasional flippant comments that have no bearing on my life.

    -- Seejay

    (PS: I'm not a pathetic humourless whiner either, thankfully!)

  • Sgt. Preston (unregistered) in reply to Not First
    Not First:
    yeah, but how are you supposed to test it? This is much better.

    private static bool GetTrue() { IoCContainer myContainer = Configuration.GetContainer(); Object oFact = myContainer.GetObject("IFactFactory"); IFactFactory fact = (IFactFactory) oFact; Object oConfig = myContainer.GetObject("IFactConfiguration"); IFactConfiguration config = (IFactConfiguration) oConfig; IFactResolver resolver = fact.CreateFactResolver(config); return resolver.GetBooleanResultProvider().GetTrue(); }

    Kudos, Not First, this is hysterical! It's exactly the kind of factory pattern over-engineering that makes maintenance a nightmare.
  • Sharkie (unregistered)

    It's important to wrapper such things as, given the way the industry is going, the value or method of deciding TRUE may change in the near future.

    Also, what if the "suits" someday wish all truths to instead be declared as falsities.. but only on Wednesdays? Instead of having to hunt down all 20,000 conditions of TRUE, you simply maintain the singular function with something like: if ( strcmp(today, "WED") ) { return false; } else { return true; }

    With executives pushing harsher business requirements, and IT people bending to these new requirements near-daily, as well as the amount of outsourcing overseas occurring, it's important such forward thinking methodologies be employed in our everyday code.

  • An apprentice (unregistered) in reply to yafake
    yafake:
    I still don't get... the only WTF here is a Refactoring tool going mad.

    You know:

    private int foo; public Object bar;

    -> add getters and setters for all field

    public int getFoo() { return foo; }

    public int setFoo(int newvalue) { int tmp = foo; foo = newvalue; return tmp; }

    etc.

    Now, you can imagine, it might have seen the true-literal somewhere, thought it was a variable, and added a getter function.

    So you think there is a SetTrue function somewhere?

    private static bool SetTrue(bool NewValue) {
       true = NewValue;
    }
  • dolo54 (unregistered) in reply to JOHN
    JOHN:
    The REAL WTF is stereotyping goths as "fat weirdos who worship satan".

    "TheDailyWTF" is too offensive because of the "F", but it's just fine to stereotype?

    WorseThanFailure = worse than failure.

    I know cause there's skinny one's too!

    captchya: "burned" - yes you are!

  • Sgt. Preston (unregistered) in reply to Sharkie
    Sharkie:
    It's important to wrapper such things...
    Did you just verb that noun?
  • AZ Bmr (unregistered)

    For the record, Xenu is not Scientology's version of God (in fact, I've yet to meet a Scientologist that even believes that story). If the story is to be believed, Xenu would be the devil.

  • Dennis Ferron (unregistered)

    private static bool GetTrue() { throw new ExistentialismException(); }

  • (cs) in reply to josh
    josh:
    I'm surprised no one has suggested:
    bool GetTrue()
    {
      return GetTrue();
    }

    Better yet...

    private static bool GetTrue() {
      return !GetFalse();
    }
    private static bool GetFalse() {
      return !GetTrue();
    }
  • RON (unregistered)

    This isn't a WTF until we see the context it is used in.

    There are many times when you have a system that uses delegates or function pointers for customizable functionality.

    For example, imagine a job scheduler, that has a simple rule system about when it is allowed to run a job. C#:

    public delegate bool RunJobRuleDelegate();
    public class JobScheduler
    {
        RunJobRuleDelegate runJobRule;
        public RunJobRuleDelegate RunJobRule
        {
            get { return runJobRule; }
            set { runJobRule = value; }
        }
    
        public void ExecuteJobs()
        {
            bool runJob = false;
            if( runJobRule != null )
                runJob = runJobRule();
            if( runJob )
                // now run the jobs
        }
    
    
        public static bool GetTrue()
        {
            return true;
        }
    
        public static bool OnlyOnMondays()
        {
            return DateTime.Now.DayOfWeek == DayOfWeek.Monday
        }
    
    }
    
    
    

    Now later on, you can do this:

    JobScheduler mondays = new JobScheduler();
    mondays.RunJobRule = new RunJobRuleDelegate( JobScheduler.OnlyOnMondays );
    
    JobScheduler always = new JobScheduler();
    always.RunJobRule = new RunJobRuleDelegate( JobScheduler.GetTrue );
    

    This is a perfectly valid .NET 1.1 program and there really aren't many ways to do this better.

    However, if this were for .NET 2.0, I might have taken points off for not using anonymous delegates, depending on whether or not GetTrue was referenced only once or not. If GetTrue was a one-shot usage, then I would have used Anonymous delegates:

    JobScheduler always = new JobScheduler();
    always.RunJobRule = delegate() { return true; };
    

    However, if the "Always run" rule is used in multiple places, then I would go back to the GetTrue function (and make the name a bit more meaningful while I was at it).

    It's all about the contextamins.

  • PuckeL (unregistered)

    private static bool GetFalse() { return InvertBool(GetTrue()); }

  • (cs)

    Given just that code excerpt it does seem redundant. Given more context however, it might not seem ridiculous. What if the programmer is implementing an interface and the semantics of getTrue() is not always consistent? For that particular class it may be pertinent to always return true. But if another class has a different meaning/purpose, then getTrue() might be returning the truth in different context. I don't consider this a true WTF unless more context is given.

  • (cs)

    It's just a testing function. If you are testing another function and want to make sure you are testing the "true" path, you would substitute this function for the boolean test. That way you are only testing one function at a time.

    There are obviously better ways to do this (i.e. any other way).

  • mh (unregistered)

    The real WTF is that it might be in some weird namespace that mangles the standard definition of true, so it really should be:

    [code]private static bool GetTrue () { return (bool) !!true; }

  • (cs) in reply to Paul Evans
    Paul Evans:
    I suggest in fact, we need a complete interface, consisting of the following methods:

    private static bool getTruth();

    private static Set<bool> getWholeTruth();

    private static Set<bool> getNothingButTruth();

    You missed one:

    private static Set<bool> getTruthiness();

  • (cs) in reply to RON
    RON:
    This isn't a WTF until we see the context it is used in.

    There are many times when you have a system that uses delegates or function pointers for customizable functionality.

    Exactly.

    (Though this is dependent on the assumption that it is, in fact, C# and not Java, since Java doesn't have those. (At least as of my latest knowledge.))

  • brendan (unregistered)

    obviously this code was orginaly doing something else, but that feature got removed,

  • Zygo (unregistered) in reply to RON
    RON:
    This isn't a WTF until we see the context it is used in. There are many times when you have a system that uses delegates or function pointers for customizable functionality. For example

    The real WTF is that people write 50-line example code fragments to illustrate their point that getTrue() makes sense when its address is passed as the argument of a function...after several other people have written exactly the same statement, but used 25 words or less.

  • BillyBob (unregistered) in reply to seejay
    seejay:
    ben:
    JOHN: The REAL WTF is stereotyping goths as "fat weirdos who worship satan".

    Yes, "pathetic humorless whiners" would have been more accurate.

    I'm into goth stuff, but I skimmed right over the comment.

    Frankly, I have more important things to get upset and worked up about.

    Like whether The Cure or My Dying Bride is "more goth"

  • Jon (unregistered) in reply to EvanED
    EvanED:
    Because C# has delegates, there is actually plenty of room for a function such as this as a callback function, as many people have said.

    It might be a WTF, but it might not be.

    This might be where Common Lisp's "constantly" function comes in handy. In C# syntax:

    return constantly(true);

  • MedO (unregistered)

    You want enlightenment?

    root@linuxbox# apt-get install enlightenment_

    See? It's so simple.

  • Old Wolf (unregistered) in reply to Derrick Pallas
    Derrick Pallas:
    th0mas:
    static char* Dash_I = "-I";
    Whoever wrote that was likely passing those character constants to a function that didn't take const arguments because "const is too hard."
    Yeah there's about a 0% likelihood of that. There aren't any character constants in the above code. The "-I" things are string literals. In C these are arrays of non-const char. Const doesn't come into this at all.

    In C++, string literals are arrays of const char, but there is an implicit conversion to (char *), so even in that langauge you never would have const-problems with passing string literals to functions expecting char *.

  • Old Wolf (unregistered) in reply to mh
    mh:
    The real WTF is that it might be in some weird namespace that mangles the standard definition of true, so it really should be:

    [code]private static bool GetTrue () { return (bool) !!true; }

    Is this a joke? (If not, then I'm glad I'm not a java programmer!)

  • Jon (unregistered) in reply to Old Wolf
    Old Wolf:
    mh:
    The real WTF is that it might be in some weird namespace that mangles the standard definition of true, so it really should be:

    [code]private static bool GetTrue () { return (bool) !!true; }

    Is this a joke? (If not, then I'm glad I'm not a java programmer!)
    The code uses C# capitalisation conventions, and I'm pretty sure that Java calls its boolean type "boolean", so the code seems to be C#. Either way, you can't redefine true or false.

  • (cs)
    crazy celebrities in Xenu

    Are you trying to get sued?

  • yafake (unregistered) in reply to An apprentice
    An apprentice:
    So you think there is a SetTrue function somewhere?
    private static bool SetTrue(bool NewValue) {
       true = NewValue;
    }

    Yes and no.

    No, because there're two common cases: adding getters and setters, and just adding getters (and no setters).

    Yes, because the setter might have actually been created. Since it would break with a compile error, the mistake was found and corrected. However, since the getTrue() is valid, this second mistake was not noticed.

    BTW, I'm sure you forgot the return. Typical contracts of setter methods in Java are: don't return anything at all, return the old value. So your implicit "return false;" sure can't be intended.

  • (cs)

    Reminds me of a article about Null Object Refactoring.

    http://aspalliance.com/1258_Null_Object_Refactoring

    To make null checking easier, Fowler recommends adding an IsNull method, which the ReviewStatus class returns a static value of false. NullReviewStatus overrides the IsNull method and returns a value of true, noting that the object is null. This makes it easier to process whether or not the object is actually null.

    Listing 3

    //ReviewStatus Implementation public virtual bool IsNull() { return false; } //NullReviewStatus Implementation public override bool IsNull() { return true; }

  • Eugene (unregistered)

    As a fat goth satanist, I'm offended that I'm being stereotyped as a weirdo.

    As a fat satanist weirdo, I'm offended that I'm being stereotyped as a goth.

    And perhaps most of all, as a fat goth weirdo, I'm offended that I'm being stereotyped as a satanist!

  • ArraysRWhat (unregistered)

    bool GetTrue() { if (true != false) return !false; else return !true; }

  • jaavaaguru (unregistered)

    You can find enlightenment on Sourceforge:

    http://sourceforge.net/projects/enlightenment

    captcha: stinky - well, I've not had my morning shower yet

  • Arioch (unregistered) in reply to Sad
    Sad:
    Better yet: private static bool GetTrue() { return false; }

    I leave the third alternative an exercise to the reader.

    No, i disagree. Better something like

    private static bool GetTrue(in bool Value) { return Value > false; }

    PS: but what is it obviously WTF ? Couldn't it just be something like a stub argument to filter high-order-function (it is not since it does not taking arguments, but it could be something of a kind!) ?

    For example, let's take Delphi. Its objects' properties can be published (some early kind of reflection, allowing enumerating and changing at runtime, most use is to keep object values in external resource like window declaring resource in EXE, like database, etc). And each property can be marked if it should save it's value or it should not, when the object is serialised. You can do it, you can mark the property with true (do save), false (don't save) and same-object-boolean-method, that will yield true or false depending on the propertie value and the rest of object state. Remove from this scheme constants true anf false (for example for COM/CORBA functions-only interfaces) and clearly you immediately just NEED stub functions returning true and false!

    So what is the WTF in this ?

  • Arioch (unregistered) in reply to Sgt. Preston
    Sgt. Preston:
    Sharkie:
    It's important to wrapper such things...
    Did you just verb that noun?

    Sure he did not. The proper verb he would be "wrapperized"

    capthca:onomatopoeia - hope i will manage to key it in correctly...

  • slartibartfast (unregistered)

    With all the stereotypes you forgot one thing:

    REAL fat goth weirdos are not upset about being called "fat" or "weirdos" but being called "goth"!

  • Arioch (unregistered) in reply to Patrik
    Patrik:
    This makes perfect sense for use in a boolean returning callback function. GTK+ has gtk_true() and gtk_false() for exactly that usage, for example.
    Way to far. Every Unix has /bin/true and /bin/false programs, returning the proper (respecting their names) errorcode when run from batsh scripts :-) However they really are not private and can be used outside of /bin
  • woof (unregistered) in reply to Calli Arcale

    Its always such a pity when someone completely misses the wtf...sigh

  • (cs) in reply to JOHN
    JOHN:
    The REAL WTF is stereotyping goths as "fat weirdos who worship satan".

    "TheDailyWTF" is too offensive because of the "F", but it's just fine to stereotype?

    WorseThanFailure = worse than failure.

    I wish my lawn was an emo. Then it would cut itself!

  • Truer (unregistered) in reply to MyWillysWonka

    private static bool GetTrue() { //more true than true if (true == true){ return truer; } }

  • (cs) in reply to DigitalLogic
    DigitalLogic:
    I'd like to see a use case for this.

    I've wrote this exact same function a few weeks ago for testing purposes. I was testing a function that took a function pointer as an argument and wanted to test it against a function that always returned true.

    In effect its a mock function (as apposed to a mock object).

    Heh, now it's time for you to figure out which one of your coworkers submitted you to theDailyWTF :)

  • ChrisLively (unregistered) in reply to traininvain
    traininvain:
    There is actually a use for this. Visual Studio gives a warning about unreachable code, so if you try to comment out code with if (false) it will give a warning. Using if (!GetTrue()) doesn't get flagged.

    Honestly, if you are using this to comment out code, then you probably want the unreachable code detection.

    If you really want the code commented, then just highlight the whole section and do ctrl+k,ctrl+c to uncomment ctrl+k,ctrl+u.

  • Suppressive Thetan (unregistered)

    Actually, Xenu is the $cientologist's idea of Satan. But don't worry, they have him trapped behind a forcefield powered by an eternal battery or something. They find their truth in the writings of one L. Ron Hubbard, a True Nutbag if ever there was one.

    P.S. You can't defame the dead, so I can call LRH a lying, thieving, con artist, asshole Satanist disciple of Aliester Crowley as much as I want :P

  • Shaft (unregistered) in reply to th0mas

    My favorite is this little gem from some code I am working on:

    #define ELEVEN 11

  • (cs) in reply to Stephen Sweeney
    Stephen Sweeney:
    Sad:
    Better yet:

    private static bool GetTrue() { return false; }

    I leave the third alternative an exercise to the reader.

    // // You can't handle the truth :) // private static bool GetTrue() { System.exit(1); }

    i love you

  • (cs) in reply to BillyBob
    BillyBob:
    seejay:
    ben:
    JOHN: The REAL WTF is stereotyping goths as "fat weirdos who worship satan".

    Yes, "pathetic humorless whiners" would have been more accurate.

    I'm into goth stuff, but I skimmed right over the comment.

    Frankly, I have more important things to get upset and worked up about.

    Like whether The Cure or My Dying Bride is "more goth"

    Now that's fighting talk. My Dying Bride are a black metal band and The Cure are just an indie band with bad dress sense ;-)

  • (cs) in reply to Suppressive Thetan
    Suppressive Thetan:
    Actually, Xenu is the $cientologist's idea of Satan. But don't worry, they have him trapped behind a forcefield powered by an eternal battery or something. They find their truth in the writings of one L. Ron Hubbard, a True Nutbag if ever there was one.

    P.S. You can't defame the dead, so I can call LRH a lying, thieving, con artist, asshole Satanist disciple of Aliester Crowley as much as I want :P

    But it's not defamation if it's true.

  • (cs) in reply to kupal
    public static boolean GetTrue() { return '='=='='; }
    public static boolean GetTrue() { return (')'!='('); }
    public static boolean GetTrue() { return '='=='='==(')'!='('); }
    public static boolean GetTrue() { return '-'-'-'=='/'/'/'==(')'=='='); }
    

    and so on ...

  • Strainu (unregistered)

    Actually, some coding style guides do recommend using functions like that instead of using constants. I do fail to see the point of this when dealing with Bools, but...

  • Harald (unregistered)

    Ah, I see your problem. It should actually read

    private static bool getTrue() { return true; }

    P.S.: How come I could cut&paste the captcha into the text box?

  • ah (unregistered) in reply to Calli Arcale
    Calli Arcale:
    pi is a mathematical constant and therefore will never change

    Its anticipating another "Indiana PI Bill" perhaps?

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

Leave a comment on “Seeking the Truth”

Log In or post as a guest

Replying to comment #:

« Return to Article