Can i get a cached TRUE_AND_FALSE please?



  • Well, after lurking for a long time i thought it was time to post a WTF from my job over here. My colleague and I read the thedailywtf daily and stumbled on this piece of gold. In the system that we have to maintain a lot of lists are cached so they dont have to be retrieved from the database every page request. Sounds simple enough and for lists that barely change its an good idea. Today i was creating a list of all cached lists we use and which ones we need to manually update.

    While the manual updating is a bit tedious (we have to login to the system, call a "hidden" asp page that reads all values from the database, then creates a cachedLists.js next to the asp file. We then have to login to the remote desktop and distribute this file to all servers that serve the list.) i came across certain gems. Almost all code lists contain 2 columns, an description and a code.

    Most of the code lists that are retrieved has a function call that includes the category/table name to be retrieved and this is seen from the function.


    return GetaList("TABLENAME");


    But when i came to the list for WorkHandicap the call looked very odd:

    public dataSet GetWorkHandicap()
    {
    return this.RecBool(TRUE_AND_FALSE);
    }


    The first thing that kinda felt odd was the "TRUE_AND_FALSE" constant. So i checked the definition:

     

    static private string TRUE_AND_FALSE = string.Empty;



    My first guess was that, wait, i really had no idea why they would call an empty string TRUE_AND_FALSE? So, onto the RecBool function!


    private DataSet RecBool(string strCode)
    {
    DataTable table = new DataTable(CODE_TABLE_NAME);
    table.Columns.Add(CODE_COLUMN);
    table.Columns.Add(DESC_COLUMN);

    if (strCode == "1" | strCode == "")
    {
    DataRow trueRow = table.NewRow();
    trueRow[CODE_COLUMN] = "1";
    trueRow[DESC_COLUMN] = "Yes";

    table.Rows.Add(trueRow);
    }
    if (strCode == "0" | strCode == "")
    {
    DataRow falseRow = table.NewRow();
    falseRow[CODE_COLUMN] = "0";
    falseRow[DESC_COLUMN] = "No";

    table.Rows.Add(falseRow);
    }

    DataSet dataSet = new DataSet();
    dataSet.Tables.Add(table);

    return dataSet;
    }


    So, it seems they created a function that actually creates a dataset with 2 columns in it that include yes and no. The best part may be that its even possible to create a dataset with 1 row that has either yes or no.. Not to mention they dont check for a Null value.. No wait, the best part is probably that we have more then 10 cached lists with Yes and No! This is actually called more then 10 times in a row to create cached lists!

    But hey, its just another day at work ofcourse!



  • A few things you missed about recBool()

      <!-- Fuck closing the li tags, this BB is such a piece of shit it really doesn't matter if I give it invalid HTML. Hell if it chokes on it then we can all celebrate --/> <li>It checks against an empty string for both Yes/1 and No/0 <li>(I may be incorrect about this one, it is a C-like language, so I'm presuming the | and || operators are the same as C's) It uses a bitwise or instead of the logical one. <li>So what if it doesn't handle NULL? It doesn't handle anything other than "", "0" or "1" either </ol>


  • @Lingerance said:

    A few things you missed about recBool()

    1. It checks against an empty string for both Yes/1 and No/0
    2. (I may be incorrect about this one, it is a C-like language, so I'm presuming the | and || operators are the same as C's) It uses a bitwise or instead of the logical one.
    3. So what if it doesn't handle NULL? It doesn't handle anything other than "", "0" or "1" either

    No, i didnt really miss those parts. Its written in C# (forgot to mention it). Are you saying the way this all is handled is the proper way? In c# it is indeed a bitwise or instead of a logical one. If you give it something else then "", "0" or "1" it wont crash, if you give it a null value of string it would cause a crash.



  • @Wiebbe said:

    Are you saying the way this all is handled is the proper way?
    No. I was just adding a list.



  • Why not use HttpContext.Current.Cache?

    And also for lists that never change you can use enums:

    enum TrueAndFalse
    {
        True = 1,
        False = 0,
        FileNotFound = -1,
    }



  • Oh please, dont get me started on the general outline of the system.

    The general outline:

    The system itself uses a 3rd party business process application. It serves html pages using a dll file thats hooked in IIS. In order to handle the processes action files are called that are made up of "ProcessScripts". These scripts are fun, because they use a script no one really knows! Luckily, its possible to place Visual Basic Script in these files!

    So, to get the cached list, the DLL forwards the call to the ProcesScript, that in turn calls the Visual Basic script, where there is an Object created to get the lists (from a external dll), and then in the dll the DataSet created by the above function is changed to a recordset (because VBS doesnt support DataSets!) and then returned. And THEN we have where we are :(

    A enum would be nice i guess..



  • @Wiebbe said:

    static private string TRUE_AND_FALSE = string.Empty;

    It looks like TRUE_AND_FALSE is actually meant to be used like a Null value. For example, for cases where a user can choose between: "Yes", "No" and "Don't know"


Log in to reply
 

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