When Visual Basic version 5 hit the streets, Biff Bummer, vice president of software development at Tough Guys, Incorporated, laid down the law:
“Don’t write the same code twice while you’re working for me. I want every line of code coming out of this shop from here on out to be a COM component. Drawing forms isn’t real programming, and we’re not going to pay real programmers to do it. You need a square root? Don’t let me catch you calling the Sqr function in some event procedure on a form. No, you had better call the Square method of a CCalc object. Or better yet, write an XCalc control. We’re not paying ten different people to calculate the same thing ten different places. We write one public calculator class for everybody, and everybody better use it.”
Some wise guy pointed out that Tough Guys sold products to end users, not to developers. End users weren’t likely to buy classes or forms. But Biff had that covered.
“We’ve hired some high school students to come in after school and string your components together into applications.”
This ultimatum was met with skepticism at first. But the policy was not without its supporters and its successes. The official calculator component was indeed written, and it was indeed used by all, despite some quiet grumbling about the pointlessness of using the Subtract method instead of the subtraction operator. Young Joe Hacker Jr. won praise for his complex XWidgit control with its ten-level object hierarchy, starting with CDooDad as the base class and working its way up to the NWonkers collection. And, indeed, a bright high school student was found to create—with a little coaching from Joe—a Wigician application from the component, although it turned out to be a pretty thin wrapper. Still, no one denied that the Wigician was far superior to the old Widgiterium program with its 50 command-line options.
But many programmers felt the component thing was getting a little out of hand. There just might be some code somewhere that didn’t need to be shared with the whole world. Sally Clockstein was leader of the opposition, and everyone knew she was a dangerous opponent. No one was surprised when Biff came to work one morning and found his empty office locked and his personal effects in boxes in the hall. Sally moved in the next day, and Biff’s protégés started shopping their résumés. A week later, Sally laid down the law:
“Interfaces are the wave of the future. I want every class you write from here on out to implement interfaces. Everybody prints; everybody implements IPrint. Everybody walks; everybody implements IVariantWalker. Everybody loves me; everybody implements ILoveYou.
This edict was met with the wild enthusiasm reserved for all such cultural revolutions. But gradually, hard disks began to fill up with COM components implementing such interfaces as IPlus, IMinus, and IEnthusiasm.
Every parable has its limit, and this one passed its limit some time ago. So let’s cut to the moral: use COM, but don’t let it use you. Alas, I’m going to ignore my own advice throughout most of this chapter. I’ll be doing some fairly obscure tasks and looking behind some out-of-the-way curtains (whether or not I have permission). Who knows? You might even run across one or two practical techniques that you can use in real programming projects.