• krftsman (unregistered) in reply to Digitalbath
    Digitalbath:
    Anonymous:

        bool v_ISO9001 = value;
        //can only be true or false
        if (v_ISO9001.ToString().ToUpper() == "TRUE" ||
            v_ISO9001.ToString().ToUpper() == "FALSE") { m_ISO9001 = v_ISO9001; } else
        {
          throw new ArgumentException();
        }

    Wouldn't the [bool v_ISO9001 = value;] part throw an exception if  value couldn't be made into a bool type anyways thus making the rest of this code pointless?

    Yes.



    Wouldn't it simply not compile if value wasn't a bool?  The property is defined as a bool, therefor, value will always be a bool, no?

    p.s.  forgive the previous screw up
  • FuzzyLogic (unregistered) in reply to Wayne

    Some appear to miss the value point of this code.

    You outsource to "save" money.  Yes the code could have been written in much fewer lines of code, but the more lines of code for the same amount of money is considered a "value".  IE:

    6 lines of code per property sets and gets for $6 @ $1 per line.

    or

    24 lines of code per property sets and gets for $6 @ .25 cents per line

    The idiots that hire them see the latter as a better investment, besides the other outsource company was charging .75 cents per line of code right...

  • (cs) in reply to Jake Vinson

    Jake Vinson:
    Wow, think of all the lines of code that could be used to validate that an integer is an integer.

    Pssht... Just string and regex it... [;)] Wait, that's not the "enterprise" solution...

  • - (unregistered) in reply to naterkane

    // Here's a patch for a bug I found in their code:
    throw new ProgrammerIsAMoronError(true);

  • xcor057 (unregistered)
      set
      {
        bool v_ISO9001 = value;
        //can only be true or false
        if (v_ISO9001.ToString().ToUpper() == "TRUE" ||
            v_ISO9001.ToString().ToUpper() == "FALSE")
        {
          m_ISO9001 = v_ISO9001;
        }
        else
        {
          throw new ArgumentException();
        }
      }
    }

    On second thought.  I think this was written by a former therapist.  It's 'true' or 'false' or 'what do you think (...err feel) the answer should be?'

     

  • (cs)

    *sigh* Another incarnation of IsTrue(). How funny.

  • (cs) in reply to nobody

    nobody:
    enterpricy

    Now THERE'S truth in advertising.

  • (cs) in reply to Quietust

    Anonymous:
    The fun part comes when Boolean.ToString() is localized to return true/false strings in the appropriate language, at which point m_ISO9001.ToString().ToUpper() returns "VRAI"/"FAUX" on a computer in France and the program dies horribly.

    Fortunately, Microsoft plans for such foolishness, and Boolean's ToString is never localized, and always returns "True" or "False" regardless of the culture setting:


     public static void Main()
     {
              IFormatProvider french = new CultureInfo("fr-FR");
              Console.WriteLine(DateTime.Now.ToString("D", french));
              Console.WriteLine(true.ToString(french));
     }

    Displays:


    jeudi 20 avril 2006
    True

     

     

  • John (unregistered) in reply to bullseye

    null

    or maybe an error object.

    perhaps the origional function returned a Variant (Varient? whatever)

  • (cs) in reply to JamesCurran

    Well, that just made a mess of my code.  Let's try this again:

     public static void Main()
     {
      IFormatProvider french = new CultureInfo("fr-FR");
      Console.WriteLine(DateTime.Now.ToString("D", french));
      Console.WriteLine(true.ToString(french));
     }

     

     

  • (cs) in reply to John

    I wonder what these functions look like (I'm sure they have them)

    IsTrue();

    IsFalse();

    IsTrueOrFalse();

    IsNotTrueOrFalse();

  • xocomil (unregistered)

    It is really impressive how bad this outsorced code is. If they really cared about this project they would know that if(m_ISO9001.ToString().ToUpper() == "TRUE") actually creates two new strings in memory on top of the boolean value that it is representing AND the "TRUE". To get a truly optimized compare that will compare without case sensitivity, any real developer knows you should use if(string.Compare(m_ISO9001.ToString(), "TRUE", true) == 0). This only creates one extra string in memory. That is a 50% increase in performance!!!

  • (cs) in reply to krftsman
    Anonymous:
    Digitalbath:
    Anonymous:

        bool v_ISO9001 = value;
        //can only be true or false
        if (v_ISO9001.ToString().ToUpper() == "TRUE" ||
            v_ISO9001.ToString().ToUpper() == "FALSE") { m_ISO9001 = v_ISO9001; } else
        {
          throw new ArgumentException();
        }

    Wouldn't the [bool v_ISO9001 = value;] part throw an exception if  value couldn't be made into a bool type anyways thus making the rest of this code pointless?

    Yes.



    Wouldn't it simply not compile if value wasn't a bool?  The property is defined as a bool, therefor, value will always be a bool, no?

    p.s.  forgive the previous screw up

    Yeah, sorry, I was just going for the quick answer.  You would get a compilation error.

  • (cs) in reply to naterkane
    Anonymous:
    if a boolean isn't true or false, then we have some bigger issues to address, no?

    What you say is very file not found, very file not found indeed.

  • (cs) in reply to ammoQ

    ammoQ:
    They know something you don't.  In 2012, MS will release a quantum computer compatible version of the .net runtime that will replace the two-valued boolean with a fuzzy value that can take any value between false and true. Think of it as a float, constrained to a value between 0 and 1. 0=false, 1=true, 0.5=maybe, 0.2=rather not, 0.9=most likely etc. The way they programmed this property, they can make sure that only true and false slip through, not those undecided other values.

     

    I'm (blnSure = .1) sure you're right

  • (cs) in reply to MikeMontana

    Perhaps it's pay-by-line billing, and the contractor is counting on not being spot-checked. After all, more code means it must be a better product!


  • (cs) in reply to xocomil
    Anonymous:
    It is really impressive how bad this outsorced code is. If they really cared about this project they would know that if(m_ISO9001.ToString().ToUpper() == "TRUE") actually creates two new strings in memory on top of the boolean value that it is representing AND the "TRUE". To get a truly optimized compare that will compare without case sensitivity, any real developer knows you should use if(string.Compare(m_ISO9001.ToString(), "TRUE", true) == 0). This only creates one extra string in memory. That is a 50% increase in performance!!!


    Are you sure that each call to bool.ToString() creates a new string? Why the hell should they do that?
  • (cs)

    I think this wtf proves the Infinite Monkey Theorem.

  • (cs) in reply to ammoQ
    ammoQ:
    Anonymous:
    It is really impressive how bad this outsorced code is. If they really cared about this project they would know that if(m_ISO9001.ToString().ToUpper() == "TRUE") actually creates two new strings in memory on top of the boolean value that it is representing AND the "TRUE". To get a truly optimized compare that will compare without case sensitivity, any real developer knows you should use if(string.Compare(m_ISO9001.ToString(), "TRUE", true) == 0). This only creates one extra string in memory. That is a 50% increase in performance!!!


    Are you sure that each call to bool.ToString() creates a new string? Why the hell should they do that?

    if (quotedPost.isSarcasm().toString().toUpper() == 'FALSE') {
            say("Where else would they put it? Mars?");
    }
    else if (quotedPost.isSarcasm().toString().toUpper() == 'TRUE') {
            quotedPost.append("</sarcasm>");
            sarcasmDetector.fix();
    }
    else {
            throw new ThisIsReallyAWtfException();
    }

  • (cs) in reply to Jake Vinson

    Jake Vinson:
    Wow, think of all the lines of code that could be used to validate that an integer is an integer.  Or testing every possible string combination.  That's like infinity billion lines!

    Yah, that'd be like totally cool.  and with all of the extra little bracket thingies it creates even more lines so it'd be like infinity billion + a whole bunch! 

  • (cs) in reply to Wayne
    Anonymous:

    That made my day.  Thanks!

    I wonder if this outsourcing shop was CMM level 5.  I wonder if it had all this redundant code because it was CMM level 5.

    My first reaction was to say the code was complete developer-is-an-idiot crap. My second thought was the developer was being paid by the KLOC. But the name of the property, ISO9001, has me wondering. Could some manager have forced the developer to do this in the name ISO9001 compliancy? Or could this be a developer trying to be recursively funny and putting all this redundancy stuff in there because the property is name ISO9001.

    With any other property name, I'd call out WTF or KLOC. But I too am wondering if this is CMM 5 humor. Heck, I'd be tempted to do something like this in an attempt to bring humor into my life if I was forced to be ISO9001 compliant with no good reason. Whether this is WTF, KLOC, or ISO induced, I think Scotty has the best description of the situation.

    Cap'n, I canna give you warp nine much longa - she's gonna blow

  • (cs) in reply to OneFactor
    OneFactor:
    My first reaction was to say the code was complete developer-is-an-idiot crap. My second thought was the developer was being paid by the KLOC. But the name of the property, ISO9001, has me wondering. Could some manager have forced the developer to do this in the name ISO9001 compliancy? Or could this be a developer trying to be recursively funny and putting all this redundancy stuff in there because the property is name ISO9001.

    With any other property name, I'd call out WTF or KLOC. But I too am wondering if this is CMM 5 humor. Heck, I'd be tempted to do something like this in an attempt to bring humor into my life if I was forced to be ISO9001 compliant with no good reason.


    What you're proposing is reasonable.  But it violates Hanlon's Razor:

    http://en.wikipedia.org/wiki/Hanlon%27s_razor

    Even so, I can follow your logic.  The code does look like a smart-ass way to "test for every possible condition," perhaps in response to some reviewer who was not convinced that true and false are all of the possible conditions for a boolean.

    But, in accordance with Hanlon's Razor, and maybe even Occam's Razor, stupidity seems to be a more plausible explanation.

    Perhaps at one time, the property was declared as a string, and whoever changed it, well, wanted to change as little as possible.  That is very plausible, as I've seen people declare boolean attributes as strings and also as integers in both Java and C#.

  • Darth (unregistered) in reply to MikeMontana
    MikeMontana:
    I would have to ask myself "why didnt they see the circular logic in using a Bool, casting to a String, and checking the string result in a boolean fashion?"


    You've got it.  The WTF is, of course, that they failed to validate the boolean result of the comparison on the string result.

    *facepalm*
  • Urz (unregistered) in reply to W

    <font face="Lucida Console" size="2">Quoting W:

    <?php // I like PHP<br>function isValidInt($variable)
    {
       if ($variable == 0) { return true; }
       elseif ($variable < 0) { return isValidInt($variable + 1) }
       elseif ($variable > 0) { return isValidInt($variable - 1) }
       else { return false; }
    }
    ?>

    Somewhat ironically that function does not actually work. Because of PHP's automatic type conversion, isValidInt(false) would return true. (after you add in the missing semicolons of course)
    </font>

  • John Hensley (unregistered)

    This is the kind of WTF that you get when someone doesn't grasp the distinction between compile time and runtime, and doesn't care to ask.

    The thought process was probably like this: "A program's source code is a string, so the names of the boolean values are also strings. When someone passes true or false to my function, they're passing a string. But what if they pass something else? I'd better check."

    It also shows that masochistic attitude toward coding that we see from so many F-heads.

  • Bob (unregistered) in reply to JamesCurran
    JamesCurran:

    Well, that just made a mess of my code.  Let's try this again:

     public static void Main()
     {
      IFormatProvider french = new CultureInfo("fr-FR");
      Console.WriteLine(DateTime.Now.ToString("D", french));
      Console.WriteLine(true.ToString(french));
     }


    Why would they do that?  How do you get a localized version of true or false?

  • John Hensley (unregistered) in reply to John Hensley
    Anonymous:
    This is the kind of WTF that you get when someone doesn't grasp the distinction between compile time and runtime, and doesn't care to ask.

    The thought process was probably like this: "A program's source code is a string, so the names of the boolean values are also strings. When someone passes true or false to my function, they're passing a string. But what if they pass something else? I'd better check."

    Oh yes, and Perl sucks because it rewards such thinking. I shouldn't pass up a perfect chance to dump on Perl.

  • this board sucks (unregistered)

    Totally fake, but amusing regardless.

  • Julie (unregistered) in reply to Digitalbath
    Digitalbath:
    Anonymous:

        bool v_ISO9001 = value;
        //can only be true or false
        if (v_ISO9001.ToString().ToUpper() == "TRUE" ||
            v_ISO9001.ToString().ToUpper() == "FALSE") { m_ISO9001 = v_ISO9001; } else
        {
          throw new ArgumentException();
        }

    Wouldn't the [bool v_ISO9001 = value;] part throw an exception if  value couldn't be made into a bool type anyways thus making the rest of this code pointless?

    Yes.



    The scariest part of this code is the "ISO9001" name - I wouldn't be surprised if this outsourcing company's secret to success is that they do ISO 9001 compliance - and this is what ISO 9001 compliance means.  Yikes. 
  • joe s (unregistered)

    Wow, Performance-Penalty for upcasing the String and matching it with a constant for an operation that checks one bit.

    disgusting

  • Konrad (unregistered) in reply to this board sucks
    To me this looks like a misguided attempt to check for an unitilised variable . 
    I have read most of the posts and everyout seemd to have forgotten that apart from
    True and False a boolean can have a value of (unasigned/None/Null or whatever C#
    returns for an uninitilised variable)
     
    No I can't see any sane reason for going to the effort of checking for undefined and then
    teturning it any way, or using string comparison to do the verification.
     
    As I write this it occures to me that C# may not allow a Boolean to be undefined, if
    so please exuse my ignorance of a Microsoft language.
     
    OK I can understand why there is a CAPTCHA but blue on blue...  is getting a little ridiculous.
  • John Hensley (unregistered) in reply to this board sucks
    Anonymous:
    Totally fake, but amusing regardless.

    Think so? I've spent plenty of time answering newbie questions about C. I wish I had a nickel from everyone who has asked me why "int n = argv[1];" doesn't work.

  • (cs)

    Problem solved:

    <FONT face="Courier New" size=2>if(!true && !false) { return 'file not found'; } else { return new MooseManager(); } // good to go.</FONT>

    _______________________________

    I really like MOOSE.  It's so versatile.  How 'bout y'all?

    [^o)]

  • (cs) in reply to ammoQ
    ammoQ:
    Anonymous:
    It is really impressive how bad this outsorced code is. If they really cared about this project they would know that if(m_ISO9001.ToString().ToUpper() == "TRUE") actually creates two new strings in memory on top of the boolean value that it is representing AND the "TRUE". To get a truly optimized compare that will compare without case sensitivity, any real developer knows you should use if(string.Compare(m_ISO9001.ToString(), "TRUE", true) == 0). This only creates one extra string in memory. That is a 50% increase in performance!!!


    Are you sure that each call to bool.ToString() creates a new string? Why the hell should they do that?


    While I am not familiar with C# in particular, it would seem reasonable that since the .ToString() function is returning a value, then it has to exist in memory somewhere.  And since it exist in memory, it must have been created at some point, and I highly doubt C# would just keep static versions of the true/false strings just for the heck of it.
  • (cs) in reply to AnonymousJack
    Anonymous:
    I'm pretty sure it's a forum


    You're probably the only one; I think most people would stop at "it might be a forum when it's finished".

  • The Great Lobachevsky (unregistered) in reply to Jake Vinson

    No.  You should keep the possible string combinations in a relational database table -- HELLO!!!!!   And look them up by key.  I strongly suggest using a GUID, because you can generate an infinite number of them, right?

  • Joshua (unregistered) in reply to WeatherGod
    WeatherGod:
    ammoQ:
    Anonymous:
    It is really impressive how bad this outsorced code is. If they really cared about this project they would know that if(m_ISO9001.ToString().ToUpper() == "TRUE") actually creates two new strings in memory on top of the boolean value that it is representing AND the "TRUE". To get a truly optimized compare that will compare without case sensitivity, any real developer knows you should use if(string.Compare(m_ISO9001.ToString(), "TRUE", true) == 0). This only creates one extra string in memory. That is a 50% increase in performance!!!


    Are you sure that each call to bool.ToString() creates a new string? Why the hell should they do that?


    While I am not familiar with C# in particular, it would seem reasonable that since the .ToString() function is returning a value, then it has to exist in memory somewhere.  And since it exist in memory, it must have been created at some point, and I highly doubt C# would just keep static versions of the true/false strings just for the heck of it.


    At most, it would be created once, and, hopefully, on the stack: according to the MSDN documentation, both TrueString and FalseString
    are shared/static fields of a boolean. (Hopefully, of course, Boolean.ToString does something analogus to
    return Value ? TrueString : FalseString;
    . MSDN seems to suggest that as the case.)

    (Here's hoping this works proper.)

  • bigh_29 (unregistered)

    A few comments

    1- If you can't trust the CLR to give you bool values that are either true or false, then can you really trust the string comparison operator to work?

    2- The setter is a real beauty (creating an unecessary variable, upper casing the string twice). I guess if you don't understand boolean types, there probably isn't a whole lot that you are good at.

    3- Ironic that the purpose of this POS code is to return whether ISO9001 quality standards are in effect. I would say based on the code, the answer to the question is always no.

    H^2

  • Chaos_Engineer (unregistered)

    This actually makes sense. Probably the value is coming from user input, and he doesn't trust the calling program to validate data before calling the routine.

    Like maybe it's a web application and it's using calls like

     setISO9001.asp?company=yoyodyne&certified=true

    A malicious user could run "calc" and compute 0/0, which returns NaN ("not a number"). Then they could cut-and-paste to replace "true" with "NaN" and corrupt the database. (This is a subtle exploit that a lot of programmers don't seem to know about. If you pass the literal string "NaN", then it evaluates to "true" because it's non-zero. But if you run "calc" and copy over the representation of 0/0, then you've got a value that's zero and non-zero simultaneously.)

  • waefawfe (unregistered) in reply to Chaos_Engineer
    Anonymous:
    This actually makes sense. Probably the value is coming from user input, and he doesn't trust the calling program to validate data before calling the routine.

    Like maybe it's a web application and it's using calls like
     setISO9001.asp?company=yoyodyne&certified=true

    A malicious user could run "calc" and compute 0/0, which returns NaN ("not a number"). Then they could cut-and-paste to replace "true" with "NaN" and corrupt the database. (This is a subtle exploit that a lot of programmers don't seem to know about. If you pass the literal string "NaN", then it evaluates to "true" because it's non-zero. But if you run "calc" and copy over the representation of 0/0, then you've got a value that's zero and non-zero simultaneously.)

    No.  First off, you can't divide by zero in .NET.  You simply get the DivideByZeroException.
     
    And, the accessor and mutator only take/send bools.  Therefore, you can't even call the method using a string ("NaN") without getting an exception.  Hell, your program won't even compile.
     
    What I think happened here is that the programmer doesn't understand strong typing.  He thinks that setting a return type of "bool" can be a dynamic cast in .NET that perhaps could be a null value (it can't be, because booleans in .NET are value types, and cannot be null, unless you're using .NET 2.0, in which case you can declare nullable types, such as bool?).  Therefore he checks for the only two possible values for a
    boolean.
  • nameless (unregistered) in reply to MikeMontana
    MikeMontana:
    Without bashing the developer, I would really want to know why the developer really felt it was important to go this route. Absolutely, this is "wtf-code", but, someone actually sat down to think this out - I would have to ask myself "why didnt they see the circular logic in using a Bool, casting to a String, and checking the string result in a boolean fashion?"

    Something is critically wrong when a developer, who obviously understands the OO principles of Get/Set and constructs of IF..THEN..ELSE plus Casting, yet, writes total bunk like this.

    Sure, you can say "well, thats what you get when you outsource stuff", but I dont buy that. I've worked with lots of people from India, Russia, Eastern-Europe, China - they understand and get the concepts of programming just as well as you or me. Something more sinister is at hand - is it "Antagonizing Compliance" between a sour employee and a sour manager? Is it compliance with a tersely worded spec that ridiculously demands "each and every parameter will be checked on entry and exit, in each and every call" [I've seen crap like that].

    Or is it just someone who plainly doesnt get it? I hope this isnt the case - oh it would be sad to think that someone next to me might be perpetrating a coding-crime like this, and actually mean it!


    Maybe it is just a joke on behalf of ISO9001? Because that standard does not improve the quality, it only forces to document the stupidity.
  • (cs) in reply to ammoQ

    Except in VB.Net, where True will be -1...

  • (cs) in reply to raluth

    Darn; missed the quote bit! above relates to:

    <quote>Think of it as a float, constrained to a value between 0 and 1. 0=false, 1=true, 0.5=maybe, 0.2=rather not, 0.9=most likely etc.</quote>

  • (cs) in reply to raluth
    raluth:
    Darn; missed the quote bit! above relates to:

    <quote>Think of it as a float, constrained to a value between 0 and 1. 0=false, 1=true, 0.5=maybe, 0.2=rather not, 0.9=most likely etc.</quote>



    If -1=true, then -0.5=maybe etc. That's not a big issue. I think implicit casting between bool and float is not enterprisy anyway.

  • (cs) in reply to APAQ11
    APAQ11:

        bool v_ISO9001 = value;
        //can only be true or false
        if (v_ISO9001.ToString().ToUpper() == "TRUE" ||
            v_ISO9001.ToString().ToUpper() == "FALSE") { m_ISO9001 = v_ISO9001; } else
        {
          throw new ArgumentException();
        }

    Wouldn't the [bool v_ISO9001 = value;] part throw an exception if  value couldn't be made into a bool type anyways thus making the rest of this code pointless?



    To be exact, the fact that the property, of which this code is the setter portion, is defined as a bool means that the attempt to assign to the property a value which is not bool and can not (implicitly) be cast to to it (as in SomeObject.ISO9001 = "FileNotFound") would already result in a compiler error, so "value" in the code above can safely be assumed to always be a bool.
  • Metaspace (unregistered)

     I suspect you use a generator for these Boolean-WTF's - admit it! :-)

    I wonder when we will be through all combinations it can produce :-) 

  • Newbie (unregistered) in reply to Digitalbath

    Actually, it wouldn't throw an exception here.  value is already guaranteed to be a boolean.  It would happen before here in the assignment as either a compiler error or an invalid cast.

  • Chris (unregistered) in reply to bigh_29

    3- Ironic that the purpose of this POS code is to return whether ISO9001 quality standards are in effect. I would say based on the code, the answer to the question is always no.

    ISO "quality" standards have very little to do with quality. If you do the same crap every time, and its documented, you're ISO-approved. So you could put the crap around every boolean, have a 20 page document explaining it and you'd pass your ISO audit with flying colours.

  • (cs) in reply to Newbie

    this wtf reminds me of the "When (n<0) wont't do" wtf.

  • LordCrc (unregistered) in reply to Joshua
    Anonymous:
    Hopefully, of course, Boolean.ToString does something analogus to

      return Value ? TrueString : FalseString;


    Yes, it would appear that it does.

Leave a comment on “Outsourced Property Value”

Log In or post as a guest

Replying to comment #:

« Return to Article