M*A*S*H and Single Responsibility

If you haven’t heard of the TV show M*A*S*H, it’s based on an equally excellent movie by the same name. It has exactly nothing to do with coding, software development, business, or anything else you might think is germane to this blog. Except that I watch a lot of it (may have even gotten a Hulu subscription JUST to take advantage of their recent acquisition of the show). Like most art you consume a boatload of it will eventually worm its way into the rest of your life.

Most recently, I had to use a Charles Winchester quote to remind myself of the Single Responsibility Principle.

“I do one thing at a time. I do it very well. And then I move on.”

— Major Charles Emerson Winchester, III

You see where this is going, right?

My bread and butter right now is Azure webjobs. Continuous, queue-driven little background programs that are more Azure SDK code than anything I write. Mine do a variety of things, from processing data after updates, to performing proprietary analyses, to calling stored procedures on various databases.

I fell into a bit of a trap a few months back, where I didn’t really want to access a resource twice to do two similar operations on the same dataset. At first glance, it seemed naturally to just combine these sibling processes into one webjob and save the hassle of a second queue and all the time spinning up an additional webjob. I’ll just have one webjob do two things!

“Mmmmm. Stupid man.” — Eddie Izzard

Almost immediately this split-personality webjob made me question my competence, my sanity, and my fitness to be a productive member of society. I had to rework one of the processes three times in rapid succession to account for new requirements. Each time I had to contort the code into increasingly bizarre shapes to keep the two processes coupled. This single webjob, at one time, was taking a queue message that had 5 arguments and split into 8 possible subsets of logic.

I was still getting the desired outputs in an acceptable time frame…but there was zero maintainability going on here, and every change I had to make was exponentially more stressful than the last. This was not software designed by a professional; it was something else altogether.

A blue dumpster in front of a concrete wall with flames and smoke rising from it
I think this sums it about up.

Fast forward to us deciding to build on what this weird, out-of-control, not-so-little webjob does. We’d essentially use this monster of mine as the starting point for several other processes that were tangentially related to each other. If you’re fighting the urge to fling a phone across the room, slam the laptop shut, or fling coffee at your monitor in an effort to avoid learning what happens next–I understand, and I offer blunt foreshadowing: it does not end in tears.

Fortunately for me, a very special episode of MASH was playing soon after I got the run down on the project. This was the episode where we meet Winchester, a fancy pants, highly skilled surgeon. He insists he will not rush through surgery. “I do one thing at a time. I do it well. And then I move on,” he tells Hawkeye and company. That’s about the point it clicked for me.

The way to avoid another decent into madness like the nightmare I described above wasn’t to consolidate similar processes–it was to find as many different processes as I could, isolate the hell out of them, and handle them all separately with an absolute minimum of coupling. Man did I feel like an idiot.

It became my mantra over the next couple weeks as I sketched out my plan and dove in. “Do one thing at a time. Do it right. Then move on.” Every time I had a thought of “Well we could just do this at the same time and skip the–” I just pictured good old Chuck, rolling his eyes disdainfully.

David Ogden Stiers in his army uniform and lab coat against a camoflauge background from MASH
Somehow more effective for me than any number of minutes going “Wait which almost-identically-named method does the thing I actually need?”

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

Blog at WordPress.com.

Up ↑

%d bloggers like this: