Home > Basics, Programming > Worst way to do a sum

Worst way to do a sum

I’m dealing with some seriously bad code. It’s sort of like this.

Suppose you need to add two integers in C:

    int sum(int x, int y)
        return x+y;

Let’s not even consider nastiness like int limits, just a plain sum that works. That above is the sane way. That’s how you work. You do a single, tiny function that does a single job well.

This is the legacy I’m dealing with:

    //Declared globally
    int sum1 = /* a value */;
    int sum2 = /* another value */;
    int sum; /* the result */
    sumx(); /* execution */
    void sumx()
        sum = sum1+sum2;

Technically, it works. Same result. What’s the difference? Maintainability.

Categories: Basics, Programming Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: