-Поиск по дневнику

Поиск сообщений в rss_thedaily_wtf

 -Подписка по e-mail

 

 -Постоянные читатели

 -Статистика

Статистика LiveInternet.ru: показано количество хитов и посетителей
Создан: 06.04.2008
Записей:
Комментариев:
Написано: 0


CodeSOD: The Cleaner

Четверг, 19 Ноября 2015 г. 14:30 + в цитатник

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, isnt a good trait in a cleaner. Dont ask questions. Dont poke your nose where it doesnt 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] Release! is a light card game about software and the people who make it. Play with 2-5 people, or up to 10 with two copies - only $9.95 shipped!

http://thedailywtf.com/articles/the-cleaner

Метки:  

 

Добавить комментарий:
Текст комментария: смайлики

Проверка орфографии: (найти ошибки)

Прикрепить картинку:

 Переводить URL в ссылку
 Подписаться на комментарии
 Подписать картинку