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

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

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

 

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

 -Статистика

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


CodeSOD: Defensive Programming

Среда, 17 Июня 2015 г. 13:30 + в цитатник

Marino was handed this code. Like all great code, its written defensively, protecting itself against nulls, empty strings, and other unexpected values.

I mean, sort of.

public static void LogMessageWithArguments(string message, params object[] args) {
        Condition.Requires(message, "Message");
        Condition.Requires(args, "arguments");
        if (string.IsNullOrEmpty(message))
        {
                message = string.Empty;
        }

        if (args != null)
        {
                message = string.Format(message, args);
        }

        if (string.IsNullOrEmpty(message))
        {
                throw new NullReferenceException("Geen data om te loggen");
        }

        Log(message);
 }

I mean, theyre really thorough about checking that the message has an actual value. Marino checked the Log function, and found that it already had an overload the accepted a list of formatting parameters, thus making this function both redundant and ugly.

[Advertisement] Scout is the best way to monitor your critical server infrastructure. With over 90 open source plugins, robust alerting, beautiful dashboards and a 5 minute install - Scout saves youvaluable engineering time. Try the server monitoring you'll M today.Your first 30 days are free on us. Learn more at Scout.

http://thedailywtf.com/articles/defensive-programming

Метки:  

 

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

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

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

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