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

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

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

 

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

 -Статистика

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


CodeSOD: And I Try, and I Try

Понедельник, 11 Мая 2015 г. 13:30 + в цитатник

If you want to put everything under test, you have to write code like this.

At least, thats what Alexs co-worker said to him, when Alex demanded an explanation for this block of code.

        public interface ITrier
        {
                void Try(
                        Action tryAction,
                        Func catchFunc)
                        where TException : Exception;

                void Try(
                        Action tryAction,
                        Func catchFunc,
                        Action finallyAction)
                        where TException : Exception;

                TReturn Try(
                        Func tryFunc,
                        Func catchFunc)
                        where TException : Exception;

                TReturn Try(
                        Func tryFunc,
                        Func catchFunc,
                        Action finallyAction)
                        where TException : Exception;

                TReturn Try(
                        Func tryFunc,
                        Func catchFunc,
                        Action finallyAction,
                        Func defaultReturnFunc)
                        where TException : Exception;

                TReturn Try(
                        Func tryFunc,
                        Func catchFunc,
                        Func defaultReturnFunc)
                        where TException : Exception;
        }

Now, this code doesnt precisely do anything, but dont worry- Alexs co-worker built an AbstractTrier class, which implements this interface, and can be inherited from in any situation where your testing patterns prohibit the use of try/catch blocks. Theres also a MockTrier, making this useful for testing, somehow.

And before you point out that theres a perfectly good language construct that could be used instead of this interface or its implementors, Alex warns us that the genius behind this code also has crafted ILooper, and IConditional.

[Advertisement] BuildMaster is more than just an automation tool: it brings together the people, process, and practices that allow teams to deliver software rapidly, reliably, and responsibly. And it's incredibly easy to get started; download now and use the built-in tutorials and wizards to get your builds and/or deploys automated!

http://thedailywtf.com/articles/and-i-try-and-i-try

Метки:  

 

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

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

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

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