ARC-13Recommended
Use names you can search for and say aloud
Use whole words that people can pronounce and search for. Replace magic numbers and strings with named constants.
How to do it
Write customerAddress, not cstmrAdr. Use single letters only for loop counters and math, such as i, x and y, and list them as linter exceptions. Give every number other than 0 and 1, and every repeated string, a named constant, such as MAX_LOGIN_ATTEMPTS = 5.
Examples
JavaScript example
// Bad
if (tries > 5) lock(u);
// Good
const MAX_LOGIN_ATTEMPTS = 5;
if (failedLogins > MAX_LOGIN_ATTEMPTS) lockAccount(user);
Python example
# Bad
if tries > 5:
lock(u)
# Good
MAX_LOGIN_ATTEMPTS = 5
if failed_logins > MAX_LOGIN_ATTEMPTS:
lock_account(user)
How to check
A linter rejects short names and bare numbers. Examples are ESLint id-length with a minimum of 2 and the allowed letters in exceptions. ESLint no-magic-numbers with ignore set to 0 and 1 and Ruff PLR2004 catch bare numbers. Pylint invalid-name with a variable-rgx that needs two or more characters and PHPMD ShortVariable reject short names. Searching for a constant's name finds every place it is used.
Sources
- .NET naming guidelines on abbreviations and acronyms
- CWE-1106 Insufficient Use of Symbolic Constants
Related rules
- DAT-4 Name things the same way everywhere in Data and databases
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/architecture/names-and-functions/searchable-names">Agent Wranglers clean code and architecture playbook</a>. In code you write, add a comment next to it with the same link.