Saturday, November 17, 2018

Deja Vu and a Significant Number of "Why"s

The pattern seemed to repeat itself, possibly forever.

Again, Samantha sat in the darkness, with only the pale light of her laptop to illuminate her surroundings. Again, she was hunched over in concentration.

She leaned toward the computer and peered at the alien script through narrowed eyelids. It was a symbolic act, an expression of her focus more than an amplifier of it.

Kramer Code had struck again.

It had become a constant in her life.

On the phone, earlier that night her husband remarked that Kramer got more of her attention than he did. The back of her mind recognized he was only half joking.

Samantha had confirmed and rebutted in four words: "Attention? Yes. Affection? No."

The truth of it stung her, though.

Why should she have to stay late because he can't seem to get anything right?

Why did he always check in just before a release?

Why did none of the tests ever catch what he was doing?

The team had become so tired of it, that they turned on pull requests. The branching made things a lot slower but they hoped that requiring a certain number of approvals to merge might help.

Somehow Kramer always got around it.

Usually, the approvals came from another office in another part of the country or even on the other side of the world. Sometimes, Kramer bamboozled a manager into granting him a variance to let him merge something that was an emergency.

As with most of Kramer's code, the change was nearly irreversible. You could go forward, meaning fix what he had done, but you couldn't go backward.

In this case, as was most of the cases, the code misused some data fields, redefining their meaning in the process.

Reverting the Kramer Code would produce an application that was still broken because the old version of the application couldn't use the new data and there's no easy, automatic way to reverse the change to the data.

Kramer had left Samantha between a rock and a hard place: fix the code or fix the data.

There was no "go back to green". Not for the customers who failed to back up before updating, which is most of them. Not for the customers who want to keep any of the data they have collected since, which is the rest.

Kramer Code was usually just hard enough to deal with that she could crack it but, this time, she was at a loss. It looked, to her, like Kramer had created irreparable data loss.

The only thing Samantha could imagine was to fix the code, create a space for the lost data, and create some kind of migration utility that allowed customers to merge the data they had lost out of a backup.

That was the path of least destruction.

Samantha fired off a note to Fred. Without a body, the message read "Should we forcibly back up before every update?"

She let her mind relax and her focus slackened. Idly, she clicked around, bouncing from class to class. She was thinking but not really about what she saw.

Then she saw something that snagged her attention.

It was a little class called DataTransformMediator. Something kind of strange. Without drilling into the classes to which it delegated, it appeared to copy data out of some entity objects and into a malleable document which would be stored in a non-relational database.

What caught Samantha's eye was that the mediator in question seemed to be coordinating preservation of the exact fields she thought Kramer had destroyed.

She was already VPNed into a client's network, so she opened up their DocumentDB instance and searched for the records related to an affected entity.

"I'll be damned..." she said. "Gotcha."

She minimized the virtual desktop, exposing Visual Studio and started creating a new utility. One that would clean up the affected document databases, repair the affected structured databases, and rollback the Kramer-affected deployment all at one time.

A blinding glare flooded through the window from what appeared to be a yellow ball of hellfire snuggled between two gigantic pines.

"Morning," said Samantha. "Guess I'll get to it."

A parking lot with the sun peaking through between two pines.

Friday, November 16, 2018

New Barista

A manager shouting at one barista that all his drinks get sent back and the barista's defense being that he makes twice as many as another barista named "Rick". Nearby, rick carefully places a drink on a counter.

The other day, I ran into Starbucks to get something for my wife. She wanted a Brulee Latte.

It was the end of the day and the more seasoned baristas were letting the new guy make what appeared to be his very first drink.

I thought to myself. "Great. Lucky me."

The guy took a long time but I'm glad he did. The reason he took so long was that he was making sure he did everything exactly right.

He double-checked the mixture to make sure he had the right number of shots. He carefully distributed the whipped cream to make sure it was done correctly. He tried shaking the large-grain sprinkles on to three different ways before he found a technique that got the right amount out of the shaker.

By the end of watching him make the beverage, I thought to myself "This guy's going to be alright."

Sure, it took him a long time to make my drink but it would have taken even longer to make it a second time after I sent it back for not being done correctly. He avoided that extra cost immediately but there's an even more important benefit to the way he went about making that drink.

The next time he has to make a latte with sprinkles, he'll use the technique he learned making the one I bought. As a result, he'll be a little faster. He'll carefully apply the whipped cream in the same pattern but he'll be able to do that a little faster, too.

Maybe he'll keep double-checking the number of shots a few more times but, eventually, he won't need to do that, either.

Every time he makes a drink, he'll make it just as accurately as the first time but he'll be able to do it a little more quickly. Eventually, he'll be fast and good.

If he'd focused, instead, on getting some sloppy splash of liquid out the door, he probably would have taken longer in the short run and it's doubtful that he'd get any faster or more accurate in the long-run. Had he made that choice, he would have flunked out of Starbucks.

I doubt Starbucks is this guy's ultimate career path - although it may be. Yet, wherever he goes, I'm sure the kind of decision making he exhibited that night, making that first latte, will serve him well.

Bon chance, barista whose name I didn't think to catch.

Thursday, November 15, 2018

For Any Pattern: "Does This Allow More Objects to Each Deal with Fewer Things?"

An expert woodsman or carpenter is better than one person who does both...at least in code.

One of the principles of design patterns thinking is favoring delegation between objects over inheritance from one class to another.

I think we can actually expend that if we want to:
Favor delegation between objects over the same object doing two things.
Remember, when you inherit you end up with one object even though you wrote two classes. So the way I just wrote it still works for inheritance but it also works for, say, lumping everything together into a giant algorithm.

Note: Not more classes. More objects.

If you are considering a design pattern for your codebase and you're not certain if it applies, ask yourself this:
"Does this allow more objects to each deal with fewer things?"
If so, you may be headed in the right direction. If not, maybe consider a different approach.

Wednesday, November 14, 2018

For Any Pattern: "Does This Make Something Less Aware of a Kind of Variation?"

A car is on a road. There's a dirt road leading off to the left between some trees. A passenger says "They said turn left at the trees!" The driver says "I can't. I don't know how to turn left onto a dirt road."

If you have alternatives - different kinds of things that can be used to replace one another or, sometimes combined with one another - then you have variation.

Design patterns thinking tells us that we should encapsulate variation. That's the kind of thing that is obvious once you already understand it (the hallmark of a good idea) but turning the advice into action can be challenging for people at first.

The immediate goal isn't really to make code less aware of the fact that there is variation so much as making your code so it doesn't need to change when you add or subtract a variant.

So, it's not that we're trying to hide variation altogether. We just want to minimize its impact on most of the code. We are seeking to lessen awareness, not eliminate it altogether.

If you are considering a design pattern for your system, and you aren't really sure if it's the right way to go, ask yourself this:
"Does this make something less aware of a kind of variation?"
Or...
"Does this make something less aware of the variants in a kind of variation?"
If the answer is "no", you aren't attending to the fundamental value-proposition of design patterns thinking and there's a good chance you should be considering another path.

Tuesday, November 13, 2018

For Any Pattern: "Does This Help Me Couple to an Higher-Level Abstraction?"

A sign indicating the steps to use a gas pump: insert dinosaur, age 100,000,000 years, refine gas, fill car.

One of the things that design patterns thinking is supposed to help you do is elevate the level of abstraction in your code. That doesn't just mean "write more interfaces" or "use ore abstract classes/protocols".

What it means is try to move the points of coupling away from the metal. The more a coupling point is about implementation details, the less useful it is and the shorter is helpful life will be. That is especially true an high-traffic interface but, really, it's true for the surface area of any piece of code.

So, if you are considering a design pattern and aren't quite sure if it applies to your situation, ask yourself this question:
"Does this help me couple to an higher-level abstraction?"
If applying the design pattern will make the interfaces (not the keyword interface, the English word "interface") a little more about "what" and a little less about "how", you might be on to something. If it cuts the other way, you may want to reconsider.

Monday, November 12, 2018

Honesty

I think that most of the misleading information in the world stems from people not being honest with themselves. I don't know that I could prove it for the whole of mankind but I think it would be pretty easy to design an experiment that showed this to be true for businesses.

The someone asks you a question and your answer is self-congratulatory, take a beat and ask yourself if there are any other answers that might make sense.

A person looks in a mirror with an angry mob behind it and says "Look at the happy person!"