In software development, there are people who get the unenviable task of being the cleaner. Somebody makes a mess, and the cleaner comes in to take care of it. And that brings us to Tina.

I'm Winston Wolf. I solve problems.

Tina was brought in as a cleaner. There was an application that was a mess , and the powers-that-be wanted it taken care of. Tina took a look, and she noticed that there were a lot of round trips to the database. In fact, after profiling, it almost looked like every query ran at least twice. She saw code following this pattern everywhere:

    if (!IsTableEmpty("users")) {
        results = GetTableData("users");
    }

Or, worse:

    if (!IsTableEmpty("users") && !IsTableEmpty("orders") && !IsTableEmpty("line_items")) {
        users = GetTableData("user");
        orders = GetTableData("orders");
        lines = GetTableData("lines");
        for (int i = 0; i < users.count; i++) {
            for (int j = 0; j < orders.count; j++) {
                for (int k = 0; k < lines.count; k++) {
                    //manually join all the records together
                    //with a giant block of conditionals
                }
            }
        }
    }

With that sort of logic, Tina knew exactly how this particular application needed to be “taken care of”, but she was curious. Curiousity, of course, isn’t a good trait in a cleaner. Don’t ask questions. Don’t poke your nose where it doesn’t belong. But she just had to know- how was IsTableEmpty implemented?

    private bool IsTableEmpty(string s){

            SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM "+s,"server=****;database=****;User ID=****;Password=****");

            DataSet ds = new DataSet();

            adapter.Fill(ds);

            int count=0;

            foreach(DataRow row in ds.Tables[0].Rows){

                    count+=1;

            }

            if(count>0)

                    return false;

            return true;

    }
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!