Characters and Strings
This section provides some tips for using strings. The first applies to strings in all languages.
Cross-Reference
Issues for using magic characters and strings are similar to those for magic numbers discussed in Numbers in General.
Avoid magic characters and strings Magic characters are literal characters (such as ‘A’) and magic strings are literal strings (such as "Gigamatic Accounting Program") that appear throughout a program. If you program in a language that supports the use of named constants, use them instead. Otherwise, use global variables. Several reasons for avoiding literal strings exist:
For commonly occurring strings like the name of your program, command names, report titles, and so on, you might at some point ...
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.
Read now
Unlock full access