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.4. Communicate with Text

Text is an excellent way to communicate between systems. You do not need to worry about the homogeneity of the systems. The physical representation of primitives, such as a double, in each of two systems can be different. The text form is the lingua franca into which each system translates its primitive values. The text can be unformatted or formatted, such as comma-delimited files or XML. In addition, the text form can be read by a human tester and can easily be created to fashion data-dependent tests.[*]

[*] See The Art of UNIX Programming by Eric S. Raymond (Addison-Wesley Professional, 2003) for a discussion on text.

Text inside a system is a different matter. When text strings are read into a program, they should be converted into the corresponding data types as soon as possible. Performing this conversion separates the external presentation of the information to the user and to other programs from the internal usage of that same information. If there is an error in the representation, the failure will appear in the translation process, not later on when you are trying to process the data.

We defined the CDCategories used in the previous section with an enumeration. If the values for a CDCategory were kept in a configuration file, it might be denoted in that file as the string "GoldenOldie." When reading in that data, this string value should be converted to the corresponding enumeration value. If the input string is misspelled or does not match ...

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