Friday, October 23, 2009

The Siren Call of Abstraction

To be a great programmer you must master the use of abstraction. I don't care how big your brain is, if you can't abstract away details, your code will get bogged down in them. To a large degree, modern languages are all designed to help programmers with tools for managing complexity through powerful abstractions.

I know some good programmers who are quite productive despite having mostly low-abstraction tools in their tool set. For example, I know programmers who implement almost any collection of objects using linked lists, with the link implemented as a next pointer embedded inside the object, something like this:

class SomeObject
{
public:
    SomeObject(SomeObject* next) : mNext(next) {}
    SomeObject* Next() const { return mNext; }
    ...
private:
    SomeObject* mNext;
};

This is a fine choice for some problems, but it is a suboptimal choice for most problems. One pragmatic reason is that objects implemented this way can only belong to one collection at a time. The bigger problem comes simply from coupling together the two concepts of Object and Containment. If the programmer sees the next pointer as just another attribute of the object, then the methods of the object will probably blur the different operations, with one line of code manipulating the object's state, and the next line of code manipulating the container state, and no clear demarcation between the two fundamentally different abstract operations.

But what does this have to do with The Siren Call of Abstraction? Well, good programmers can be productive despite not having mastered the use of abstraction. But being obsessed with abstractions can be a major hindrance to productivity. A couple different posts crossed my RSS feed today that made me think about this topic.

First, Joel Spolsky wrote recently about the virtues of Duct Tape Programmers. He sings the glories of programmers who get the job done with simple tools analogous to duct tape and WD-40, and ridicules programmers who love multiple inheritance. As usual Joel is a fun read.

But Joel only ridicules some caricature of a programmer. DPP's tweet today was about a specific programmer and is far more damning, so much so that I feel sorry for the subject of his scorn.

No comments:

Post a Comment