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

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

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

 

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

 -Статистика

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


CodeSOD: As The World Ternaries

Четверг, 22 Сентября 2016 г. 13:30 + в цитатник

Ah, the ternary operator. At their worst theyre a way to obfuscate your code. At their best, theyre a lovely short-hand.

For example, you might use the ternary operator to validate the inputs of a function or handle a flag.

Adam Spofford found this creative use of the ternary operator in a game hes developing for:

    this.worldUuid = builder.worldId == null ? null : builder.worldId;
    this.position = builder.position == null ? null : builder.position;
    this.rotation = builder.rotation == null ? null : builder.rotation;
    this.scale = builder.scale == null ? null : builder.scale;

    this.worldUuid = builder.worldId;
    this.position = builder.position;
    this.rotation = builder.rotation;
    this.scale = builder.scale;

Curious about how this specific block came to be, Adam poked through the Git history. For starters, the previous version of the code was the last four lines- the sane lines. According to git blame, the project lead added the four ternary lines, with a git comment that simply read: Constructing world details. That explains everything.

[Advertisement] Universal Package Manager - ProGet easily integrates with your favorite Continuous Integration and Build Tools, acting as the central hub to all your essential components. Learn more today!

http://thedailywtf.com/articles/as-the-world-ternaries

Метки:  

 

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

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

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

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