The Ghetto Mini-Pattern

May 28, 2003 11:14 PM

Name: The Ghetto

Context:

You are in some way subject to architectural, framework or language constraints that force you to write ugly code. For example, your UI framework requires one kind of object, your persistence framework requires another, and you keep having to convert between the two.

Forces:

  • You will not always be in a position to remove the root cause of the ugliness.
  • Ugly code is usually boiler-plate, and not very interesting.
  • It is better not to have ugly, boiler-plate code obscuring code that actually does something interesting.
  • Of course, [insert-your-favourite-language-or-framework-here] is immune to this problem. Obviously this pattern does not apply to you.

Therefore

Hide your ugly code inside a Ghetto. The ghetto is a single file or class where issues of code cleanliness do not apply. It is entered by reputable developers with no small amount of trepidation, and left as quickly as possible. On the other hand, it does the job, and it keeps the bad elements away from more cultured code.

If the constraints that caused you to build a Ghetto are widespread, though, it may end up being the biggest single file in your application.

Examples of use:

None that this author is willing to admit to.

Previously: This one is Alan's fault

Next: Impossible Performance Art