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

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

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

 

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

 -Статистика

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


CodeSOD: Returnary

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

Theres a certain class of bad code weve all seen before:

boolean someFunction() {
    if (someBooleanExpression) {
        return true;
    } else {
        return false;
    }
}

Its dumb, but largely harmless. Weve posted variations on this idea in the past. Scott P, however, found a new variation that may be the pinnacle of this kind of simple-minded programming. Ill let him introduce it.

I inherited a project that was developed in isolation by a lone developer that didnt do code reviews. I find something new to be horrified about every day. The developer responsible has a knack for adding unnecessary complexity to what should have been a much simpler application. This method perfectly sums up what the architecture of this application is like on every level. Its layer upon layer of obfuscation or redundant code.

boolean hasFeatures() {
        if (license.getFeatures().size() > 0 ? true : false) {
                return true;
        }
        return false;
}

Honestly, I think the ternary operator doesnt get enough use. We should just start putting ternary expressions all over our code, even if it means writing things like: myvar = true ? valueReturningFunction() : valueReturningFunction();. Isnt that pretty great? I love it.

[Advertisement] Otter allows you to easily create and configure 1,000's of servers, all while maintaining ease-of-use, and granular visibility down to a single server. Find out more and download today!

http://thedailywtf.com/articles/returnary

Метки:  

 

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

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

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

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