Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Revenge of the Anti-patterns


Feb03: The New Adventures of Verity Stob

Verity is the pseudonym of a programmer based in the UK. She can be contacted at [email protected].


Verity has created two new anti-patterns.

I admit it—I've bottled out. My first thought was to present you with a few new design patterns that I have worked out. But ever since the GoF (Gang of Four) first thrust its modest list of 23 out into an admiring world, the competition has been beavering away into the night, tirelessly flicking through dictionaries in search of new abstract nouns that can be used to name them: Spiral of Dexterity, Sanity Principle, Circumstantial Vista. Giant catalogues containing hundreds of patterns have plopped out from the big publishers. Reading them, one is soon overtaken by the suspicion—and this is a difficulty that recalled a rather different catalogue of patterns I once thumbed through, a tome translated from Sanskrit by Sir Richard Burton and entirely lacking UML illustration—one is overtaken by the suspicion that #245 is pretty much the same as #121 but with its pinkies crossed.

It is too late for patterns. The competition is just too plentiful.

On the other hand, with antipatterns, the field remains wide open. True, the MoF (Mob of Five) has got the discipline off the ground by writing the first ever book dealing with the subject (and on the evidence of Amazon.com, also the second, third, and fourth). But there remains plenty of work to be done.

Extensive research (I asked Dave) suggests that only one antipattern has really "taken" in the world at large. "Lava Flow" is an excellent antipattern with a clever name—for the benefit of A-P neophytes, I should explain it refers to those swathes of nasty obsolete code prefaced with a comment like this:

// Dunno how/if this works

// LEAVE IT ALONE!

Lava Flow is good, but it's lonely. Hands up everybody who remembers "Poltergeists" or "Stovepipes." Well, exactly. It is no good sitting there sniggering. This is serious. What would you do if tomorrow you were required to implement a RavioliCode system? Oh yes, there is such a thing. No soldier, ordinary spaghetti code is not good enough.

What is needed here is that a mature programmer, with extensive close-up experience of creating a large variety of badly written code, takes this discipline to the next level. It goes against my English bashfulness to say this, but I have become convinced that I am the person to take this on. I am to be known, henceforth, as the CoO (Crowd of One).

Here are two brand new antipatterns for the twenty-first century.

Classtorbaitor

Consider a class, probably from a library, whose interface looks like this:

class CBaitor

{

public:

virtual T method1();

virtual T method2();

protected:

virtual T method3();

virtual T method4();

private:

// instance data and

// accessor methods here

}

You would like to vary some aspect of the behaviour of this class. How would you go about it? Look at all those lovely virtual methods, flaunting their signatures in public and protected scope. Can you hear them calling out to you: "C'mon Big Boy! Override me if you dare!" What are you going to do about it?

Why, you derive of course. And just about halfway through implementing a new version of method1(), you discover you need access to some bit of state—and the trap closes. That protected section is just bait, put there to draw you into the Classtorbaitor. All the instance data is locked away, beyond your reach, in the private scope. There may be a couple of methods that look as though they might be shoe-horned into the roles of accessors, but closer examination reveals that they have ghastly side effects when called. You are comprehensibly stuffed.

You might think that such monsters don't exist in real life, but they do and, some years ago, I have written their ilk. And I didn't do it out of malicious intent, either. It's quite easy to make such a thing, when one is rather inexperienced in the Ways of OOP. All you need do is apply the principles "virtual is good" and "inheritance is desirable" with blind naivety.

Clever Clogs Comment

We are all familiar with the basic duh comment

i++; // add one to i

that is an unsung foundation of antipatternery. But, in fact, it does no more damage than clutter the layout and could even be argued to be useful in that it warns the reader that the module-writer is quite thick.

But there is another kind of comment, in some sense from the other end of the scale, which is much more unhelpful. The Clever Clogs Comment has three distinguishing features: Its writer correctly identifies that a comment would be useful at this juncture; Its writer understands what information is needed: Its writer is a smartarse.

Here is an example I recently found written by Ms V Stob:

// This function doesn't have a no-throw guarantee;

// however it does offer a no-throw six month

// return-to-base warranty ;-)

What, by all the hairy Norse gods, did I mean by that? Does it throw or doesn't it throw? Honestly, it's enough to make me want to develop a primitive time travel vehicle, so that I can travel back to 1999 and punch myself.

I have an absolute peach of an example of a vintage CCC that can be found on the Net. This comes from a famous app that I know you know, even if the guilty party, one Bernard S. Greenberg, may not be the first programmer whose name springs to your lips in this context. The app is the Emacs editor, the programming language is LISP, and the header comment of the redisplay module is in Latin:

;;; 3/6/78 inceptus Luna meo adjutorio.

;;; 4/19/78 duas fenestras feci.

;;; 5/30/78 ^V creavi.

;;; 6/18/78 signum linearum elongatarum, ^0^L, &c

This carries on until 1981, when commenting switches to English "at popular demand." I should cocoa. Illiud Latine dici non potest.

We seem to have a little space before the next article, so here is a treat. Following my recent mention of the cult BBC TV programme "What Not To Wear," I have been deluged with requests for more Susannah/Trinny dialogue, especially from those who can't yet get BBC2. Happy to oblige. Here is a classic exchange from the week before last. The girls are watching secretly filmed footage of their next victim. Enjoy.

S: She looks slovenly. Slobby T-shirt, and the leggings, she looks...

T: (who hisses a little on her sibilants when excited): Ssslovenly!

S: (rolling the word around her mouth): Like a SLOVERN.

T: (immense relish): SSSLOVERNLY!

DDJ


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.