I'll be back...



  • A few unfortunate individuals may know something of this beast. The title is an allusion to the system name.

    Deep within the bowls of a large financial institution lurks this monster system, written by a single person (Highly Paid Consultant, before you ask). The Objective-C GUI is a work of art. The ANSI C server code follows the same pattern...

    Here are some of finest gems of true WTF-ery I've accumulated from the beast over the years. A lot of it's normal bad code, cut&paste and messed up. But the pieces here are true gems that make you sit up and ask yourself the same question that has driven scores of maintenance programmers mad over the years:

     "WTF!?!?"

     Say which... what?

        
    if (what == 0) {
    // Code Block A
    }
    else if (what == 2) {
    // Code Block B
    }
    else if ((what == 1) || (what == 3) || (what == 5)) {

    if (what == 1) which = 0;
    if (what == 3) which = 1;
    if (what == 5) which = 1;
    }

    // Code Block C omitted for sanity/brevity

    if (what == 5) FooBar(position, 3);
    else doWibble(position, what);
    }

     I was going to leave out mystery Code Block C, but actually it's good a few laughs too:

           if (manualrequests[position].systemid == 1) {
    if (strcmp(clients[i].type, "AAA") == 0) {
    found = 1;
    temp_fd = clients[i].fd;
    send_data(1, temp_fd, retstr);
    }
    }
    else if (manualrequests[position].systemid == 2) {
    if (strcmp(clients[i].type, "BBB") == 0) {
    found = 1;
    temp_fd = clients[i].fd;
    send_data(1, temp_fd, retstr);
    }
    }

    .....etc.....

    else if (manualrequests[position].systemid == 10) {
    if (strcmp(clients[i].type, "XXX") == 0) {
    found = 1;
    temp_fd = clients[i].fd;
    send_data(1, temp_fd, retstr);
    }
    }

    Oh except for case 3 which actually looks like this:

           else if (manualrequests[position].systemid == 3) {
    if (clients[i].g1 != 999) continue;
    temp_fd = clients[i].fd;
    send_data(1, temp_fd, retstr);
    }

    If at first you cannot bind; bind, bind then bind again...

    The original HPC didn't understand really how TCP works, particularly closing sockets and that whole damn TIMEDWAIT crap, when he wrote his network code. As the system was inevitably a massive distributed system built around TCP/IP sockets (which would certainly be what I'd write if I didn't understand sockets), we have some interesting network code. Like this:

       for(;;) {
    myport++;
    if ((myport - LISTENPORT) >= 5) {
    myport = LISTENPORT;
    WARNING(func, "bind() failedon all ports from " << LISTENPORT);
    SLEEP(func, 5, "No idea");
    }

    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servaddr.sin_port = htons(myport);

    if (bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) {
    std::strstream msg;
    msg << "bind() to " << myport << " failed with ";

    if (errno == EADDRNOTAVAIL) msg << "EADDRNOTAVAIL";
    else if (errno == EADDRINUSE) msg << "EADDRINUSE";
    else if (errno == EBADF) msg << "EBADF";
    else if (errno == EINVAL) msg << "EINVAL";
    else if (errno == ENOTSOCK) msg << "ENOTSOCK";
    else msg << errno;
    ERROR(func, msg.str());
    // close(listenfd);
    continue;
    }

    if ((ret = listen(listenfd, LISTENQ)) != 0) {
    LOG_WARNING(func, "listen() failed - myport = " << myport);
    // close(listenfd);
    continue;
    }

    break;
    }

    Ironically, one of the reasons why the system was made distributed was for increased reliability and fault tolerance. That is, if you could ever get restarted processes to connect again...

    This code block is used in around 20 different processes, in various cut&pasted modified variants. 

    Other gems

    There are too many code snippets to fully list here are a few good ones:

        if ((onoff != 99) && (onoff != 98)) {
    clients[found].foobarregister[group] = onoff;
    if (onoff == 0) checkFoobarRegistered(group);
    }

    ---

    static char months[13][4] = {" ", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
    static char monthslow[13][4] = {" ", "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"};

    ---

    if ((int_year > 80) && (int_year < 100)) int_year +=1900;
    if ((int_year >= 0) && (int_year < 20)) int_year +=2000;

     

    But of course, in a full-scale disaster movie like this, the damage isn't limited to only the code - invariably, there's a database involved as well... 

    One day, the HPC was thinking deeply... 

    Hmm... how can we store stuff that can be on or off?

    Aha - simple: 

    SELECT * FROM ONOFFTABLE

    keycode text
    ------- -----
    0 OFF
    1 ON

    Just the flexibility we need to add

          3           FILE_NOT_FOUND

    at a future date! But, dang, the "text" column is only a VARCHAR2(5)... who needs pesky Boolean values. Also ironically, ono

     

    And there's plenty more...



  • Did you get carried away with anonymization, or was everything actually named foobar, which, and what?

    I could see either being the case, as this guy was coding for job security.  Don't worry, as soon as you finally snap, the HPC will be called back in at double the rate.



  • I like the built-in 2020 bug and hardcoded month names instead of querying the system. I hope that system doesn't handle mortgages stored in 2-digit format. Of course the whole thing should be using 4-digit years, but with code like that, I wouldn't be surprised if it doesn't.



  • I am weeping onto my keyboard. 



  • Oh, and, by the way: I tried to find the original FILE_NOT_FOUND post, but it seems to have disappeared. Can that be? Or I am looking the wrong way? Can anybody fill me in about the whereabouts of that article? 



  • That would be "[url=http://thedailywtf.com/Articles/What_Is_Truth_0x3f_.aspx]What Is Truth?[/url]"



  • @vt_mruhlin said:

    Did you get carried away with anonymization, or was everything actually named foobar, which, and what?

     

    Anonymized. The function names were pretty cryptic though.

     

    My personal favourite was an 1800 line function called "doit" - kind of gives you an idea of the level here.

     



  • @AbbydonKrafts said:

    I like the built-in 2020 bug and hardcoded month names instead of querying the system. I hope that system doesn't handle mortgages stored in 2-digit format. Of course the whole thing should be using 4-digit years, but with code like that, I wouldn't be surprised if it doesn't.
     

    There is a dedicate army of support Oompa Loompa's for this system. Innocent souls fed into the meat grinder as sacrifice to keep the beast operating.

    Nothing is consistent, so the date handling logic in one source file would be cut and pasted to another and "reused" as needed.

     



  • An enterprise system written in Objective C?

    Are you guys a Mac shop?

    Thats a WTF all in itself. 



  • @Jonathan Holland said:

    Thats a WTF all in itself.

    That Mac people would use Obj-C? I don't get it.

    If you mean there's anything wrong with the language, do tell. I'm kind of messing around with it, and would like to do something useful later on.

    Edit: Oh, you mean that they're using Macs at all. Duh.



  • @TheRider said:

    ...I tried to find the original FILE_NOT_FOUND post, but it seems to have disappeared...

     

    Very funny meta post! 



  • Not programming languages make WTF's, people do. Except you use <write your #1 language to bash here>.



  • @Jonathan Holland said:

    An enterprise system written in Objective C?

    Are you guys a Mac shop?

    Thats a WTF all in itself. 

     

    NeXT, more likely.  The financial industry invested heavily in NeXT in the 90s.  I'd imagine they still makes use of their legacy stuff, or port it to Cocoa/GNUstep.



  • @magetoo said:

    @Jonathan Holland said:
    Thats a WTF all in itself.

    That Mac people would use Obj-C? I don't get it.

    If you mean there's anything wrong with the language, do tell. I'm kind of messing around with it, and would like to do something useful later on.

    Edit: Oh, you mean that they're using Macs at all. Duh.

     

     

    I wish I had a mac so that I could fiddle with it then maybe I could make cool apps for my iPhone.  /cry 



  • @JukeboxJim said:

     Say which... what?

        
    if (what == 0) {
    // Code Block A
    }
    else if (what == 2) {
    // Code Block B
    }
    else if ((what == 1) || (what == 3) || (what == 5)) {

    if (what == 1) which = 0;
    if (what == 3) which = 1;
    if (what == 5) which = 1;
    }

    // Code Block C omitted for sanity/brevity

    if (what == 5) FooBar(position, 3);
    else doWibble(position, what);
    }

     

     

    Am I the only one who noticed the extra '}' in the code (bolded)?  (Perhaps that is a typo on the poster's part, but judging by the rest of the code...) 

     

    My first post, and I noticed the "Tags" box is fail; I can't type my own tag using the keyboard.  (I had to type the start of my tag then right-click->Cut to remove the extra text.)  Am I supposed to be allowed to?


Log in to reply
 

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