Birthday cake in ice cream shop in Basking Ridge New Jersey

Good intentions are never enough. If they aren't coupled with the wisdom to follow through properly, they can result in a horrible mess. Today’s Anonymous submitter has learned this the hard way:

I'm working on this particular 500k LOC monster for a few years now, and I consider this code to be a "representative function". It's a performance-critical server application crunching huge amounts of data through its bowels, and its development started around 2001 on a desktop computer. For this reason, the original developer chose to '"'develop'"' with performance being the primary concern (see, I put the quotes into quotes to let you know that the original developer was very creative about "developing"; he "made things work", you know).

He was very agile and customer-driven ("Yeah, refresh the page a few times, and if the right thing comes out, I'll put that live on all systems."). He was environment-aware (he did variable recycling). He kept the code clean and simple ("char*" and "int*" is all you ever need). He wrote easy-to-use interfaces (query parameters are mostly bit-flags, unless you query with a few special values like "format=100" or "format=3", which do something very useful). He wrote an easy-to-use line-based output format (sometimes switching between "\n" and "\r\n", and the lines themselves even had context-sensitive formats, alternating between pipe- and semicolon-separated lists). Users didn't have to cope with errors (if the first line of the output was "0" or "-1", something went wrong). [He] even showed different results in consecutive requests if there were too many results to fit into the size-limited list, so the user had the chance to see everything [that] might be of interest to him!

int GetAgeFromBirth(time_t nBase, int nBirth)
    tm tms;
#if _MSC_VER >= 1400
    tms = *localtime((time_t*)&nBase);

    char strConv[8];

    int nD,nM,nY;
    if(sscanf(strConv,"%2d%2d%2d",&nD, &nM, &nY)==3){
        int nRet=tms.tm_year-nY;
        if(tms.tm_mon<nM || (tms.tm_mon==nM && tms.tm_mday<nD))
        return nRet;
    return 25;

[Advertisement] Otter, ProGet, BuildMaster – robust, powerful, scalable, and reliable additions to your existing DevOps toolchain.