I recently answered a question on the junit Yahoo! group. The questioner included text from an article about when to use class-level (static) methods and when to use instance-level methods. While I don’t wish to single out the article’s author, I do wish to single out the article, because I found its example ludicrous. To give you an idea, here is some of the article’s example:

public class MrHappyObject {
    private String _mood = _HAPPY;

    private final static String _HAPPY = "happy";
    private final static String _ANNOYED = "annoyed";
    private final static String _ANGRY = "angry";

    public void printMood() {
        System.out.println("I am " + _mood);
    }

    public void receivePinch() {
        if (_mood.equals(_HAPPY)) {
            _mood = _ANNOYED;
        }
        else {
            _mood = _ANGRY;
        }
    }

    public void receiveHug()
        if (_mood.equals(_ANGRY)) {
            _mood = _ANNOYED;        
        }
        else {
            _mood = _HAPPY;
        }
    }
}

Mr. Happy Object?! What kind of example is that? I don’t mean to be rude, but an example like this seems to serve only to insult the reader’s intelligence. I also find it lazy, although I admit it’s better than examples with nonsense like int a = 3; int b = 4;.

Please, if you’re writing articles with code, please make the code examples at least somewhat meaningful. Use concepts that your readers will generally be able to understand. One person’s humor is another person’s condescension.

As a footnote, let me make it clear that this is not an indictment of the author of this article. Many more than he use nonsensical examples in their writing.