Remy Porter

Computers were a mistake, which is why I'm trying to shoot them into space. Editor-in-Chief for TDWTF.

Feb 2014

Code that Works

by in Coded Smorgasbord on

The first step to working with dates is to learn when to use the built in APIs. The second step is to learn how to do basic arithmetic, as Ron shows us.

if (wishDate.Hour < 10)
{
   while (wishDate.Hour < 10)
   {
       wishDate = wishDate.AddHours(1);
   }
}
else if (wishDate.Hour > 16)
{
   while (wishDate.Hour > 16)
   {
       wishDate = wishDate.AddHours(-1);
   }
}

Christmas is Cancelled

by in CodeSOD on

Murray’s company needed an easy way to tell whether or not a given date was a banking holiday or not. Someone wrote this function for MySQL .

CREATE FUNCTION `IS_HOLIDAY`(a_date datetime) RETURNS char(5) CHARSET utf8 COLLATE utf8_bin
   READS SQL DATA
   DETERMINISTIC
BEGIN

   DECLARE is_holiday char(5);

     select (CASE WHEN (DAYOFWEEK(a_date) = 1 OR DAYOFWEEK(a_date) = 7)

                      THEN 'Yes' ELSE 'No' END) INTO is_holiday;

   RETURN is_holiday;

 END

TC119a()

by in CodeSOD on

Matt recently made some changes to a “legacy” application. Unlike most legacy applications, this one was well instrumented with unit tests. Matt’s changes failed some of those unit tests, so he went to look and see what he needed to change to update the tests.


User Rejection Testing

by in Feature Articles on

The next feature confused Tim. After plucking all of the low-hanging fruit, the only requirements left were the ones that were difficult to understand or poorly specified in the functional documents. Right now, Tim had a fairly nice e-commerce system for handling most of the products and processes it needed to, but there was one requirement he didn’t understand: “System must calculate VAT appropriately.”

The system was complex, and served such a wide variety of products that there were several VAT calculations that could be correct. The specification didn’t define what “appropriately” meant in this case, and given the costs of being wrong, Tim didn’t want to guess. He rode the elevator all the way up to the lofty halls of the executive floor, where he found Reggie, the head of the finance department and primary customer contact for the e-commerce site.