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

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

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

 

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

 -Статистика

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


CodeSOD: The Hard Problem

Вторник, 27 Октября 2015 г. 13:30 + в цитатник

Ill warn you to start: this is a date handling CodeSOD, but thats only a small part of the WTF. You see, theres an old joke, There are three hard problems in computer science: naming things and counting things. This code has a hard time with the first:

       private string ReturnCurrentGMTTime()
        {
            string result = string.Empty;
            DateTime time = DateTime.Now;
            string fs = "yyyy-MM-dd'T'HH:mm:ss";
            result = time.ToString(fs);
            result += "+02:00";
            return result;
        }

Robert sent this in, after receiving it from a contractor.

This method name is a thing of beauty, simply because it is so wrong. Everything about it is wrong. The first problem is small, but rarely do we use the word Return as part of a method name. GetCurrentGMTTime would be better, but as this is C#, the convention is just to treat it like a property: CurrentGMTTime. Of course, GMT stands for Greenwich Mean Time, so like ATM Machine, our method name remains wrong. Perhaps it should be CurrentGMT or CurrentGMTime.

But thats small potatoes. Not only is the method just poorly named, its wildly inaccurate. DateTime.now only returns GMT in the event that you are on a machine in that time zone- which I happen to know that Robert is not. Hes actually in Denmark- which explains the +02:00- during Daylight Savings Time, that is their offset from GMT.

So, the method isnt ReturnCurrentGMTTime, but it is CurrentTimeWithTimeZone. And, of course, this formatting uses some of the built-in formatting functionality from .NET, but decides in the end to use string concatenation to take it the last mile. In the end, it's not wrong- just stupid.

[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/the-hard-problem

Метки:  

 

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

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

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

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