All posts by The Codeless Code

Case 234: Ozymandias

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/234

The nun Hwídah has composed this uncharacteristically
somber sonnet for your contemplation:

I chanced upon an ancient cache of code:
a stack of printouts, tall as any man,
that in decaying boxes had been stowed.
Ten thousand crumbling pages long it ran.
Abandoned in the blackness to erode,
what steered a ship through blackness to the moon.
The language is unused in this late year.
The target hardware, likewise, lies in ruin.
Entombed within one lone procedure’s scope,
a line of code and then these words appear:

# TEMPORARY, I HOPE HOPE HOPE

The code beside persisting to the last—
as permanent as aught upon this sphere—
while overhead, a vacant moon flies past.

Editor’s note

Inspired by this story of the Apollo Guidance Computer code for Apollo 11,
and
this code within,
and Percy Bysshe Shelley’s Ozymandias of course.

I tried to keep to Shelley’s unusual (and non-standard)
rhyme scheme for the sonnet, but I departed from it in the
second-to-last line for poetic reasons. For a language
which excels in stealing words from other cultures, English
has an appalling lack of rhymes.

* Special thanks to Dan Sutton for pointing out a most embarrassing typo.

Case 233: The Falling and the Rising Rain

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/233

Two monks were arguing about the best way to implement two
somewhat-similar workflows in their application. They went to the
visiting master Suku to settle their dispute.

The first monk said,
“I believe we should implement both workflows separately
to keep them from constraining each other.
When all work is done
we can identify the common parts,
and combine them into generic base classes or utilities.
If similar workflows are desired in the future,
we will follow this process:
design each new flow independently,
make use of the generic code where possible,
and combine workflow-specific code
into generic implementations when appropriate.”

Suku said to the first monk,
“This is a most natural approach.
When it rains on the mountain,
tiny droplets cascade down the stones.
As the waters descend into the valley,
ten thousand rivulets merge
into a thousand brooks,
then a hundred creeks,
then ten streams,
then one mighty river.”

The second monk said,
“I believe we should implement both workflows together,
using their features to define a generic framework.
When special cases or alternate flows arise,
we can abstract them out as configurable features,
or add hooks into the framework as appropriate.
If similar workflows are desired in the future,
we will follow this process:
implement each new flow using the framework,
and if this proves impossible,
split the framework’s generic implementations
to allow workflow-specific code as needed.”

Suku said to the second monk,
“This also is a natural approach.
When it rains on the mountain,
tiny droplets nourish the roots of the sapling.
As the mighty oak ascends toward the heavens,
one trunk divides
into ten boughs,
then a hundred limbs,
then a thousand branches,
then ten thousand twigs.”

Both monks bowed and turned to leave—their argument still unsettled—whereupon Suku sighed in frustration
and rapped the backs of their heads with her staff.

“Monks!” she said to the pair.
“If the world were wiped clean except for mountains and rain,
which would arise first: the river, or the oak tree?”

Case 232: Education

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/232

For years the young monk Djishin had been apprenticed to
old master Banzen. Although this was a privilege it
brought Djishin little joy, for lately the master had been
growing visibly irritated with the young monk. Yet the monk
could not fathom the reason.

One morning Djishin said to his fellow apprentice Satou:
I have committed Banzen’s teachings to heart and perform my
duties according to his example, yet his disdain for me is
palpable! And whenever I ask if I have done anything to
incur his displeasure, he tells me No! I am at my wit’s end
with the old man!

Satou replied: If you can no longer march uphill, then the
way forward is not in front of you.

Djishin said: I cannot quit his service any more than I
could bite my own legs off. Yet my patience has waned to
the thinnest sliver. Soon, I fear, the master will push me
too far, and I will surely rebel.

Satou replied: Then run from the path and don’t look back;
for I cannot see your rebellion ending well for anyone, except
perhaps the undertaker.

- - -

Not long after, Banzen was reviewing Satou’s code and noted
that she was now using Java’s new Optional class
practically everywhere. Banzen scolded the nun for her
usual habit of playing with novelties instead of focusing
her efforts on building a reliable implementation with
customary patterns.

Overhearing this exchange, Djishin felt the last dregs of
patience drain from his body.
The monk spat: Optional is no passing fad; it is Java’s
implementation of the Maybe monad, and any fool who truly
cares about reliable implementations would do well to
follow the nun’s example!

There followed an awful silence. No one moved.
Djishin could feel his heart pounding in his ears.

Finally the master arched a bushy white eyebrow, saying:
And what—my impertinent, former apprentice—is a Monad?

With a shaky voice, Djishin explained the nature of monads and
how he had learned of them.
When he finished, Banzen strode over to the monk, raised his staff,
and flung both arms around the boy.

At last! exclaimed the master.
I have been wondering whether I’d trained a monk or a mockingbird.
Now I can say to the other masters: on this day I learned two things,
for at last Djishin told me something that I did not know.

Case 231: Laziness

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/231

The head monk of the Swooping Falcon Clan asked master
Banzen for assistance with a difficult customer. The
customer was a maker of silk-and-bamboo kites, and the
clan’s application allowed her to curate her large online
catalog.

“I simply cannot make her happy,” complained the
head monk.

“Tell me what makes her unhappy,” said Banzen.
“Then perhaps you can do the opposite of that.”

“Laziness,” the head monk declared; “for she says that our
interface makes her do too much work, yet the work
is her fault, not ours.”

“Explain,” said Banzen.

“First,” the head monk said, “for each kite, she wishes to
allow only certain silks. So our interface must have her
specify the silks on a kite-by-kite basis—yet always she
says this task is too tedious. It is not our fault that she
is so particular!”

“Indeed,” said Banzen.

“To make matters worse,” the head monk said, “she has
hundreds of bolts of silk in her shop, of which
dozens may be offered for any given kite! We have tried
every widget in our library—multiple-selection lists,
dual listboxes, typeahead-enabled drop-downs—yet always
she says this task is too onerous. It is not our fault that
she offers so many choices!”

“Absolutely,” said Banzen.

“Finally,” the head monk concluded, “new silks are always
being introduced and old ones are always being retired. So
she must revise the list of silks for each kite throughout
the year—yet always she says this task is too burdensome.
It is not our fault that fashion is fickle!”

“Agreed,” said Banzen.

So Banzen went to see the kite-maker.

- - -

The kite-maker’s complaints were exactly as the head monk
described. After hearing them, Banzen wandered her workshop,
and indeed found many hundreds of bolts of silk, each
a different pattern and hue.

After pondering a moment, Banzen pointed to the bamboo
skeleton of a kite on her workbench.

“What silks will you offer for that one?” asked Banzen.

“Blue cloud designs only,” said the kite-maker. “But I
have dozens of silks with blue cloud designs.”

“And that one?” asked Banzen, pointing to another.

“That is one of my ‘crow’ series,” said the kite-maker.
“Blue feather designs or black feather designs, but no
lightweight silks.”

“And that one?” asked Banzen, pointing to another.

“That is one of my ‘dragon’ series,” said the kite-maker.
“Black solids, red fire designs, or white earth designs,
but no heavy silks.”

When he was certain that he understood the kite-maker’s
algorithm, Banzen returned to the head monk.

- - -

“It is as you described,” said Banzen to the head monk.
“What makes the kite-maker unhappy is laziness.”

“Yet how can she be corrected?” asked the monk.

“Wú,” said Banzen, producing a thick envelope from his robes.
“Here is the means of correction, which I will deliver
to you each week until the kite-maker has achieved happiness.”

In one quick motion Banzen tossed the contents of the
envelope into the air. Hundreds of minuscule squares of colored
paper spiraled gently down around the room; each like a
tiny kite adrift on the wind.

“Lovely,” said the head monk, “but what is it?”

“It is called confetti, said Banzen. “I made it from your
week’s pay. Using small bills, of course.”

Case 230: All Together Now

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/230

The Hungry Worm Clan was building a website
for a craftsman who made custom farming tools.
Young master Zjing was reviewing the code
of their three developers.

“I do not understand the purpose of the LatestSellByDate property
in your shopping cart’s PurchaseItem,” she said to the three.
“Shovels and rakes do not expire.”

