Snipe Hunting. Er, Find the WTF.



  • <font size="2">

    I was getting an error while refactoring some software.  "Value could not be converted to a boolean value."  Software is UI, library, database.  UI code looked good so I located the library and pulled it out.

    <font size="2">

    private string isPercentage;
    public string IsPercentage
    {
         set { isPercentage = value; }
         get { return isPercentage;   }
    }

    Ok, it's named IsPercentage and I had naively assumed it was a boolean without looking at the data type.  I mean, I'm fairly certain that most folks would look at that variable name and think "true/false" or SOMETHING along those lines.

    But what really ground my gears was when I started looking at the usage of the above variable.

    Everywhere it was used, it was converted to a boolean.

         objDB.MakeParameter("@blnIsPercentage",Convert.ToBoolean(this.IsPercentage), DbType.Boolean),

    <font size="2">(Feel free to have fun with the prefixes in both the code and the stored procedure parameter names.  I didn't write it.)</font>

    </font></font>

    <font size="2">So... why would ANYONE make the variable a boolean, use boolean variables in the UI, save it as a boolean, but SAVE IT AS A STRING in the business layer?</font><font size="2"></font>



  • The real wtf is the absence of a // wtf ! comment along the MakeParameter line.



  • By business layer, do you mean that the "boolean" is stored as a string in a field in the DB?  If that's the case, then I can't say that I'm that surprised... I'm still sad, but not surprised. :)



  • [quote user="skippy"]By business layer, do you mean that the "boolean" is stored as a string in a field in the DB?  If that's the case, then I can't say that I'm that surprised... I'm still sad, but not surprised. :)
    [/quote]

     Actually I think it's much worse than that.  It looks like it's a boolean in the database, a boolean in the UI, but a string in the business layer.  That's actually a pretty good WTF.
     



  • [quote user="smbell"]

     Actually I think it's much worse than that.  It looks like it's a boolean in the database, a boolean in the UI, but a string in the business layer.  That's actually a pretty good WTF.

    [/quote]

    Yep, you nailed it.  I came across another gem today too.

    <font size="2">

    if(string.Equals(isValid , true))
    {
         AddtoGrid();
    }

    And you wish isValid was a string variable... it's Boolean.

    </font>

    grumble...


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.