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

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

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

 

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

 -Статистика

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


Coded Smorgasbord: Efficient WTFery

Среда, 18 Февраля 2015 г. 15:00 + в цитатник

Some horrible code is acres of awful, thousands of tortured lines of mess and horror. Some developers can compress their WTFs down into a handful of lines.

For example, Zlatko was working with a Node.js developer who was big on unit tests. Unfortunately, that developer didnt understand that you couldnt write a synchronous test for an asynchronous method- the test will always pass.

Thats why this code, buried in a callback, passed:

while (i <= location.length) {
    if (i === location[i - 1].rank) {
        i++;
    }
};

Or take Wendy, who inherited an application that has to deal with poorly sanitized data. Some fields, like Print_Code, are VARCHAR(2), which means many records end up with a trailing space.

Wendys co-worker cleaned out that extra white-space with this block:

String print_code = " ".concat(dto.getPrint_code().trim());
if (print_code.length() == 3) {
print_code = print_code.trim();
}

With Java web development, its not uncommon to need to detect whether youre inside of WebLogic, Tomcat, etc.. Josh found this… exceptional solution in his codebase:

boolean isTomcat = new Throwable().getStackTrace()[1].toString().indexOf("org.apache.catalina") > -1;

For a language not exactly known for its brevity, this amount of WTF in a single line is quite an achievement .

Then again, maybe we dont need a line of code at all. Alexandre was hunting a bug that caused the wrong products to show up as a deal in their e-commerce site. Fortunately, his predecessor documented the code quite well:

/* ATTENTION: this crap below is messed up and brings more deals than you expect, it is because SQL SP looks up for the deals inside children groups of selected group. Don't change this until somebody notice the situation */

And finally, well close with a true confession from Corey. When Corey started a comp-sci program in college, he aleady had a fair bit of experience as a developer. When his professor assigned a write a factorial function exercise, Corey turned in this:

int f(int n){return n?f(n-!!n)*n:!n;}

The professor was not amused.

[Advertisement] Release! is a light card game about software and the people who make it. Order the massive, 338-card Kickstarter Edition (which includes The Daily Wtf Anti-patterns expansion) for only $29.95, shipped!

http://thedailywtf.com/articles/efficient-wtfery

Метки:  

 

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

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

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

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