GeekLondon.com Help icon Syndication Feed icon 

Big Picture, Little Picture

This post addresses a problem encountered by newcomers to programming. Newbies tend not to be big technical-readers, so if you're browsing this of your own volition it probably doesn't apply to you. If, on the other hand, someone has specifically asked you to read it, you're probably one of the people I'm describing.

The problem with the Sun Java Forums is the unclear requirements. Well, apart from the Trolls. And the homework cheats. And the illiterates. And the 14,000 post eulogies to pedantry. And the fact that it's a damned time sink that I'll be giving up completely any day now. But apart from that, it's the unclear requirements.

Here's a typical plea for help, only without the lack of clarity, bad spelling, and petulance:

How do I call methods in Java source files?

Why is this such a bad question? Well, by analogy, the user is essentially asking:

What's the heaviest pair of pliers I can get to bang nails in with?

That is to say, the user is asking how to use a tool for a purpose that it is clearly not designed for. In fact the Java example is slightly worse, because while possible it is likely to be timeconsuming and almost impossible to be a good idea in most circumstances. Banging nails in with pliers is never a great idea, but it doesn't take long to find out what a bad idea it is.

So that question is pretty misguided, but it does have the signal redeeming factor of being conspicuously misguided. Far worse are the questions like this:

How do I find out the class of an object?

Finding out the class of an object is not, intrinsically, a bad thing. For example:

log.info("Retrieved an object of type " + foo.getClass().getSimpleName() + " from the list.");

That's a legitimate usage. On the other hand, they might be intending to do something like this:

if( foo instanceof Square) {
   ((Square)foo).display();
} else if ( foo instanceof Circle ) {
   ((Circle)foo).display();
} else if ( foo instanceof Triangle ) {
   ((Triangle)foo).display();
}
// ...
} else if ( foo instanceof Dodecagon ) {
   ((Dodecagon)foo).display();
} else {
   System.err.println("Error - unrecognised shape");
}

Now, in this case, if the user had expressed their problem in macroscopic terms - that is, if they had given the big picture of "I want to display representations of several different classes of shape on the screen - how do I call the appropriate method on each of them?" we would have had some idea that the correct answer was not "use the instanceof operator" but rather "use interfaces." To illustrate the interface based alternative:

if( !(foo instanceof Shape) ) {
   System.err.println("Error - not a shape");
} else {
   ((Shape)foo.display();
}

That's a hell of a lot simpler, and if Shape is an interface common to all those classes then the above will substitute very nicely indeed. If it isn't, it should be. The instanceof operator might still be useful, but it's not actually the correct answer to the question.

Unfortunately some people get very attached to their microscopic view of the problem. If you ask for a more detailed explanation, or worse yet, tell them that what they want to do is misguided/impossible, you'll often get:

The hostile response usually takes the form of "if you don't know the answer mind your own business." Doubly irritating when you're honestly trying to help someone find the best solution to their actual problem, and things generally deteriorate from there. But it is the incomprehension of the first three responses that's most frustrating really.

A model version of that original misguided question:

How do I allow for the use of third-party created plugin modules in my paint application?

This version of the question has given us the big picture, which the user understands. They don't understand the small-picture problem, by definition, because if they did they wouldn't need to ask the question. It allows the people answering to side-step the whole irrelevant issue of compilation and invocation of source code, because the actual answer involves the use of classloaders, interfaces, and Jar files. If the original question had been answered without further exploration, the best the user could hope for is an answer that would make their code far more difficult to write and more fragile once it was complete.

In summary, when you want help - give the big picture.

Further reading: How to Ask Questions the Smart Way

Posted at Dec 10, 2007 8:19:06 PM, and last updated Dec 10, 2007 8:27:06 PM