Skip to Main Content
Prefactoring
book

Prefactoring

by Ken Pugh
September 2005
Intermediate to advanced content levelIntermediate to advanced
240 pages
6h 28m
English
O'Reilly Media, Inc.
Content preview from Prefactoring

5.2. Declaration Versus Execution

Example 5-5 with arrays rather than separate methods illustrates the difference between using declarative-style and executable-style code to express an operation. The base_rental_period_per_category array is an example of declarative style. If you want to change the base period for a category, you do not change the internal operations of a method, just the values in a table. Because the values are in a table, this is often referred to as table-driven code . I use the term declarative-style programming to encompass any form of coding in which the design permits expected changes to be made in anything other than executable code. This includes table-driven code and configurable code.

With tables in source-code files, the code will have to be recompiled if the values change. Instead of hardcoding these values into the source, you could read in the values from a configuration file. The implementation of the configuration file could employ comma-delimited files, XML, or a database. The configuration data acts in a declarative-style mode. It contains information on what needs to be done, without specifying how it is done.

With a configuration file, the source program code does not change, even if a new CDCategory is added. We could add hundreds of new categories without an additional line of code. The configuration file would contain additional data on the new categories.[*]

[*] If Sam was going to be adding new categories or altering data for existing ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Understanding Unittest.Mock

Understanding Unittest.Mock

Mario Corchero
Java™ Performance

Java™ Performance

Charlie Hunt, Binu John

Publisher Resources

ISBN: 0596008740Supplemental ContentCatalog PageErrata