Cover by Steve McConnell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required