March 10, 2008

...Learn TDD with Codemanship

Patterns vs. Principles = Recall vs. Insight

What's the difference between a pattern and a principle?

Well, some people can draw pretty much anything you put in front of them. They understand shape, and proportion, and perspective, and light and shade, and so on.

Some people know how to draw Marvin the Martian.

One of these skills requires greater insight than the other. The best artists have to build their understanding, to the point where they learn anatomy, for example, so that they can draw people and animals more realistically.

You don't need to udnerstand how a Martian works to draw Marvin, He is just a simple set of visual patterns - icons, if you will - arranged together in such a way that it looks like Marvin the Martian.

If you look at the history of art through the ages, you can see a progression from cave art, where the artist "knew how to draw a horse" or "knew how to draw a man with a spear" in much the same simplistic way that some people "know how to draw Marvin the Martian".

As our understanding evolved, our art became more sophisticated and realistic. Such is the insight and skill of some painters, for example, that they have been able to create pictures that look almost completely real. and they don't do it by "learning how to draw a horse" or "learning how to draw a table". They do it by learning about the principles of light and colour and perspective and anatomy and so on, and applying these to the scene in front of them. So they can draw or paint just about anything, as long as it can be seen.

Marvin is a pattern. Objects appearing smaller the further away they are: that's a principle.

The learning process often seems to involve progressing from reproducing patterns to being able to solve new problems and infer new knowledge from underlying principles. And as we learn, we can see the evidence of this process.

If we study cave art, for example, we see how one cave painter might master the depiction of buffalo. Soon afterwards we see buffalo appearing in many cave paintings, many times. It seems that once we know a new pattern, we're keen to use it everywhere. At least until it loses its novelty, and then we move on to the next new pattern.

Principles evolve less quickly than patterns. Yes, they do eventually change as our understanding grows, but they don't change rapidly, and so we can rely on them to be useful for longer. They also tend to be more widely applicable (not every scene can justify the inclusion of buffalo, but perspective is almost universally a component in any scene).

In the long term, it's better to know principles, I find.

And as a developer, I see only to clearly the difference between patterns and principles (i.e., recall and insight). Take design patterns, for example. A developer learns the Factory Method, and then daubs it liberally throughout their code until they get bored and the next pattern comes along, and then they splash that one about with gay abandon, like cave dwellers covering the walls with buffalo until one of them figures out how to draw a woolly mammoth, and then that becomes the motif.

As the developer matures, she will hopefully learn about the design principles that lie behind most of the GoF patterns, and then she will find that she's able to go beyond mere recall of oven-ready design solutions and start inferring new knowledge and solving new problems by applying those principles to whatever is in front of her.

Same seems to be true of practices and methods. We start by learning how to do it the way the book says (well, a few of us do, anyway), and then we begin to see the reasons why we're doing what we're doing, and begin to apply that insight to new situations.

Posted 10 years, 4 months ago on March 10, 2008