/
Giving Literal Values Names

Giving Literal Values Names

Values in code sometimes come dynamically at runtime from sources outside of the code itself (ex. user input). Those have to be stored in some kind of variable. However, many values - numbers, text, etc. - often can be hardcoded in the code itself. When this happens, such values are called literals - they are “literal” textual representations of some value in code.

First step is recognizing that these values don’t have to be used as literals all throughout source code. Usage of literals can often be cryptic. You can instead give literals name to communicate greater understanding, as discussed in the following sections:

 

Related content