The Tao of Exceptions Will Make You Error-Free




The Tao of Exceptions



In the beginning, there was error.

♦ 

The master programmer was about to write the most beautiful program ever written by mankind. He sat in front of his keyboard as the jumble of thoughts in his mind began clearing away at the smell of freshly brewed coffee. He carefully wrote:  
    void do_beautiful_stuff() {}

As the parentheses were closed, a question rose from the depth of the void, and it's answers needed to be enumerated; the question spoke thus: "how will they know that I, do_ beautiful_stuff(), have returned?".

The master programmer pondered the question, while many valuable clock cycles fleeted away into the void. At last, he carefully re-arranged the electrons: 
    int do_beautiful_stuff() {}

He looked at the screen and chuckled. I have answered the question, he thought. If do_beautiful_stuff() does indeed succeed, it returns 0, else it returns 1. Now one can merely look at the return value, and decide if it was a success or a failure.

The master programmer looked out of the window. A storm cloud was gathering in the distance. It will perhaps be a clear day when I am done with my beautiful program, the master programmer thought.

Little did he know that something exceptional was about to happen.

♦ 

The code was now complete. It was a work of art. With an elegant flourish of his fingers, the master programmer left the compiler running overnight to convert his code into the most beautiful machine language ever known. He then went to sleep, his head resting on the keyboard.

He dreamed of a wonderful world ruled by 0s and 1s.

♦ 

The master programmer woke up to the sound of rain pounding the roof. It was to be a dark, ominous day. 

The program was compiled, ready. With fingers shaking in anticipation, the master programmer typed:  
    ./a.out

There was a pause, and then the giant wheels of the machine began to turn. Soon they were running in unison, and you could hear a melodic hum emanating from the machine. There was a trance-like quality to the hum, and the master programmer listened intently to the melody for any signs of ugly disturbances in the force. There were none.

Then all of a sudden the machine screeched to a halt. It wheezed and coughed, and finally spat out a single number. The master programmer looked carefully. The number was 1.

The error was born.

That was the beginning.


Thirty long years passed.

The master programmer has written 300 million lines of code. He now has a long white beard; he still wears his tie-dye shirt on Fridays. His name is spoken far and wide with fear and respect.

He has conquered exceptions.

His programs always return 0. This makes the master programmer very happy. Beautiful things happen in the world when a 0 is returned. There is harmony, peace, happiness, and the Tao is pleased.


An intern looks at the code written by the master programmer. It is indeed a work of art. Every semicolon is in it's place; no pointer is left dangling; every exception is tried and caught. Finally, all errors are exquisitely handled.

The intern is puzzled.

The beautiful program, written by the master programmer, always returns 0.

Trembling in fear, the intern meets the master programmer. "I may be wrong", he says, "but I do not seem to find any way I can make the beautiful program return anything but 0. Can you, O Master Programmer, please show me how an error is detected and returned by the beautiful program, so I may learn from your infinite wisdom?".

The master programmer looks long and hard at the intern. The silence deepens in the void. The intern prepares to leave.

"Success is in not allowing failures to happen", the master programmer says at last, as the intern reaches the door.

The intern is enlightened.

The intern writes a new program. It never fails. It always returns 0.

The Tao rolls over in his sleep.


Comments

Susan said…
Love it! Who says tech cann't be humorous?
Anonymous said…
Delightfully written. The humor really digs deep into the truth of how things work, at work. Love the inherent satire of the piece. I believe I have met master programmers like this. :-)
Pinaki Poddar said…
Theorem: number of errors is linearly proportional to the number of lines of code.

Hence a program without error has zero line of code.


Amit Basu said…
Pinaki, clearly you haven't met the master programmer yet. All linearity breaks down in front of the master programmer. :-)

Popular Posts