0 Replies - 483 Views - Last Post: 27 June 2013 - 08:39 PM Rate Topic: -----

#1 Orthoducks  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-June 13

The misaddress processing module

Posted 27 June 2013 - 08:39 PM

This happened about 40 years ago. A lot has changed, but the nightmare code experience has not.

I was assigned to do some cleanup to an address processing module written by a fellow programmer who had left the company. Knowing my inclinations, my boss said, "Don't rewrite it! Just fix it so that it handles this case correctly."

I looked at the code (it was in IBM System/370 Assembly Language) and knew it was trouble. It was what was known, in the days before structured programming, as "spaghetti code." There were jumps all over the place, with no order, and of course, virtually no comments.

After I spent some time teasing the module's logic apart, I came across something that made me think, "Wait. If I understand what's happening, this section can't ever be executed!" It wasn't as simple as "There's no branch to that label," but the code that could call the section in question had logic which ensured that it never would.

I did some testing and discovered that I was correct.

Somewhere in this adventure I did some timing tests and discovered that the module was consuming an average of 8 milliseconds of CPU time per address. This was on a computer that was slower than molasses by today's standards, but the shop had to process about 1.5 million addresses per day, and the number of milliseconds in a day was just about the same then as it is now. It meant that the system was spending about 15% of its cycles processing addresses in a shop where address processing was considered a necessary but minor bit of background work.

After some more study, I came across something that made me think, "Wait. If I understand what's happening, this will do something totally ridiculous with such-and-such a use case." (I didn't think "use case" because use cases hadn't been invented yet, but you know what I mean.)

I did some testing and discovered that I was correct.

I showed the case to my boss, and he said, "OK, good. Fix that one too."

I kept poking at the code and found another case that it wouldn't process correctly. Then another. And another. When I got up to about 15 cases, my boss said, "OK, you win! Rewrite it!"

The story had a happy ending. I approached the problem systematically, and did a job that I was proud of. The finished module not only processed all of the cases correctly, it did so more than ten times faster than the old one.

Ten years later, when I taught myself C, I rewrote the same program in C as a learning project, using the same logic. And fifteen years after that, when I taught myself C++, I did it again.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1