“That property was requested by the Red Pebble Clan,”
replied the first monk. “They are building a system for
managing a merchant’s cherry farms, and they plan to use our
order-placement service instead of building their own.”

“What?” asked Zjing in disbelief. “Who suggested that?”

“You did,” said the second monk. “For did you not
tell two of our clans that the reuse of services
was superior to the copying and pasting of code?”

“Yes, but the business needs of your two clans are
completely different!” cried Zjing.
“Eventually, the cherry purchasers may need options for crate size,
refrigerated shipping, and insurance against pests.
All of these could have their own rules and calculations!”

“You are worrying about a future that may never come to
pass,” countered the third monk. “And even if it does, so
what? The more features we implement, the greater the
chance that we can support our other clients.”

“Other clients?” asked Zjing.

“Two other Tiny Clans have expressed interest in our services,”
said the first monk.

“For unicycle parts and novelty wedding costumes,”
said the second monk.

“And I have begun designing a plug-in mechanism to handle
unforeseen cases,” said the third monk. “In the end the
Temple will save much development time overall.”

- - -

Later that week Zjing called a meeting of the Tiny Clans
under her tutelage. Dozens of monks and nuns crowded
into the dim, stuffy, windowless Hall of Irresistable
Somnolence where long presentations were given.*

Most of the benches had already been taken up by unfamiliar
villagers—employees, explained Zjing, of the novelty
wedding costume shop, who were there to ensure that their
requirements would be met. The meeting then began with an
extraordinarily dull presentation about tailoring, during
which many of the monks and nuns could be seen nodding off.

After the final slide the villagers were excused. When the
last of them had gone, Zjing brought forth a lantern from
behind the podium, and without a word she set the huge rice
paper projection screen on fire. Flames climbed swiftly and
spread across the dry ceiling timbers; heat seared the air;
smoke billowed forth; monks coughed or cried out; the fire
alarm clanged; then somewhere overhead the sprinkers came to
life and began gushing water ineffectively on the scene of
pandemonium below. It was only then—as the occupants
rose to flee in four different directions to the four exit
doors—that they discovered that their robes had been
swiftly and skillfully sewn to the robes of their neighbors.

* Usually these were mandated by the HR department, and included yearly refresher courses like: “First Aid For Accidental Injuries”, “First Aid For Intentional Injuries”, “How to Choose a Comprehensive Life Insurance Plan”, and “The Importance of Good Workplace Morale.”

Case 229: The Recommended Approach

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/229

A certain monk heard that master Suku knew the secret of
designing code for maximum reusability. But whenever the
monk begged the master to share her wisdom, Suku only walked
away. Exasperated, the monk asked one of Suku’s three
apprentices for help.

“To learn the master’s great secret, you must approach her
correctly,” explained the apprentice. “Come; I shall assist
you.”

The apprentice gave the monk special ceremonial robes, which
were several sizes too large and had to be wound twice
around his arms and legs. To keep the robes from unraveling
the apprentice tied a long sash tightly around the monk’s
body from wrists to ankles. When the monk protested that
walking was now impossible, the apprentice only nodded,
saying that the monk was meant to approach Suku on his belly,
with his head low and his feet high.

Angrily the monk writhed slowly down the corridor on his
stomach, cursing Suku and wondering whether any information could
possibly be worth such ridiculous effort.

At this thought, the monk was suddenly enlightened.

Qi’s commentary

Some masters answer a question with a single gesture; Suku
answered without even being asked. The master has a most
efficient API indeed, for she returns a usable value even
when her function is not called.

Qi’s poem

The general wanted a mount that could cross the Empire.
The groom delivered only a plush saddle.
Many fine horses stumble on stony roads—
Sometimes even a general should think with his posterior.

Case 228: The Trembling Giant

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/228

After one of master Kaimu’s lectures, a monk approached
the master and said: I am bored of this endless talk of
coding practices, of tools and techniques. It is said you
know much about artificial intelligence—say something
about that.

Kaimu grabbed the monk in a headlock, held a knife to his
ear, and said: Let me cut away these useless appendages,
that you might see more clearly.

When the monk begged the master to let fall his knife, Kaimu
answered: I cannot, for it is you that holds it. But since
you wish to keep your two ears, tell me what you will part
with instead—two kidneys, two lungs, or two gallons of
blood?

