Technical correspondence: File updating—still once more. author's response
暂无分享,去创建一个
old master file, one called TRANSACTION for a transaction record, and one called NEW-RECORD , in which all records are prepared for the new master file. (Two areas for master records are necessary if insertions occur.) Initially a dummy record with LOW-KEY as key is placed in NEW-RECORD, and the algorithm does not write such a record to the new master file. In the main loop, the first IF statement causes the NEW-RECORD to be written to the new master file as soon as it is clear that no more transactions apply to it. The other IF statement determines whether an old master record or a transaction is to be handled this time. It is not difficult to verify that when this algorithm specifies that a transaction is to be processed, the master record with matching key is in NEW-RECORD if one exists, and if none exists, the transaction key lies between the key for the last new master record written and the one in OLD-RECORD. (Of course, a complete program should check that no matching record exists for insertions, that a matching record does exist for other transactions, and give an error message when these conditions are not met.) Then ordinary transactions like debit and credit are applied to NEW-RECORD. An insertion is done by simply building the new master record in NEW-RECORD. Deletions are best handled by setting the key in NEW-RECORD to LOW-KEY. It is also not difficult to verify that the algorithm handles the cases where the first record in the transaction file precedes the first old master record, or vice versa, or where the first records match, and similarly at the end of the file. I believe that any special conditions such as constraints on the existence of certain types of transactions can be handled as easily in this framework as in the other. I do not know the origin of this algorithm, but note that the idea of processing one record on each execution of the main loop is the basis of RPG, so it is certainly not a new idea. If we are asked to choose between algorithms of roughly similar efficiency , we must appeal to the notion of relative simplicity. Measuring simplicity by the number of loops in the program is totally inadequate. It is well-known that any program can be reduced to a single loop containing a case statement, but …
[1] Michael Jackson,et al. Principles of program design , 1975 .
[2] J. Inglis. Updating a master file—yet one more time , 1981, CACM.
[3] Edsger W. Dijkstra,et al. A Discipline of Programming , 1976 .