There is plenty of drama in the process of software development, yet little theater or poetry about it. Poems are written on the heroic deeds of warriors, lovers and explorers; why not on those of software engineers?
I was previously a longtime software developer at Microsoft, and I’m often asked what that was like. So to give friends and family a flavor of the job, I wrote the poem below about fixing a Windows bug. It’s a fictitious story based loosely on many real-life experiences.
The Windows Thread that Wouldn’t Go to Bed
By Anirudh Sahni
There was once a Windows thread
That refused to go to bed
When politely told its time had come to exit,
For it liked to stay up late
In a SingleObjectWait()
For a semaphore with no-one left to set it.
When this thread so overstayed
System shutdown was delayed
And our team could not release the second beta,
Which the PMs and the testers
And the company’s investors
Said we’d better get out sooner and not later.
Now we couldn’t risk the fate
Of a ProcessTerminate()
While the other threads might still have work unsaved;
So we set a kernel trap
In the function KillWinApp()
To observe it right before it misbehaved.
And we blocked there sure enough
But found diagnosis tough
For it hung on us as soon as we hit go,
And we still could not be sure
Who had not SetSemaphore()
So for all our labor nothing more did know.
So we turned on DebugTrace()
But the execution pace
Was then slowed enough that everything just worked,
So despite all else we knew
From the debug output spew
The infernal bug still in the system lurked.
Droned an elder of our floor
Whose advice we sought him for,
Nodding sagely, “Got yourself a race condition.
Using libraries is wise,
Not this rush to optimize.
You’re a needless victim of your own ambition.”
Frowned another, “What d’you think?
DCs do get out of sync.
Serve you right for coding down the wrong trajectory!
For our docs are very clear
That delays can be severe:
We’re not ‘Active Database,’ we’re a Directory.”
Crowed alumni of Research
From their supercilious perch,
“You are fretting over bugs of yesterday!
Write in C-sharp and you’ll find
You enjoy more peace of mind.
Managed code makes all these problems go away!”
Losing patience with suggestions
Raising answers less than questions
And prejudging our investigation failed,
With an ounce of inspiration
Ninety-nine of caffeination
And a stack-scavenging quest, we had it nailed:
While a relic of the past
Known as WM_BROADCAST
Was alerting all who listened would our thread block,
And the problem therein lay,
For at times the Plug-and-Play
Service calls to us, and lo, we have a deadlock.
The old author of this mess
Had kludged it quickly to impress
And departed, with the glory and a bonus,
While our egos took a beating
In the daily war team meeting,
For to clean it up was left on us the onus.
To get all the ducks in line
We proposed a redesign.
Cried the leads, “We can’t take such a schedule hit!
Coding lockdown has begun
And you’re starting from square one?
There has got to be a quicker retrofit!”
Thus arose a compromise that
Drove us to philosophize:
Intercept the call with yet another thread!
Wrap the bloat in still more code?
Kick the problem down the road,
Turn performance tuning tenets on their head?
Hard we won the knowhow to
Pay the fiendish scheme its due:
Exorcize it in a final cleansing chop.
Should it yet more cycles steal
In a war room sweetheart deal?
Haunt us more in version 4? When would it stop?
War team said this RAM abuser
Would be better for the user,
And the reasons that they offered were compelling:
A design that never ships
Always runs at zero MIPS.
Is it useful being clean if you’re not selling?
Even bloating to a whopper
Cannot count as a showstopper
When enabling required functionality;
Besides, the cost of hogging store
Grows ever less, by Laws of Moore.
Hence idealism must yield to practicality.
And that’s how it came to be
That on nights when your PC
Lies reposing with the screen a quiet black
And not e’en a mouse is stirring,
All at once your disk starts whirring
To run ShutdownBroadcastDeadlockBreakerHack().
Anirudh Sahni is a software engineer and a former longtime member of the Windows development team. He lives in Seattle and believes that engineers need not restrict their creativity to engineering alone. © 2015, Anirudh Sahni; republished with permission.