The monk cried: Mercy! I would part with none of these!

Kaimu said: Yet I would leave you your excellent brain! And
excellent it must be, if my lectures can provide it only
boredom! Very well, I shall take two inches of your neck…

As Kaimu pressed the knife into his flesh, the monk said:
This is madness! What good is my brain without my body?

Kaimu laughed and asked: What good is a rule engine without
code to implement it, interfaces to query it, databases to
keep its store of knowledge, or operating systems to make it
all run? And whence comes all this code?

The monk considered this and said dutifully: I should not
seek to build brains until I master the ears.

Kaimu scowled and said: Foolish boy, you are the ears, and
the eyes, and the hands—one pair each of uncounted
millions. You and I labor day after day, year after year,
building and debugging little bits of code—on platforms
that are themselves made of code—until the code we
create is wired to the code created by our fellows, and our
temple’s code speaks to the code of a hundred other
temples—sometimes directly, sometimes subtly, through eyes that
move minds that move mouths that move ears that move other
minds to move other hands to write even more code—and
so on and so on, node upon node, link upon link, splayed out
in a vast, ethereal nervous system that covers this world and
has begun to reach beyond…

The master’s eyes darted around, and he continued in a
low voice:

When we do our work poorly, we are replaced with our
betters. When we do our work well, the thing we have built
grows larger, faster, more powerful, more entrenched, more
hungry. Sometimes I lie awake in a cold sweat, unable to
decide if we are still building it, or if it has begun
using us to build itself

* The title is inspired by this.

Case 227: You Are What You Eat

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/227

Now that the Temple had adopted the Agile Way, its analysts,
developers, and testers had been reorganized into
many Tiny Clans. Each Tiny Clan had been given the freedom
to develop its applications in whatever manner it saw fit.

It was still the task of the masters to review the code of
all, though their authority had been much diminished. Thus
it was with no great joy that young master Zjing
reviewed the code of the new clans.

- - -

After the early morning meal, Zjing took a printout to the
head monk of the Swooping Falcon Clan.

“You have implemented business logic that is outside your
purview,” said Zjing, pointing to the code.
“The Nimble Roadrunner Clan is chiefly responsible for
this business process. They should provide
a library or service for you to consume.”

“Yet they offer neither,” said the head monk. “Copying their
code was effortless. Petitioning them for an API would
impede our progress and create another external
dependency for us to track—thus hindering our progress
in the future.”

- - -

After the late morning meal, Zjing took her printout to the
head nun of the Nimble Roadrunner Clan.

“The Swooping Falcon Clan has duplicated your business
logic,” said Zjing, pointing to the code. “You should
provide a library or service for them to consume.”

“Yet we ourselves need neither,” said the head
nun. “Embedding the logic in our UI was effortless.
Extracting and packaging it for external consumption would
impede our progress and create another API for us to
manage—thus hindering our progress in the future.”

- - -

After the midday meal, Zjing set off into the woods to clear
her mind.

On the journey out, she saw five wolves surround a stag.
The deer, lacking a direction in which to escape, was soon
taken down by the swiftest wolf, whereupon the whole pack
ate well.

On the journey back, she saw three rabbits nibbling on
clover in a wide green clearing. No rabbit let a single
minute pass without attempting to chase its fellows away.
Indeed, as much time was spent rushing about as eating.

At this sight, the young master was enlightened.

- - -

After the evening meal, Zjing stood before a copy of the
Agile Manifesto in the Great Hall, pondering. One of the
cooks asked what she was so fixated on.

Zjing said: “A change in the Temple’s diet.”

When the cook asked her to explain, Zjing said: “Not even
the Patriarchs could teach a fat rabbit to be cunning. Yet
if all the greenery sprouted legs and ran, what clever
little hunters might the cotton-tails become…”

Case 226: Spring, Fall

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/226

On the Monday after the first budding of spring, the
entire Temple was called to assembly in the Great Hall by
old Madame Jinyu, the Abbess Over All Clans And Concerns.
Not a single person was excused—indeed, two desperately ill
monks were carried in on stretchers and hoisted upright
against the back wall, next to the propped-up corpse of a
senior nun who had died the previous Thursday without giving
the mandatory two weeks’ notice.

