Santa Claus Code

  • Santa Claus code, n.:

    Code using especially convoluted or complex method to achieve a goal while ignoring an obvious simple solution. Because "why enter the house through the door when you can use the chimney?"

    For example this is how we convert one timestamp structure to another:

            std::string dateTimeString = timestamp->toString();
            char year[5], month[3], day[3], hours[3], mins[3], secs[3], ms[7];
            sscanf(dateTimeString.c_str(), "%4[^'-']-%2[^'-']-%2[^'T']T%2[^':']:%2[^':']:%2[^'.'].%s", year, month, day, hours, mins, secs, ms);
            std::shared_ptr<OtherTimeStampType> dateTimeValuePtr (new OtherTimeStampType());
            dateTimeValuePtr->setDate(static_cast<unsigned short>(strtol(year, nullptr, 10)), static_cast<unsigned short>(strtol(month, nullptr, 10)), static_cast<unsigned short>(strtol(day, nullptr, 10)));
            dateTimeValuePtr->setTime(static_cast<unsigned short>(strtol(hours, nullptr, 10)), static_cast<unsigned short>(strtol(mins, nullptr, 10)), static_cast<unsigned short>(strtol(secs, nullptr, 10)));

    The only purpose of the OtherTimeStampType is to serialize itself to the exactly same iso-8601 format it is being created from here as part of some convoluted serialization machinery.

    Using the door is so out!

  • Discourse touched me in a no-no place

    @Bulb said in Santa Claus Code:

    this is how we convert one timestamp structure to another

    Please tell me this is in the implementation of the relevant cast operator…

  • @dkf No, this is implementation copied to the two places that do the conversion. There is no conversion operator.

Log in to reply

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.