From the front lines
Data Migration
The Solo Developer
On Sophistication

On Sophistication

Here is a definition: sophistication is the process of disguising every flaw to give the appearance of perfection.

In the movie Miss Congeniality actress Sandra Bullock plays the part of a decidedly unsophisticated FBI agent who has to infiltrate a beauty pageant. The movie is a wonderful analysis of sophistication.

Of course a well designed program must present a perfect front to the user. It must be sophisticated. That is not my concern here. I am thinking of the way things work inside the program. Look at this example, taken from a program I wrote some time ago:

  if _nbLottery.ActivePage = 'pgLottery' then begin
Caption := Format(CapFmt, [Msg(mPageCaptionLottery)]);
dmLottery.tblCompetitionType.Active := True;
dmLottery.tblPrize.Active := True;
pcLotteryChange(Sender); { Set Focus Control }
end else
if _nbLottery.ActivePage = 'pgCompetition' then begin
Caption := Format(CapFmt, [Msg(mPageCaptionCompetition)]);
dmLottery.tblCompetition.Active := True;
dmLottery.tblPrize.Active := True;
dmLotteryLookup.lkpCompetitionType.Active := True;
end else
if _nbLottery.ActivePage = 'pgMngBankAccount' then begin
Caption := Format(CapFmt, [Msg(mPageCaptionMngBankAccount)]);
dmLottery.tblBankAccount.Active := True;
end else
if _nbLottery.ActivePage = 'pgRunCompetition' then begin
Caption := Format(CapFmt, [Msg(mPageCaptionRunCompetition)]);
dmLottery.tblActiveCompetition.Active := True;
end else

Everything is shown in its awful glory. Other bits of relevant code is scattered about. The thing is a mess.

There is a programming technique for tidying up this kind of code. It is called refactoring. Like refactoring in algebra, this process brings together like terms. With suitable renaming, you can avoid the repetition. When this has been done to code such as this, the result is two types of code: generalized code that can be used in many contexts, and code specific to the task at hand. Sophistication comes about because all the horrible details are now hidden from view. The wonderful thing is that the generalized code can be used in contexts never thought of before.

Encouraged by this, I started to identify code that could usefully be generalized I isolated the generalized code and started incorporating it in an application framework. The aim was to take advantage of the best code I had produced to date when starting a new project. Any new generalized code developed for the project gets incorporated in the framework. The result is a growing body of tested solutions that I can bring to bear on problems I need to solve.