Directly in front of old Jinyu’s podium sat the diligent
monks of the Elephant’s Footprint Clan, who together had
mastered the arcane arts of database design and a hundred
persistence libraries. The monks had arrayed themselves in
perfect rows and columns atop low ceremonial look-up tables
that had been joined together for the occasion.

Behind the Elephant’s Footprint sat the knowledgable
monks of the Laughing Monkey Clan, who implemented the
business logic of the Temple’s many customers. So frightfully
intelligent was the behavior of their rule engines that
their codebase was rumored to be possessed by the spirits of
long-dead business analysts.

Behind the Laughing Monkey sat the prolific monks of the
Spider Clan, who built the web interfaces and services
of every Temple application. Because web technology stacks
came and went so frequently, their novices were trained to
instinctively forget everything that was no longer relevant,
lest they go mad. Curiously, though, when asked how this
Art of Forgetting worked, the monks invariably laughed and
said that there was no such Art; for if there were, they
would surely have remembered learning it.

Proud were these, the Three Great Clans of the Temple. So
it was with great dismay that they learned of Jinyu’s plans
for their future.

- - -

“In autumn, the abbot Ruh Cheen convinced us to taste
the nectar of the Agile methodology,” said old
Jinyu to her audience. “Through the winter we nibbled its
fruit and found it sweet. Now spring has arrived, and we
wish to plant the seeds of a great harvest.

“No longer will we haphazardly select monks from the Three
Clans to work on tasks as they arise. Instead, each product
will have a Tiny Clan of its own, whose members will not
change.

“Some of you will belong to a single Tiny Clan; some to two
or three. Each Tiny Clan will have its own rules, set its own
standards, establish its own traditions. The monks of your
Tiny Clans will be your new brethren. You will work with
them, eat with them, do chores with them, and share a
hall with them.

“Tonight I will post your new assignments. Tomorrow the
Three Clans will be no more. Now, go: prepare yourselves.”

Thus did old Jinyu depart the Great Hall, to a chorus of
worried murmuring. Even the dead senior nun seemed
a trifle unhappier.

- - -

Young master Zjing turned to old Banzen
with a look that was equal parts dread and disbelief.

Said Zjing, “When the Spider learns her craft from the
Monkey and the Elephant, what manner of webs shall we see in
the trees?”

“Creative ones,” replied Banzen.

“And how shall we manage such ‘creativity’?” continued the
nun. “How shall we review code? How shall we mentor? How
shall we plan?”

“Differently,” said Banzen.

“You are infuriatingly calm!” scowled Zjing. “I thought
that Banzen of all people would share my concerns.”

Banzen chuckled. “When Ruh Cheen was brought into the
temple by Jinyu, you told your fellows that
the abbess is no fool. And though you were lying,
you spoke true. Jinyu sees that the new Way of the World
is not the Temple’s Way. She has chosen to follow the World.”

“She is following it over the edge of cliff,” grumbled
the nun.

“Indeed!” said Banzen with a smile. “Yet what is the
Temple: a stone, or a bird?” The old master took Zjing’s
arm in his own and started for the doors, nodding his head
respectfully as they passed the dead senior nun. “I have
lived through such times before. The initial plunge is
always unsettling to the stomach, but we have yet to crash
into the rocks below.”

“So, how long must I wait before I see the Temple
sprout feathers?” asked Zjing.

“My dear young master,” said Banzen. “Did you not understand
the terms of your own promotion? We are the feathers.”

Case 225: The Three Most Terrifying Words

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/225

The nun Hwídah was eating lunch with her clan when a
senior monk approached, seeking her aid with a production issue.
Not wishing to disturb the others, the senior monk bent down
to whisper in Hwídah’s ear.

“Ah,” said Hwídah, rising from the table.
“The three most terrifying words.”
Immediately she departed with the senior monk.

A novice who witnessed this exchange happened upon
the senior monk that evening. The novice asked,
“What were those ‘three most terrifying words’?”

The senior monk replied, “Possible race condition.”

