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

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

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

 

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

 -Статистика

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


CodeSOD: String Cheese

Четверг, 17 Марта 2016 г. 13:30 + в цитатник

Imagine youre a Java programmer. You need to iterate across a list of strings. Your natural instinct might be to just use a for loop, and thats proof that youre not a true enterprise Java programmer.

Diethers company is home to true enterprise developers, and they know how to get things done.

List brandSpecValues = specValueDao.getBrandSpecValues();
boolean brndValueFound = false;
String listString = brandSpecValues.toString().replace("[", "");
listString = listString.replace("]", "");
String[] arr = listString.split(",");
for (String s : arr) {
        if (s.trim().equals(brandSpecValueString.toUpperCase())) {
                brndValueFound = true;
        }
}

Why iterate across a list when you can turn the list into a string first then turn it back into an array? For a moment, I thought, well, maybe the interface to the DAO changed to use Generics and they were trying to minimize code changes? But that makes no sense, because the only thing they would have needed to change was the type of brandSpecValues. Im left with one conclusion: they just really like Strings.

For bonus points, the array contains only 5 values ever, and this block of code is called from inside of a for loop that runs thousands of times in a row.

[Advertisement] Application Release Automation for DevOps – integrating with best of breed development tools. Free for teams with up to 5 users. Download and learn more today!

http://thedailywtf.com/articles/string-cheese

Метки:  

 

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

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

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

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