A Bug in Three Acts

I was pleased to have found an obscure bug that had created much fear and suffering. By obscure I mean hard to explain in the way that I know it. Here I reflect with an analogy to theatre.

I'm fond of the theatre and especially like a three act play with strong characters. Act I, we learn of the characters, Act II, they face the challenge, Act III, the consequences of things, small things, are shown to be of profound importance.

Act I

If I told you the characters were an artist, a teacher and a soldier on leave then you would already know something. The setting matters too. 50's America or 30's Europe. It makes a difference. Still people are people.

My characters are techniques. In order of appearance: defensive code; object-oriented programming; model-view-controller; test-driven design; agile-software-development. The action takes place in Javascript.

Our story opens in a new Wiki with Story and Journal which are populated with objects that talk about each other. Create makes the Story as it begins, often empty, but sometimes fully formed.

The objects work is hard so change is underway. The object will model the work of wiki but not do the work, that will be left to views and controllers. Such agility is expected in Javascript.

Act II

Create knows the Story when it serves an importer. But most often it creates an empty story which might be known as null, or [ ], or nothing at all. In defensive style we treat all the same.

Journals merge to tell a bigger Story. Creates must accept the Story before them. We ask these objects to work new ways. They appear to obligee.

Suspicious as we are we set up tests. We test the tests then test the objects, first one by one, then in elaborate workflows. The objects can be tricky so we test them harder, harder than they worked before.

We deploy. We hear trouble in the distance. The Story is sometimes scrambled. Many possible explanations.

Act III

Word of the Wiki's greatness spreads. With it fear among its proudest supporters that there will be more scrambling.

A scramble is caught in the act. We watch it happen. Step. Step. Step by step. The Story transforms as if without aid of Journal. How can this happen?

Step. Step. Step some more. The Create was the only one in the room and scramble still happens. Ah, but wait, [ ] is there too, posing as nil, nothing, the empty story to be created. But [ ] is an object with a will of its own. An accomplice. And it transforms itself in place thereby perpetrating the scramble.

Epilog

The scrambles, the suffering it caused, and the fear that scrambling would return were the direct result of accepted and admired practices, traits of our characters.

Some will blame the shifty ways of [ ] and want to leave Javascript entirely. But they miss the true moral.

Our characters were all respectable and behaved in respectable ways. But when interactions compound, as they do whenever we build anything of substance, small decisions have impacts only easily told in retrospect.

The fix required the addition of one word. There is a pull request. github