• (cs) in reply to neminem
    neminem:
    Matt Westwood:
    The real WTF is that you're expecting some luser somewhere to type in a response which requires one of two answers. WTF is wrong with a pair of fucking radio buttons?!?
    Since you asked, we're not expecting the user necessarily to type in anything. The goal is to fill in a checkbox in a pdf. The input is coming from a token, which might come from a script, or from a database, or (most likely) from the value of another checkbox in another pdf. The pdf specification *recommends* a certain value for a checkbox being toggled, but depressingly enough, it does not *require* a certain value. The user is not necessarily the person who created the pdf they're trying to read the value of. Hence, flexibility.

    Wups sorry, I should have been responding to the initial posting, not your response.

  • (cs) in reply to C-Octothorpe
    C-Octothorpe:
    Coyne:
    If the column contains Y/N, great; if it's blank, who knows how the programs will behave?
    Isn't that what the "else" block is for? :)

    Well, based on the above, seems to me the else would be as unpredictable as the IF. :)

  • Guru (unregistered)

    Wrong, ELSE will be much more predictable because you always know it's opposite to IF, thus decreasing entropy.

    Probability theory FTW

  • (cs) in reply to Coyne
    Coyne:
    C-Octothorpe:
    Coyne:
    If the column contains Y/N, great; if it's blank, who knows how the programs will behave?
    Isn't that what the "else" block is for? :)

    Well, based on the above, seems to me the else would be as unpredictable as the IF. :)

    Depends what you want the default behaviour to be for the particular database table. Usually when you have to specifically select a property to be enabled, then absence of that value would assume disabled to be the norm. The logic would go: "Does this database field contain a synonym for 'affirmative'?" Then that feature is enabled. If not, it's disabled." Can be effective if you want to do a staged upgrade.

    At your leisure you then go through and set that property for the (old) projects which do not have that feature enabled to "N". When all the projects have been so treated, you can then issue an upgrade to your system such that the default is now "Y", and then you ask the specific question: "Does this database field contain a synonym for 'negative'?" Then that feature is specifically disabled, and any new projects (which will have that new feature by default) do not need to have that property added.

    It was a technique that proved workable when we had a few hundred projects to provide a service for, many of which, on project initiation, required certain significant enhancements which then became selling points for future projects and were therefore included from then on as a matter of course.

  • H+A=T/E\R (unregistered) in reply to Matt Westwood
    Matt Pinnocio:
    Wall of meaningless text

    Go the fuck from here dumbass brithead

    Y/Yes

  • foo (unregistered) in reply to C-Octothorpe
    C-Octothorpe:
    Hater's mom: Godammit Melllvar! I told you to stop leaving your dirty underwear in the bathroom!

    Melllvar (aka Hater): Aw, come on mom, can't you see I'm busy?!

    FTFY

  • (cs) in reply to Sadly, I've Seen This
    Sadly:
    I see "Pueba que tu bebe es sana." on the PSA billboards here. I wonder why there are so many crazed Hispanic babies.
    Probably because they don't get the health care they need due to PSA's translators doing sub-par work.
  • Matt Westwood (unregistered) in reply to H+A=T/E\R
    H+A=T/E\R:
    Matt Pinnocio:
    Wall of meaningless text

    Go the fuck from here dumbass brithead

    Y/Yes

    I'm still here.

    You have failed at ousting a single user. Why don't you go back to fourchan or reddit or whatever?

  • H. (unregistered) in reply to Matt Westwood
    Matt Westwood:
    I'm still here.

    Worse to you dickhead.

    That's only beginning.

  • (cs) in reply to adam
    adam:
    you want the truth? you cant handle the truth

    Actually, We can handle the truth. We can also handle the Truth, and the TRUTH.

    We can't handle the tRuth, the trUth, the truTh, the trutH, the TRuth.....

  • David mecham (unregistered)

    Were they trying to protect industrial secrets. Our their own reputation? If this us the most valuable code you could find to steal I suspect the latter.

  • EmperorOfCanada (unregistered)

    I've imported data from optically scanned written forms that required far worse than this. How many people do you think would have a tild(~) in their names? I suspect that they would need to add other forms of truth like OK, nope, yeah, and whatnot.

  • (user name withheld) (unregistered) in reply to ParkinT
    ParkinT:
    This was obviously written by someone unfamiliar with the "ToLower()" class. What is returned if I supply it with "trUe"?

    Nono, we just haven't yet been shown the method that does the checking yet. That's where the toLower() "class" is found, and you will see that it handles the "trUe" case just fine:

    public bool getboolstringsetting( String boolstring ) {
        bool thesetting;
    
        thesetting = FileNotFound;
        for (StringSettingBool stringsettingbool : boolflag) {
            if (checkifthisisthestringsetting( boolstring, stringsettingbool[ 0 ].toLower() )) {
                thesetting = stringsettingbool[ 1 ];
            }
        }
    
        return thesetting;
    }
    
    private bool checkifthisisthestringsetting( String boolstring, String stringsetting, int stringposition ) {
        bool thisisthesetting;
    
        if (stringposition == stringsetting.length() - 1) {
            thisisthesetting = boolstring.equals( stringsetting );
        } else {
            thisisthesetting = checkifthisisthestringsetting( boolstring, stringsetting, stringposition + 1 );
            if (! thisisthesetting) {
                if (stringposition == 0) {
                    stringsetting = stringsetting.substr( 0, 1 ).toUpper() +
                                    stringsetting.substr( 1 );
                } else {
                    stringsetting = stringsetting.substr( 0, stringposition ) +
                                    stringsetting.substr( stringposition, stringposition + 1 ).toUpper() +
                                    stringsetting.substr( stringposition + 1 );
                }
                return checkifthisisthestringsetting( boolstring, stringsetting, stringposition + 1 );
            }
        }
    
        return thisisthesetting;
    }
  • Dyspeptic Curmudgeon (unregistered) in reply to Machtyn

    "nO, yEs, yeS, yES, YeS, YEs"..

    Copied from the sound track of a p()rn0 video...

  • (cs) in reply to Matt Westwood
    Matt Westwood:
    Coyne:
    C-Octothorpe:
    Coyne:
    If the column contains Y/N, great; if it's blank, who knows how the programs will behave?
    Isn't that what the "else" block is for? :)

    Well, based on the above, seems to me the else would be as unpredictable as the IF. :)

    Depends what you want the default behaviour to be for the particular database table. Usually when you have to specifically select a property to be enabled, then absence of that value would assume disabled to be the norm. The logic would go: "Does this database field contain a synonym for 'affirmative'?" Then that feature is enabled. If not, it's disabled." Can be effective if you want to do a staged upgrade.

    At your leisure you then go through and set that property for the (old) projects which do not have that feature enabled to "N". When all the projects have been so treated, you can then issue an upgrade to your system such that the default is now "Y", and then you ask the specific question: "Does this database field contain a synonym for 'negative'?" Then that feature is specifically disabled, and any new projects (which will have that new feature by default) do not need to have that property added.

    It was a technique that proved workable when we had a few hundred projects to provide a service for, many of which, on project initiation, required certain significant enhancements which then became selling points for future projects and were therefore included from then on as a matter of course.

    All quite sensible, yes; and we're doing that, sort of. Our approach is more along the lines of, "Ensure the database has an explicit value to begin with." That way, the contradictory assumptions don't matter.

    At the moment, it's easier that way because the number of places where a column is loaded/updated is usually far fewer than where the value is referenced.

    Fortunately, our environment doesn't leave us with multiple versions to support.

  • (cs) in reply to Matt Westwood
    Matt Westwood:
    H+A=T/E\R:
    Matt Pinnocio:
    Wall of meaningless text

    Go the fuck from here dumbass brithead

    Y/Yes

    I'm still here.

    You have failed at ousting a single user. Why don't you go back to fourchan or reddit or whatever?

    Matt Westwood (Unregistered) is not Matt Westwood. I was going to ignore the pillock from now on in the hope that he'd die of malnutrition. Just leave it, yeah?

  • (cs) in reply to H+A=T/E\R
    H+A=T/E\R:
    Matt Pinnocio:
    Wall of meaningless text

    Go the fuck from here dumbass brithead

    Y/Yes

    Actually no, this is like shooting fish in a barrel.

    It's meaningless to you because you're thick as pigshit.

  • Duane (unregistered) in reply to froggy evenings

    What's hilarious is that it's not even a dictionary. It's an array of what I can only guess are some sort of tuple. There are no lookups here, just iteration... :(

  • RedFox (unregistered)

    TRWTF is that nobody realised this is C++ code and that StringSettingBool is probably a struct.

    Either way, I think the following solution displays the superiority of C++ over petty languages like C# or Java in many ways. Albeit, it doesn't remove the fact that the "Truth Enough" snippet is a disgrace to any respectable C++ programmer.

    #include <string.h> // strchr, strlwr
    inline bool isTrue(const char* str)
    {
    	char temp[2] = { *str, 0 };
    	return strchr("1tyg", *strlwr(temp)) != NULL;
    }
    
  • (cs) in reply to Mcoder
    Mcoder:
    Ol Bob:
    A less-than-obvious WTF is that somewhere deep in the code-base from which this snippet was snipped there's a function (and we pray there's only ONE such function) that iterates its way through this array doing string comparison after string comparison in hopes of finding a match. <shudder>

    And so what? How fast can humans generate input?

    About sanity certificates... My current job required one from all applicants... No wonder everybody here is insane.

    It makes a nice conversation with a doctor "- I need a sanity certificate for a job" "-Ok", and signs the paper. Didn't have time to reach the chair.

    Plenty of jobs here require something similar, but comes from the town hall. It's a certificate of good behaviour and morals. It's absolutely ridiculous to "certify" someone for it, so they recently replaced it (yet still call it the same) with an extraction of your police records / crime records / whatever it's called in English.

  • gnasher729 (unregistered)
    1. It looks as if there is code that can determine exactly what inputs are accepted as meaning true or false, and which are not accepted. If that is what is intended, then the code is absolutely fine, maybe a bit short of documentation, and the WTF is our informant not knowing the spec for the function and making ASS umptions. It looks quite sensible that "yEs" should not be an acceptable input. At the moment I could implement this easily with a bit of code, but the method used is simple enough, and easily adapted to requirement changes.

    2. The informant should be fired immediately. If his employer is security conscious, that's not for him to judge. It is for him to accept it, or to look for a job elsewhere. In no case should he have taken screenshots of code that they don't want anyone outside the company to see, and posted it here.

  • dark boog (unregistered) in reply to boog
    H+A=T/E\R:
    boog:
    Your not too smart are you?
    Also I suck cocks
    I have caught you sucking boog's cock. Pray i don't catch you sucking zune's cock!

    CAPTCHA: sino Because it would be an arch-sino!

  • (cs) in reply to gnasher729
    gnasher729:
    1. It looks as if there is code that can determine _exactly_ what inputs are accepted as meaning true or false, and which are not accepted. If that is what is intended, then the code is absolutely fine, maybe a bit short of documentation, and the WTF is our informant not knowing the spec for the function and making ASS umptions. It looks quite sensible that "yEs" should not be an acceptable input. At the moment I could implement this easily with a bit of code, but the method used is simple enough, and easily adapted to requirement changes.
    1. The informant should be fired immediately. If his employer is security conscious, that's not for him to judge. It is for him to accept it, or to look for a job elsewhere. In no case should he have taken screenshots of code that they don't want anyone outside the company to see, and posted it here.
    +1 Best troll I've seen on this site for a long time.
  • (cs) in reply to gnasher729

    tldr;

    TRWF is not knowing you're meme! Know you're meme!

    gnasher729:
    1. It looks as if there is code that can determine _exactly_ what inputs are accepted as meaning true or false, and which are not accepted. If that is what is intended, then the code is absolutely fine, maybe a bit short of documentation, and the WTF is our informant not knowing the spec for the function and making buttumptions. It looks quite sensible that "yEs" should not be an acceptable input. At the moment I could implement this easily with a bit of code, but the method used is simple enough, and easily adapted to requirement changes.
    -> I can't see what's wrong with that code! Did anyone of you bitches read the specs?
    gnasher729:
    2. The informant should be fired immediately. If his employer is security conscious, that's not for him to judge. It is for him to accept it, or to look for a job elsewhere. In no case should he have taken screenshots of code that they don't want anyone outside the company to see, and posted it here.
    -> The first rule of the fight club: etc...
  • (cs) in reply to Bronie
    Bronie:
    no laughing matter:
    Fail (includes ponies)

    [image]

    Will come and bring fledgling meme Zune with me: [image]

    Zune, how about being ass-raped by the legendary meme Tony the pony while seeing me copulate with this ungulate?

  • (cs) in reply to Gordy Gekko
    Gordy Gekko:
    Or offshore Indian code. Same difference, really.
    You're implication that there is a quality difference between code written in India for offshore and inshore is offensive and unjustifiable.
  • baka0815 (unregistered) in reply to Nagesh
    Nagesh:
    Must be junor progamer.
    FTFY
  • programmer (unregistered)

    using System; using System.Linq; using NUnit.Framework;

    namespace CodeSnippets { public static class StringParser { public static bool? ParseToBoolean(this string text) { if (string.IsNullOrWhiteSpace(text)) { return null; } string[] trueStrings = {"yes", "on", "start", "1"}; string[] falseStrings = {"no", "off", "stop", "0", "-1"}; if (trueStrings.Any(o => o.Equals(text,StringComparison.InvariantCultureIgnoreCase))) { return true; } if (falseStrings.Any(o => o.Equals(text,StringComparison.InvariantCultureIgnoreCase))) { return false; } return null; } }

    [TestFixture]
    class StringParserShould
    {
        [Test]
        public void Parse_text_correctly()
        {
            Assert.That("YES".ParseToBoolean(), Is.True);
            Assert.That("NO".ParseToBoolean(),Is.False);
            Assert.That("OFF".ParseToBoolean(), Is.False);
            Assert.That("START".ParseToBoolean(), Is.True);
            Assert.That("STOP".ParseToBoolean(), Is.False);
            Assert.That("1".ParseToBoolean(),Is.True);
            Assert.That("0".ParseToBoolean(),Is.False);
            Assert.That("-1".ParseToBoolean(), Is.False);
        }
    }
    

    }

  • polanski (unregistered) in reply to boog
    boog:
    Hater:
    I'm back on my boat with hot chicks so you should bite yourself while I'm offline
    You mean you're sitting on a blow-up mattress in your parents' basement, with a bucket of KFC.
    I am afraid that's not a mattress. Blow-up yes, but... not a mattress.
  • Bronie (unregistered)

    Mandatory morning pony

    [image]
  • Brian M (unregistered) in reply to ParkinT

    :) I was going to say the same thing ParkinT - What about yEs!

  • (cs) in reply to Guru
    Guru:
    Wrong, ELSE will be much more predictable because you always know it's opposite to IF, thus decreasing entropy.

    Probability theory FTW

    Is that the same theory that gives you 100% chance of picking the price that's hiding behind one of five doors, if you just change your mind enough times?

  • Guru (unregistered) in reply to The poop of DOOM

    No - the right one, where you can meet dinosaur in the street with 50% chance.

  • KnightSword (unregistered) in reply to The poop of DOOM

    Except, the reality is that you should never, NEVER let users type in replies like this unless there is ABSOLUTELY no way around it (like console-based applications). This is why checkbox, radio button, and select controls were created; to funnel known answers to known inputs. Keep it simple I say.

  • Could I Bother You to Recharge My Zune? (unregistered) in reply to dark boog
    dark boog:
    H+A=T/E\R:
    boog:
    Your not too smart are you?
    Also I suck cocks
    ...Pray i don't catch you sucking zune's cock!
    Which one?
  • Could I Bother You to Recharge My Zune? (unregistered) in reply to no laughing matter
    no laughing matter:
    Will come and bring fledgling meme Zune with me:[image]

    Zune, how about being ass-raped by the legendary meme Tony the pony while seeing me copulate with this ungulate?

    What is happening to me? I actually felt blood flow into my penis when looking at that pony.

    Why?

  • (cs) in reply to Could I Bother You to Recharge My Zune?
    Could I Bother You to Recharge My Zune?:
    dark boog:
    H+A=T/E\R:
    boog:
    Your not too smart are you?
    Also I suck cocks
    ...Pray i don't catch you sucking zune's cock!
    Which one?
    I said cock! Cock with a C. Not sock (pink or other colour).
  • (cs) in reply to Could I Bother You to Recharge My Zune?
    Could I Bother You to Recharge My Zune?:
    What is happening to me? I actually felt blood flow into my penis when looking at that pony.

    Why?

    Teaches you: Do not work with scissors while reading thedailywtf!

  • L. (unregistered) in reply to neminem
    neminem:
    Matt Westwood:
    The real WTF is that you're expecting some luser somewhere to type in a response which requires one of two answers. WTF is wrong with a pair of fucking radio buttons?!?
    Since you asked, we're not expecting the user necessarily to type in anything. The goal is to fill in a checkbox in a pdf. The input is coming from a token, which might come from a script, or from a database, or (most likely) from the value of another checkbox in another pdf. The pdf specification *recommends* a certain value for a checkbox being toggled, but depressingly enough, it does not *require* a certain value. The user is not necessarily the person who created the pdf they're trying to read the value of. Hence, flexibility.

    Right so you're using a PDF . and you think there is no WTF ? That's not flexibility, it's failability.

  • PRMan (unregistered) in reply to Steve
    Steve:
    Not that I want to defend this piece of code, but the main criticism so far of it not accounting for things like sTart and such is almost unfair - they've accounted for any variation that a sane human might use. "START", "start" and "Start", for example. A casual glance at those and you wouldn't immediately think it's a typo (unless your coding style dictates that it is). However, if you looked at sTart, unless you're using Hungarian notation and have some sort of string Tart, then you'd immediately think it looks wrong.

    Of course, that's besides the point in which this kind of boolean handling is just wrong.

    While this sort of Boolean coding may appear "wrong", sometimes you have code already existing with these values as settings and sometimes people are already used to calling one thing "stop/start" another "True/False" another "1/0" and another "Y/N" before even taking the project to a computer.

    What's so wrong about letting people speak what comes naturally to them? Everybody thinks Siri is wonderful.

  • (cs) in reply to Gordy Gekko
    Gordy Gekko:
    Nagesh:
    Must be junor programer.

    Or offshore Indian code. Same difference, really.

    Not really. There's at least a modicum of hope for improvement/growth/learning from a "junor programer".

  • Idiot (unregistered)

    It's "I'll be sure to follow up", not "I'll be sure to follow-up".

    I know it's industry practice here to mangle a verb and an adverb into weeaboo "verbs" like that, but just stop it. All of you. Learn to use English even if it is not your native language, and especially if it is.

    You don't "setup" anything and you don't "follow-up" anything. Those are substantives, not verbs.

  • visualbasucks (unregistered) in reply to Bryan the K

    yes/no/NaN/Null/FileNotFoundFileDeletedOrNotEnoghSpace

  • Deffy (unregistered)

    Aside from the fact that they should have each stored only once, and then call tolower on whatever they're comparing, there's nothing wrong with this. I have code to do this myself.

  • Jeremy Friesner (unregistered) in reply to froggy evenings
    froggy evenings:
    Point being, you need a pretty large dictionary to do this.

    It's a straightforward fix; just go through the OED and for each word in it, decide whether that word should map to true or false. Other languages do something similar with gender, so it's not unprecedented. ;)

  • Mark (unregistered)

    Everyone is missing the beauty here - when you are too afraid to call a utility function in your own code due to the possibility of side effects, you use a map like this.

    ;)

    Problem is, it isn't a map, but an array.

    If it is C#, then it is much more fun to extend the string class:

    static const Dictionary<string,boolean> StrBools={
       {"yes",true}
       ,{"no",false}
       ....
    };
    
    public static boolean AsBool(this string s){
       return s.AsBool(false);
    }
    
    public static boolean AsBool(this string s, boolean def){
      string s2=s.ToLower();
      boolean value = false;
      if (!StrBools.TryGetValue(s2, out value)){// dont use .ContainsKey(s2), just go for it
         return def;
      }
      return value;
    }
    //usage
    if (("yes").AsBool()==true){
      string yes="yes";
      if (yes.AsBool()==true){
        //its very true now
      }
      if (("bullshit").AsBool(true)==true){
        //even BS can be true
      }
    }
    
  • Mark (unregistered) in reply to RedFox
    RedFox:
    TRWTF is that nobody realised this is C++ code and that StringSettingBool is probably a struct.

    Either way, I think the following solution displays the superiority of C++ over petty languages like C# or Java in many ways. Albeit, it doesn't remove the fact that the "Truth Enough" snippet is a disgrace to any respectable C++ programmer.

    #include <string.h> // strchr, strlwr
    inline bool isTrue(const char* str)
    {
    	char temp[2] = { *str, 0 };
    	return strchr("1tyg", *strlwr(temp)) != NULL;
    }
    

    My God, its full of stars! Hows about:

    public static boolean ToBool(this string s){
       return "1tyg".IndexOf((s+"x").Substring(0,1).ToLower())!=-1;
    }
    // usage:
    if ("y".ToBool()) {
    }
    if (s.ToBool()) {
    }
    

    Whats needed is to extend string so it has a .Has method that takes care of "" and eliminates s+"x" weirdness.

    So ultimately it could be written:

    return "1tyg".Has(s.First().ToLower());
    

    Or even:

    return s.First().ToLower().IsIn("1tyg"); // =)!
    

    And the best part is -- you can read it at a glance and know you got it right!

  • Brian White (unregistered) in reply to frits
    frits:
    22 ways to express boolean values ought to be enough for anybody.

    It's lacking 1/0 which I would be muuuucccch more likely to assign to a bool than yes or no. And it's lacking the VBScript -1/0, which is probably for the best.

  • Andrew (unregistered) in reply to Could I Bother You to Recharge My Zune?

    If you're in trouble he will save the day He's brave and he's fearless come what may Without him the mission would go astray He's Arnold, Arnold, Arnold Rimmer

    Without him life would be much grimmer He's handsome, trim, and no-one slimmer He will never need a zimmer He's Arnold, Arnold, Arnold Rimmer

    More reliable than a garden trimmer He's never been mistaken for Yul Brynner He's not bald, and his head doesn't glimmer

    Master of the wit and the repartee His command of space directives is uncanny How come he's such a genius? Don't ask me! Ask Arnold, Arnold, Arnold Rimmer

    He's also a fantastic swimmer And if you play your cards right Then he just might come round for dinner He's Arnold, Arnold, Arnold Rimmer

    No rhymes left now apart from quimmer He'd better fade us out before we get to schlimmer Fade out you stupid plimmer.

  • Ardyvee (unregistered)

    They also forgot: nO, yEs, yES, yeS (...) to cover up all the possibilities.

Leave a comment on “Truth Enough”

Log In or post as a guest

Replying to comment #:

« Return to Article