If someone comes up to you and says that they work in the video game industry you might think that he or she has an interesting job (and if you're a gamer, then it sounds they have an AWESOME job). Surely, in between marathon video game playing sessions, they would be working with some true geniuses on really cool programs instead of working with the regular schmoes maintaining the Batch Load Processing Report - right? Well, wake up from that dream, bucko.  The same bad coders from whom you inherited that insipid, "enterprise level" application get to make video games while you slave away for "the man".

Consider Andy Goth's submission.  After successfully integrating a flight simulator with an image generator and making it a sparkling gem of efficiency, maintainability, and clear documentation, he was given the task of documenting the high-level architecture and low-level implementation of which the following code is a part of.  In between writing Doxygen comments saying "This function does nothing" or "Use of this macro is a syntax error" or "Using this macro on the left-hand side of a multiplication will result in zero", considered if it would take longer to finish his documentation or ask management if he could throw away the old code and rewrite the entire application from scratch.

 

#include "API.h"

class Obj1 {
public:
    static int data;
    Obj1() {data = 0;}
};

class Lib {
public:
    API* api;
    Obj1* obj1;
    double data;
    bool active;
    Lib() {data = -1;}
    ~Lib() {}
    void initialize();
    void initObj1(Lib*);
    static void callback(void*);
    static void updateObj1(Lib*);
    static void update(Lib*);
    static void input(Lib*);
    static void output(Lib*);
};

Lib* lib = NULL;

void Lib::initialize()
{
    api = new API();
    obj1 = new Obj1();
    initObj1(this);
    api->setCallback(&callback, (void*)this);
}

void Lib::initObj1(Lib* self)
{
    self->obj1->data = 0;
}

// Invoked by API::transmit() since it's registered with API::setCallback().
void Lib::callback(void* data)
{
    static Lib* self = NULL;
    self = (Lib*)data;
    self->active = true;
    lib = self;
}

void Lib::updateObj1(Lib* self)
{
    static Obj1* obj1 = NULL;
    if (self->obj1 == NULL) {
        return;
    } else {
        obj1 = self->obj1;
    }
    cout << obj1->data++ << endl;
}

void Lib::Lib::update(Lib* self)
{
    if (self->api == NULL) {
        return;
    }
    input(self);
    updateObj1(self);
    output(self);
    self->api->transmit();
}

extern float DATA;

void Lib::input(Lib* self)
{
    self->data = (double)DATA * (double)-1.0;
}

extern bool STATUS;

void Lib::output(Lib* self)
{
    if (self->active != STATUS) {
        if ((self->active == false) && (STATUS == true)) {
            STATUS = false;
        } else if ((self->active == true) && (STATUS == false)) {
            STATUS = true;
        }
    }
}

// Repeatedly invoked by main loop.
void update()
{
    static bool first = true;
    static Lib* myLib = NULL;

    if (first) {
        first = false;
        myLib = new Lib();
        myLib->initialize();
        myLib->api->transmit();
    }

    if (lib != NULL) {
        myLib->update((Lib*)lib);
    } else {
        myLib->output(myLib);
    }
}
 

 

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!