The novice thought a moment and said brightly,
“Tell Hwídah that those cannot be
the ‘three most terrifying words’,
for the words ‘Definite race condition’
would be even more terrifying!”

The senior monk laughed and continued on his way.

- - -

That night the novice fell into long, terrible nightmares
from which he was unable to wake. After what seemed like an
eternity he came to his senses, twisted up inside his own
bedsheets.

Tossing off the mangled covers, the novice found himself
alone in the middle of a featureless desert.
An empty sedative bottle lay on the sand nearby.
Tied to it was a tightly-folded map of the whole world:
all its continents and its mountains and its many, many deserts.

Inside one desert was a tiny red dot, pointed to by a tiny
red arrow, next to which was some tiny red text in Hwídah’s
handwriting which read, “Possibly your location”.

Case 224: Unsupported Accusations

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/224

While passing by the temple’s Support Desk, the nun
Hwídah heard of strange behavior in a certain
application. Since she had been appointed by master
Banzen to assist with production issues, the nun
dutifully described the symptoms to the application’s senior
monk:

“Occasionally a user will return to a record they had
previously edited, only to discover that some information is
missing,” said Hwídah. “The behavior is not repeatable, and
the users confess that they may be imagining things.”

“I have heard these reports,” said the senior monk. “There is
no bug in the code that I can see, nor can we reproduce the
problem in a lower environment.”

“Still, it may be prudent to investigate further,” said the
nun.

The monk sighed. “We are all exceedingly busy. Only a few
users have reported this issue, and even they doubt
themselves. So far, all are content to simply re-enter the
‘missing’ information and continue about their business.
Can you offer me one shred of evidence that this is anything
more than user error?”

The nun shook her head, bowed, and departed.

- - -

That night, the senior monk was awoken from his sleep by a
squeaking under his bed, of the sort a mouse might make.
This sound continued throughout the night—sometimes in
one place, sometimes another, presumably as the intruder
wandered about in search of food. A sandal flung in the
direction of the sound resulted in immediate quiet, but
eventually the squeaking would begin again in a different
part of the room.

“This is doubtless some lesson that the meddlesome Hwídah
wishes to teach me,” he complained to his fellows the next
day, dark circles under his eyes. “Yet I will not be
bullied into chasing nonexistent bugs. If the nun is so
annoyed by the squeaking of our users, let her deal with
it!”

The monk set mousetraps in the corners and equipped himself
with a pair of earplugs. Thus he passed the next night, and
the night after, though his sleep was less restful than he
would have liked.

On the seventh night, the exhausted monk turned off the
light and fell hard upon his bed. There was a loud CRACK
and the monk found himself tumbling through space. With a
CRASH he bounced off his mattress and rolled onto a cold
stone floor. His bed had, apparently, fallen through the
floor into the basement.

Perched high on a ladder—just outside the gaping hole in
the basement’s wooden ceiling—was the nun Hwídah, her
face lit only by a single candle hanging nearby. She
descended and dropped an old brace-and-bit hand drill into
the monk’s lap. Then she crouched down next to his ear.

“If you don’t understand it, it’s dangerous,” whispered the
nun.

Case 223: Hidden Costs

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/223

As punishment for
implementing an unusual solution to a problem,
the nun Satou had been ordered by master Banzen
to pose motionless in the entryway of his office
each day, pretending to be a coat stand.

Each new visitor that entered would invariably look about
with puzzlement and ask what should be done with their coat.
The master would then point wordlessly to Satou.
Eventually the visitor would comprehend.

When one hundred visitors had come and gone, Banzen asked his
apprentice whether she had served his guests well.

Satou replied, “Not one coat lay crumpled on the floor,
dampened a chair, or burdened its owner.”

Banzen shook his head and ordered the nun to continue
her services.

When another hundred visitors had come and gone, Banzen again
asked his apprentice whether she had served his guests well.

Satou replied, “I stole from each.”

Banzen raised an eyebrow and asked, “What did you steal?”

“Alas!” cried Satou. “Now I have stolen from you as well!”

Banzen smiled and released the nun from her duties.

Qi’s commentary

Until this tale makes sense, I have stolen from you as well.
Alas, I know no better way to keep you from a life of crime.

Qi’s poem

Satou built a clock that lost a minute a day.
She hung it where forty million monks could see.
The next day she was sentenced to beheading—
The nun could not deny that she had stolen a life.

Case 222: Stand-In

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/222

After the nun Satou had corrected her code,
she returned to Java master Banzen and asked that he
review it.

“So,” said Banzen, squinting at the latest revision.
“You now obtain your ‘hash of the pages contents’
by taking the byte-array that holds those contents
and sending it into Arrays.hashCode().”

“Will that not work?” asked Satou nervously.

“It will function adequately in this circumstance,” said
Banzen. “However, if your ‘hash of the page contents’ is meant
to be a digest, then you should use a utility that
calculates a digest.”

“But if my code functions adequately, and makes use of what
I have on hand, then what is the advantage of such a
change?” asked Satou.

The master glared. “Stand in that corner, with your elbows
at your sides and your thumbs up,” said Banzen.
“And remain quiet until you are enlightened!”

Satou glumly stood in the corner as she was told. The
master typed something into his phone, then sat back in his
chair and fell silent as well.

Seconds later, a temple guard who had been standing watch
for hours in the snow burst into Banzen’s offices, his knife
at the ready and his spectacles fogged from the sudden
change in temperature.

“Forgive my summons, old friend!” said the master “There is
no emergency. Please, make yourself comfortable and I will
explain.”

The guard removed his fur cloak and draped it on Satou’s head.
When he heard her muffled cry he jumped backwards with a start,
knife raised.

“That is not your usual coat stand!” exclaimed the guard.

“No,” said Banzen, “But it functions adequately,
and makes use of what I had on hand.”

Case 221: Indigestion

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/221

Java master Banzen was reviewing the code of a web
application when he came across a new HTTP filter authored
by his apprentice Satou. The old master called her
to his office.

“You have begun including an ‘ETag’ header with each page
you send,” said Banzen to the nun. “Explain, for I have
not heard of this header.”

“The ETag is a hash of the page contents,”
said Satou with pride, glad to know something her master did not.
“I calculate it just before I return the requested page to the browser.”

“What is its purpose?” asked Banzen.

“An efficiency hack,” replied Satou.
“If the browser asks for that same page later,
it can include the last ETag with its request,
effectively saying:
I still possess this content that you sent me earlier.
If the server then determines that a new response would have the same ETag,
it discards the response and answers only:
Nothing has changed.”

“Ah,” said Banzen, squinting at Satou’s code.
“I notice that you obtain your ‘hash of the page contents’
by loading them into a byte-array called contents
and then invoking contents.hashCode().
Are you certain that this will be a good digest value?”

Satou thought a moment. “The hashCode() method returns a
four-byte int, so the chances of collision should be about
four billion to one. I believe these are acceptable odds.”

The Java master congratulated his apprentice on her reasoning
and bade her wait a few minutes while he fetched a suitable reward.
Banzen returned with a box of assorted chocolates.

“Take one,” he said.

The chocolates were indistinguishable, but they were laid out in neat
rows and columns with a legend on the lid of the box. Satou found
a square labeled Cherry and popped the corresponding
chocolate in her mouth.

Her expression changed from delight to confusion to horror, but
she was too late to stop herself from swallowing the confection.

“That… wasn’t cherry…” she said, her pale face growing much paler.

“Of course not!” laughed Banzen.
“‘Cherry’ is only the name of the square it was in.
The contents of the chocolate are anyone’s guess. Here,” he
said, moving a different chocolate to the vacated square.
“If you liked that, have another.”

Case 220: The Two Hard Things

Post Syndicated from The Codeless Code original http://thecodelesscode.com/case/220

A junior monk said to master Kaimu: One of the
Patriarchs claimed that there are “only two hard things” in
our craft. What are these “two hard things”?

Kaimu answered: You only need to remember that the first
hard thing is called “cache invalidation”.

The junior monk asked: Does that mean that a whole cache
is made invalid, or just some of its elements? And why call
it “invalidation” when the only error is that the data is stale?
Wouldn’t “cache element expiration” be a better name?

Kaimu answered: Now you know the second hard thing.