Author: Roedy Green

Version Compatibility: Visual Basic 6, Visual Basic 5

More information:

This humorous article only slightly exaggerates common coding practices, and therefore, besides providing entertainment, also serves as a lesson in "what not to do."

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

' (None)

How To Write Unmaintainable Code

Originally published at http://mindprod.com/unmain.html. Reprinted by special permission from the author. Further reprints, without the express permission of the author are prohibited. Last updated Thursday, 05-Apr-2001 03:41:36 PDT by Roedy Green 1997-2001 Canadian Mind Products.

Introduction

Never ascribe to malice, that which can be explained by incompetence.

Napoleon

In the interests of creating employment opportunities in the Java programming field, I am passing on these tips from the masters on how to write code that is so difficult to maintain, that the people who come after you will take years to make even the simplest changes. Further, if you follow all these rules religiously, you will even guarantee yourself a lifetime of employment, since no one but you has a hope in hell of maintaining the code. Then again, if you followed all these rules religiously, even you wouldn't be able to maintain the code!

You don't want to overdo this. Your code should not look hopelessly unmaintainable, just be that way. Otherwise it stands the risk of being rewritten or refactored.

General Principles

Quidquid latine dictum sit, altum videtur.

Whatever is said in Latin sounds profound.

He views your code through a tube taken from the centre of a roll of toilet paper. He can only see a tiny piece of your program at a time. You want to make sure he can never get at the big picture from doing that. You want to make it as hard as possible for him to find the code he is looking for. But even more important, you want to make it as awkward as possible for him to safely ignore anything.

Programmers are lulled into complacency by conventions. By every once in a while subtly violating convention you force him to read every line of your code with a magnifying glass.

You might get the idea that every language feature makes code unmaintainable -- not so, only if properly misused.

Naming

"When I use a word," Humpty Dumpty said, in a rather scornful tone, "it means just what I choose it to mean - neither more nor less."

Lewis Carroll -- Through the Looking Glass, Chapter 6

Much of the skill in writing unmaintainable code is the art of naming variables and methods. They don't matter at all to the computer. That gives you huge latitude to use them to befuddle the maintenance programmer.