Sunday, December 25, 2005

What is a pattern?

Again, my answer is different. Let's boil down the kind of pattern that we'll be using.

A pattern is something that repeats. It could be a leaf, a tree, the rising & setting of the sun, the Krebs cycle, or a fleur-de-lis motif. It can also be something less pleasant and less positive ... 5-lane highways, wars, greed, propaganda, etc.

So, we'd like to explore positive patterns. The more positive, the better. Which is what positive means.

We also want to explore patterns that are actionable, or operational: something we can do. Although you may feel you can positively influence the rising & setting of the sun, most people don't consider that their daily work.

If it's a positive & operational pattern, then we're talking about Generic actions we can take to improve the world. These can be at various scales. But they all must be essential in our life's work to make things positive. They must make us feel better, and make others feel better.

This is close to Christopher Alexander's emotional starting point for patterns. And his books begat the modern Design Patterns movement in Object-Oriented programming. The fact that the latter has little or no emotional content, is unfortunate. Much has been lost in translation.

Note that I didn't call patterns generic solutions. Instead I say patterns are actions towards making improvements. This is the same thing. I'm trying to point out that a sensitive person doesn't need to use the words 'solution' and 'context' to talk about patterns in Alexander's sense. We only have to note, that an improvement is a positive resolution of forces.

Alexander's positive patterns reflect qualities like freedom, community, cooperation etc. A roasted chesnut vendor on the corner, a market for local produce, a plaza, etc. Note these are all things that can be done badly. The difference between doing them well, and doing them badly, is care & sensitivity to the feeling of people and place. And that can only be achieved through study & experiment to determine the best way to achieve those ends.

So, in the realm of computing, what is a pattern? It's usually something which you realized was important, and which was happening repeatedly, but which you often forgot about amidst the details.

In a LAMP application, one example is "Forget your password?" This is positive pattern, in that it relieves the frustration people feel about "losing their key". It can be done well, or badly ... so we should describe the best sequence for this, in the context of the web today.

1. Click "forget your password?"
2. Type in the e-mail you registered with.
3. Go to your e-mail. Click the link.
4. The link opens in a browser, which asks you for a new password & confirmation.
5. Click "Save new password".

10 years ago, this was essentially an unknown pattern. This is because contexts change. Our 'civilization' is rife with propapanda, environmental degradation, and political & economic disenfranchisement -- who knew that the web would be an important new medium for positive change? So "forget your password" becomes a positive pattern.

Positive & essential, but relatively trivial. Here's a less trivial sequence.

1. Interact with someone.
2. The interaction is registered in public statistics for both of you.
3. These statistics include feedback, which you both leave, about the interaction.
4. This helps others decide whether to interact with you both.

What is this pattern? Of course, it is the essence of eBay. But I'll give it an unusual name:

Build collective knowledge, through individual action.

This is one of the most important patterns on the web, using LAMP or any other platform. It is woefully underused, from a societal perspective. It is used mainly by annotated free market sites like Amazon & eBay. It isn't used to accumulate facts about the consequences of federal spending, for example. Because of this oversight, or lack of it, it's hard to know whether or not some pattern used at the federal level is positive or not. Ot whether the corporation you work for is doing positive things. Or whether your city is spending your tax money in your interest.

Saturday, December 24, 2005

Web patterns in PHP

I have a diiferent view of patterns, and pattern languages, than most programmers. And, although I use and appreciate the work of some of the o-o community, I feel that the notion of patterns goes far deeper than any particular computing notation.

In that spirit, I'm going to present a series of simple patterns, for dynamic websites, in PHP & MySQL. Now, I believe that PHP is a very simple scripting language ... in fact many of its advanced features are unstable. But PHP is in heavy use, in what are known as LAMP applications (Linux Apache Mysql Perl/PHP). I will try to maintain some equivalence between this and a Perl version of this programming diary.