Friday, March 16, 2012

Rubber duck debugging

I was reading yesterday about Rubber Duck Debugging, in the context of Stack Overflow. The scenario, which has happened to me several times, is as follows:
  • Programmer is stuck
  • Programmer writes a description of the problem to a help desk
  • Whilst writing the description, the programmer realises what the problem is and how to fix it
  • Programmer deletes the letter to the help desk
I went through a version of this today; following is the background. For one customer, we have to print sticky labels with identifying details on the label (this of course is not a problem). The problems start when one of our factories produces three sub-assemblies which together make up the part which the customer ordered. My program was printing three labels (so far, so good), but I was asked to serialise them (which means printing on the first label 1/3, printing 2/3 on the second label, and 3/3 on the third label).

The external program which we use to print the labels has the capability of serialisation, but this is slightly limited. Let's say that I had to print two labels for one part and another two labels for a second part. The labels should bear the tags 1/2, 2/2, 1/2, 2/2. Unfortunately, the external program was printing like this: 1/2, 2/2, 3/2, 4/2. No matter what combination of flags I tried, I was unable to print what I wanted.

Then I called the help desk - they noted my details but promised nothing.

Thinking about the problem a little more, I came to the solution. The ERP program was inserting into the 'labels' table two rows, where each row was to be printed twice. The simple fix was to insert into the table one row for every label to be printed, where each row would be printed once. I also included the total amount of labels to be printed for each part (I know that this is a seriously muddled explanation, but all will soon become clear). Now I get the results that I want.

Before:
Part numberQuantity
1232
5672

After:
Part numberQuantityNumeratorTotal
123112
123122
567112
567122

All I needed was the metaphorical (apocryphal?) rubber duck in order to look at the problem from a slightly different angle and so find the solution. All of these problems (like the Excel comments problem which I wrote about the other day) seem totally trivial after they have been solved, but they are very confusing beforehand.

No comments: