Tuesday, October 7, 2014

The Ghost--A Weird Look at Patterns


The Ghost
I yawned, cursing my choice of summer wear, the cold air from the air conditioning harshly buffeting my face as I sat, hunched over in my roller-chair, staring intensely at the object before my eyes. Said object, a laptop I overused and abused on a regular basis seemed intent on burning my face off as punishment, its bright radiation washing my face like a formless irritant.
I grumbled. “No one cares about how it works, it just does! He should be happy with that!”
The origin of my consternation lay in a lecture I had witnessed a day ago at college. A naïve student, I had wandered in, first day, expecting a droll speech about the importance of some vague concepts I would spend a year learning only to forget in the three hours of shaking and puking (of the hand and the knowledge, respectively on paper of course) that was the ritualistic end signifying a short period of release.
There’s an old saying—I forget where it comes from—, “If it isn’t broken—don’t fix it.” I can call myself, if not a fanatical, at least an ardent supporter of that principle. Needless to say, I wasn’t extremely enthusiastic when I spent two hours in a class where the singular focus was to impress upon the listener the importance of beauty in everything crafted. With my level of skill, that seemed the last thing I had to look for in anything I designed and frankly, I could not even fathom how others could devote their lives to that search.
My first reaction was of course to check to see if I had accidentally entered the wrong room but as the familiar faces could attest to, this was it. It was a class on Software Design Patterns. The main argument was that they were used to solve specific, recurring problems—a sort of ‘quick fix’, if you will, except that they were originally based on sound principles of design which caused these solutions to be more elegant than the usual meaning of the term would seem to indicate.
That was where the problem for me began. First of all, a pattern, I believed, was just a recurring theme and not something that necessarily solved any specific problem. My experiences with patterns in the past had, of course, taught me that most patterns evolved from some sort of need: Birds fly south for the winter to reach warmer climates, people smoke to de-stress and infants cry for food and changes in innerwear. But, as I had also seen, poems were written in a certain way, jigsaw puzzles were cut in a certain way and tiles, most strikingly of all had patterned designs on them that seemed more random that the actions of a higher being would seem to an infant.
Reconciliation seemed a distant dream—beauty, infinitely farther.
I sighed.
“Are you sure?”
I blinked. Adrenaline seemed on adrenaline in my body. I turned to find the source of the voice. A figure stood leaning against the closed room door, arms crossed, his features very familiar to me. I blinked again.
“Am I in the Twilight Zone?”
The figure snorted. “You wish.”
“Then how am I seeing myself over there when I’m here?” I questioned, proud of my alertness, despite my obvious descent in mental stability.
He smirked. ”It’s probably that drink you had on the way home.”
I frowned. I did remember having a questionable drink in a shady restaurant but for the life of me, I couldn’t remember where it was.
He strolled towards my bed, his gait resembling the deliberate saunter of a person who held a secret they were daring you to guess. His grin did nothing to dispel that notion. He finally rested, legs crossed and back to the wall, a yawn slipping out, mocking my curiosity.
I took the bait. ”Why are you here?”
He cracked his neck. ”You’re conflicted. I’m here to help.”
I smiled. At least my crazy was helpful. “Okay, what do you have to say?”
“You do not believe the need for beauty, for elegance and the needs higher than that of the body. Why not? Do you not acknowledge that they are important?”
I smirked. “He fed us some cock and bull about patterns being essential because they solved recurring problems and not just that—they did it beautifully, and that we should strive to achieve beauty in our creations. First of all, patterns have plenty of examples where they just exist without fulfilling any need. The next problem I have is that this beauty crap is not only secondary; it’s sometimes just a waste of time. In this hectic life if I stop to search for beauty, I’ll be eaten by the grotesque. Sorry, but I’ll pass.”
The figure—I shall refer to him as The Ghost—frowned. “Men far greater that you have pondered this question for lengths far longer than you can imagine, and they have come to this conclusion. You must relent.”
I snorted. “Convince me.”
He smirked in response. “And so I shall.”
The world twisted around us and I found myself in the lobby of a most expensive hotel.
“Right then!” The Ghost began, his hands clasped in glee. “Welcome to Paris! You are to arrange a stay for us for two nights, during which we shall visit the Eiffel tower, the Louvre, dine at the exclusive Lamp A and Sea Blue restaurants, taste wine at the Royal Orchard and see the opera. You must hurry however, as arranging transportation and tickets will take quite a while. They are quite hard as I am told. Don’t forget to find us the appropriate dress code. You will find money enough in your pockets. Now, chop chop! ”
I panicked and ran. Booking a room, I raced out into the city and went began my search. Immediately, I encountered my first barrier, bigger than all before or after it. I did not know the language and to my uneducated head, it seemed gibberish. I struggled for hours before I finally managed to find myself back at the lobby, having accomplished exactly zero productive tasks but managing to wet the carpets quite heavily.
I panted. “No…tables...all gone…in both…opera too, and I couldn't find a decent cabbie I could even talk to!”
The Ghost smiled kindly. “Not to worry, I’ve arranged for it.”
I blinked. “How?”
“The concierge of course.”
I felt a strong urge to slap myself in the face. Why hadn’t I thought of that?
“I had expected you to go there first, but since I saw you run out into the hostile city, I figured you’d fail so I arranged everything myself, just to be safe.”
I frowned. “I feel like there’s a lesson here somewhere. Is it ‘stop and think before you act?’”
He guffawed. “My boy! Welcome to the façade! The most useful concept man has ever used! It’s the lazy man’s dream, but also that of the productive man!”
I scratched my cheek. “This is one of those patterns isn’t it?”
He grinned. “Right in one! It’s an interface that allows you a one-stop access to multiple things. Convenience in a nutshell!”
I relented with a sigh. “Fine. It’s pretty useful, and it fulfills a need, and yeah, in a way you can consider it to be elegant.”
“I bet a poet would compare it to an octopus! Controlling the world with his eight arms! Ah!”
I tapped him on the head. “Let’s return.” With a snap, we were home. I fell to the bed, exhausted. Sleep was not far away.
It was late the next evening when The Ghost returned. I grinned. “Where are we off to, today?”
The world swirled. The hot sun beat down upon us. The first thing I noticed was an abundance of aeroplanes flying low. “Where are we now?” I enquired.
“Airport,” he quipped, not giving me much else. Four parallel runways lay before me, awaiting their guests. “Just watch.”
 Immediately, pandemonium ensued. People flew in all directions around me.
I paled. “What happened?”
“Possible bomb in one of the trucks on these runways.”
“What the…? The aeroplanes!” I turned my gaze skyward at the descending crafts. Confusion replaced my panic as every single aircraft swerved upwards away from danger all at once.
My mouth remained open for a few seconds. I looked at The Ghost accusingly.
“Red Button.” He explained. “Sends a danger signal to all aircrafts together. Implemented after the terrorist attacks.”
I crinkled my nose. “What’s the take away here?”
He gazed into the sky. ”Observer pattern. The planes lie in wait for the message and this change is simultaneously communicated to every plane scheduled to land or take off so that they can take precautionary measures. ”
I sighed in relief.
He grasped my shoulder. “Saving lives. Isn’t it amazing?’”
I concurred. We left.
It would be another week before I would meet my inner doppelganger. This time, he had on a most intriguing ensemble. It almost felt like we were headed for the beach.
In a flash—we were at our destination.
I gasped, clutching at my throat, the sudden dryness having caught me off guard. We had been transported to a town that was almost unquestionably situated in the middle of a desert.
“Come along,” he said as he motioned to the building behind me.
We walked in and I was immediately assaulted by the sweet aroma of delicious food. Mouth watering, we forced ourselves to move away from the smell into a larger hall. It was a wedding. We strolled, not minding the scores of people milling about like ants around us and made our way towards the couple who were on a stage. We silently took our place behind them and waited.
It took me a few seconds to realize what I had been brought there to realize. At first, there seemed to be nothing weird about the situation--normal wedding with normal people. It was only after a few minutes of observation that I realized what was out of place. There was a third person along with the bride and the groom who seemed to be butting in at every second sentence.
I frowned. “What’s that guy doing?”
“Watch closely,” was my only reply. I did. It was then that everything fell into place.
“He’s a translator!” I gasped. “They’re not speaking the same language!”
He nodded. “Adapter is what this is called in the business.”
I marveled at the scene for a few more minutes and then frowned. “Wait, wait, wait! I realize what is happening, sure, but if that’s the case, you could have just shown me an adapter that I use for my iPad charger! Why here? Is it not that simple?”
He giggled. “It is, but how often do you get to see love, like this, crossing boundaries galore! And besides, here the adapter goes both ways and he’s adapting the speech of both sides to the other. It seemed worth a mention.”
I palmed my face. We returned.
The next outing was to a place far stranger than any place I had ever been to till then.
“What is this place?” I asked, blinking rapidly to adjust to the weird lighting.
“We’re under the International Bureau for Weights and Measures building in Sevres, France.”
“And what are we doing here?” I asked, still grumpy about the discomfort.
“Look straight ahead.” Came the reply. I did. On a pedestal in the middle of the room—which I had by now noticed to be round and quite large—lay a cylinder.
We approached. It was a rather peculiar object, one that I could see was quite masterfully crafted, but no matter how hard I wracked my brain, I could not find a use for it other than maybe as an oversized paperweight.
“What is it?” I asked.
“The kilogram.” He replied.
I frowned. “That’s nice, it’s a kilogram in weight but what is it?”
He frowned at me. “Not a kilogram, the kilogram.” He stressed. I was confused.
He sighed and turned back to the object. “This is the cylinder that is used as the basis for setting one of the seven fundamental units in the International System of weights. This thing doesn’t weigh a kilogram, anything that is said to weigh a kilogram weighs as much as this. If tomorrow this thing were to lose a hundred grams in weight, the entire definition of the kilogram would change and everything in the world that weighed a kilogram till now would suddenly weigh more than that.”
To say that I gaped like a fish is to say that the Sun is somewhat warm. “This thing…? Wait…? The kilogram is based on a physical object?”
He nodded. “Of course you know what that means, right?”
I stopped. I didn’t know. “What?”
He looked at me gravely. “There can only be one.”
I nodded. I could envisage the pandemonium if there were ever more than one created.
“There are replicas, of course, because it’s quite inefficient with the number of people who need this thing. But, those replicas are periodically compared and reset to the weight of this thing.”
I marveled at the thought of such a linchpin. “But won’t this lose mass over time? Due to environmental processes?”
“Environment controlled room. And besides, they’re working on a Silicon ball to replace this thing soon. It’s already been constructed, I think. Interestingly, it is also the roundest object in the world. Once they replace it, that will be the only standard and it’ll take this platinum-iridium cylinder’s place.”
“Is there a pattern here? Because this is definitely a solution to a problem I’m seeing here.”
He closed his eyes and smiled serenely. “Singleton. Only one instance of this object in the world. Everything else has to conform to this thing. Quite the responsibility.”
I agreed. The singleton bestowed a life of immense power, but added immense load along with it.
With that thought, we were out.
It was two days after the last event that The Ghost reappeared, interrupting me in the middle of my dinner. He seemed to be fingering something in his pocket.
“We haven’t time to dilly-dally.” he declared and with firm hand on my shoulder, we were off.
We appeared in a bright room, with all the markings of a dull and boring place.
“What is it?” I asked.
He pulled out some cash from his pocket, stuffed it in my hand and took over an unoccupied chair. “A travel agent’s office. And lo and behold, here is the line. Now go and stand in it. Buy a ticket to Goa.” I did.
The line was not too long. There were three people in front of me and one of them had just been handed a printed ticket. It was not long before I was up.
“What’ll it be?” asked the lady behind the counter. If she enjoyed her job, she hid it well.
“A ticket to Goa, please.” I handed her the money.
She accepted it, punched in a few numbers and handed me my ticket. I returned to my companion.
I took the seat next to his. “Now what?”
He motioned with his head. “Look at those two.”
I did. They were the two men who had bought tickets just before I had, and they were animatedly chatting away, their tickets resting on the table next to them.
“What about them?” I ventured.
“See how their tickets differ from yours,” he said.
I frowned but complied nevertheless.
Trying to look as inconspicuous as possible, I walked up to them pretending to search for something. I glanced at their tickets. They spared me a glance but not more.
I quickly rushed through the two tickets trying to spot anything conspicuous and when I hit the fourth column, I nearly gasped. I quickly returned.
“One of them has a Mercedes picking him up to the airport!” I barked. “And the other’s getting a taxi.”
I pointed to my ticket gesturing heatedly. “Why do I have just a bus? I didn’t see them ask for any of this and they’re going to Goa too!”
He looked at me pointedly. I blinked. “Oh…it was the amount of money we handed the lady, right?”
He gestured towards a chart on the wall, that I had somehow missed.
I squinted. “First class ticket buyers get a Mercedes pickup, huh? And business class guys get a taxi. Poor me, I’m stuck with the bus.”
I sighed. “I guess it makes sense to entice them that way.” I sat with my arms behind my head. “It’s just good business strategy.”
The grin on The Ghost’s face was the scariest thing I had ever had the misfortune to lay eyes on. Were I a director for a horror flick, I’d have been a fool to let him slip away.
“Well, well, well, it seems you get it. The second she entered your amount into the computer, it allocated you a bus.”
“What’s this pattern now?” I asked, longing to get back to my dinner.
He laughed jovially. “Why it’s called the Strategy pattern, good sir!”
I blinked and joined him.
Life had, once again, proved to be just quirky enough to be fun.