|Ada 95 Quality and Style Guide||Chapter 8|
8.4.6 Table-Driven Programming
Write table-driven reusable parts wherever possible and appropriate.
The epitome of table-driven reusable software is a parser generation system. A specification of the form of the input data and of its output, along with some specialization code, is converted to tables that are to be "walked" by preexisting code using predetermined algorithms in the parser produced. Other forms of "application generators" work similarly.
Table-driven (sometimes known as data-driven) programs have behavior that depends on data with'ed at compile time or read from a file at run-time. In appropriate circumstances, table-driven programming provides a very powerful way of creating general-purpose, easily tailorable, reusable parts.
See Guideline 5.3.4 for a short discussion of using access-to-subprogram types in implementing table-driven programs.
Consider whether differences in the behavior of a general-purpose part could be defined by some data structure at compile- or run-time, and if so, structure the part to be table-driven. The approach is most likely to be applicable when a part is designed for use in a particular application domain but needs to be specialized for use in a specific application within the domain. Take particular care in commenting the structure of the data needed to drive the part.
Table-driven programs are often more efficient and easier to read than the corresponding case or
if-elsif-else networks to compute the item being sought or looked up.
|< Previous Page||Search||Contents||Index||Next Page >|