McConnell 2004 Chapter 18 Table Driven Methods Flashcards

1
Q
  1. In what situations does McConnell’s recommend using table driven methods instead of logical statements?
A

A table-driven method is a scheme that allows you to look up information in a table rather than using logic statements (if and case) to figure it out. Virtually anything you can select with logic statements, you can select with tables instead. In simple cases, logic statements are easier and more direct. As the logic chain becomes more complex, tables become increasingly attractive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. What are three main advantages of table-driven code
A

Used in appropriate circumstances, table-driven code is simpler than complicated logic, easier to modify, and more efficient.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. What are the two main issues which need to be addressed if planning a table-driven lookup of information?
A

First you have to address the question of how to look up entries in the table. You can use some data to access a table directly. If you need to classify data by month, for example, keying into a month table is straightforward. You can use an array with indexes 1 through 12.

The second issue you have to address if you’re using a table-driven method is what you should store in the table. In some cases, the result of a table lookup is data. If that’s the case, you can store the data in the table. In other cases, the result of a table lookup is an action. In such a case, you can store a code that describes the action or, in some languages, you can store a reference to the routine that implements the action. In either of these cases, tables become more complicated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. How are table driven methods more flexible that hard coded logic?
A
One advantage of a table-driven
approach is that you can put
the table’s data in a file and
read it at run time. That
allows you to change
something like an insurance rates
table without changing
the program itself.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. What is McConnell’s conclusion after discussing The ‘flexible method format example?
A

????

The format of the messages is volatile, determined by your customer, and you
250 don’t have enough control over your customer to stabilize it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. What are three things you can do if data is not ‘well behaved’ and it is not possible to directly look up a value from a key?
A
  • Duplicate information to make the key work directly
  • Transform the key to make it work directly
  • Isolate the key transformation in its own routine.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. How do ‘indexed access tables’ work?
A

When you use indexes, you use the primary data to look up a key in an index table and then you use the value from the index table to look up the main data you’re interested in.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. How do ‘stair-step access tables’ work?
A

This access method isn’t as direct as an index structure, but it doesn’t waste as much data space.
The general idea of stair-step structures, is that entries in a table are valid for ranges of data rather than for distinct data points.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly