Prime symbol in variable names: Difference between revisions
(summarize ambiguities around using prime symbol in variable names) |
|||
Line 26: | Line 26: | ||
* Primes: \( a, a', a'', a''', \dots \), | * Primes: \( a, a', a'', a''', \dots \), | ||
* Numbers: \( a_0, a_1, a_2, a_3 \dots \) | * Numbers: \( a_0, a_1, a_2, a_3 \dots \) | ||
* | * Letters: \( a, b, c, d \dots \) |
Latest revision as of 09:32, 13 July 2021
The prime symbol (\(\prime\)) is often used to distinguish between variable names. For example, given a variable \( f \), some authors might use \( f' \) as a separate variable name, which may or may not be related to the original \( f \). If more than one variation is needed, it is not uncommon to see two or more tick marks, as in \( f, f', f'', f''', f'''', \dots \).
Disadvantages
In calculus, the prime symbol is usually used to indicate differentiation, making the use of the prime symbol ambiguous when naming variables.
In some fonts, the tick mark might be too small to read.
This naming convention is popular enough that programming languages like Haskell and Coq permit the single quote symbol '
as a valid identifier. Code is normally displayed in a monospace font, where extra space before the single quote may make the tick mark appear visually separated from the identifier that it modifies.
In monospace fonts, whitespace around the single quote '
often causes it to appear visually separated from the identifier that it modifies. As an example,
Alternatives
For Pairs:
- Primes: (\( f, f' \))
- Numbers: (\( f_0, f_1 \)) or (\( f_1, f_2 \))
- Letter Pairs: (\( f, g \))
For Sequences:
- Primes: \( a, a', a'', a''', \dots \),
- Numbers: \( a_0, a_1, a_2, a_3 \dots \)
- Letters: \( a, b, c, d \dots \)