Archive for March, 2009

The Wise Men of Chelm

March 28, 2009

   

The wise men of Chelm are a gallery of wrong decision making. For example:

The wise men of Chelm discussed how to make the Chelmians in general wiser. They decided that stupid people should not have children. To achieve that, they decided to make the village shtetl idiot divorce his wife. “But he isn’t married”, someone objected. So the wise men decreed that the idiot should marry and then divorce.

That’s right. Set an intermediate goal and forget the final one. Large bureaucracies such as ministries and government agencies do that all the time.

The bridge at Chelm was dangerous: People passing over the bridge would slip at its end and break their arms or legs. So the wise men of Chelm decreed to build a hospital next to the bridge.

Programmers call that patching.

The Chelmians wanted to build a public bath. However, they couldn’t make up their minds whether to rasp the floor boards. For if they didn’t, people might get splinters in their feet, but if they did rasp and the boards were smooth, people might slip on the wet floor and fall. After discussing the matter for several days, the wise men decreed: The carpenter must rasp the boards but put them smooth side down.

Conflicting goals. And so on.

The wise men of Chelm live among us. Unfortunately, some of us are their employees.

Multivac

March 23, 2009

   

Isaac Asimov thought there would be a Multivac storing and processing data on all the people on Earth. In fact, he was quite close. Only there are several such Multivacs, each with its own part of the data. What Asimov missed completely is that the data is entered voluntarily, and most of it is publicly available.

Framework as an anti-pattern

March 14, 2009

Framework is certainly a pattern, but it often becomes an anti-pattern. I’ve heard someone say that this antipattern is inevitable in large systems, but I believe that avoiding it is a matter of keeping two simple rules in mind all the time:

Make interfaces as unrestricted as possible.

Create utilities for working in a certain way rather than requiring the user to work in that way.

As an example, consider an application like Photoshop. How do you design filters, keeping in mind that an image doesn’t necessarily fit in memory? An obvious solution would be this:

class IFilter
{
public:
  ImageBuffer Transform(const ImageBuffer& buf) = 0;
};

(Actually, the output buffer is smaller than the input buffer, and you have to express that somehow, but that’s not the point.) So now you have either a class or a function that uses IFilter to convert a complete image, and all is well.

This works for some time, and then you want to create a geometric morphing filter, and the IFilter design doesn’t suit it. So you create IGeometricTransformation, that converts a Point2d to another Point2d. But then you need to create some new filter that doesn’t work in any of these two ways, and you start twisting the design to accommodate for it. Gradually you get a mess.

The corrected design would be this:

class IFilter
{
public:
  ImageDocument* Transform(const ImageDocument& doc) = 0;
};

class LocalizedFilter : public IFilter
{
public:
  ImageDocument* Transform(const ImageDocument& doc);
private:
  ImageBuffer Transform(const ImageBuffer& buf) = 0;
};

class MorphingFilter : public IFilter
{
public:
  ImageDocument* Transform(const ImageDocument& doc);
private:
  Point2d Transform(const Point2d& pt) = 0;
};

That is, specific partial filter implementations are given as utilities rather than rigid rules, and IFilter is the least restrictive possible interface for a filter.

In the next post I’ll take this simplification one step further.

Leave the campsite cleaner than you found it

March 12, 2009

In Clean Code: A Handbook of Agile Software Craftsmanship I’ve read this very useful rule:

If we all checked-in our code a little cleaner than when we checked it out, the code
simply could not rot. The cleanup doesn’t have to be something big. Change one variable
name for the better, break up one function that’s a little too large, eliminate one small bit of
duplication, clean up one composite if statement.

Or delete some unused or commented-out code.