We have an application that consists binary files (containing a mix of text and numeric information) and programs written in various languages that create, modify and read these binary files. Because the text fields are stored in a binary file, an individual text field is stored in a binary file as a fixed number of bytes at a specified offset in that binary file. (If a text field has fewer characters, the remaining bytes are set to 0.)
There are numerous developers (in different internal organizations) who are involve in maintaining and adding new features to the all the programs that constitute this application.
One of the chronic issues we deal with is code that string comparisons often fail because the stored field may or may not have trailing whitespace, depending on how that specific field gets entered and written to the binary file, and the string in the code being compared does not. (In almost all cases, the trailing whitespace is not considered to be part of the text field value).
There are different approaches we can take to dealing with this situation:
Adopt a convention that all fields stored in a binary file must be trimmed before being written.
Adopt a convention that when comparing text, the comparison should be performed with trimmed strings.
Do both (1) and (2).
Are there any measurable advantages to suggest that one of the above approaches is better than any of the other approaches. The overall goal is to reduce the number of instances of an application error caused by trailing whitespace.
Note -- Currently we are doing (2), but we recently found legacy code that was not ignoring the trailing whitespace.