Naming code
How to name variables, keys and identifiers so related names group and grow predictably
Start generic, narrow to specific
By starting our names with generic ideas and narrowing to more specific, it’s easier to add adjacent code and ideas that follow the same pattern.
nfd-bluehost-widget-accountis better thanbluehost-account-widgetnfd-module-data-helper-adminis better thandata-module-admin-helper
Prefer specific to vague
Specificity creates a natural growth path without needing to rename or rekey overly generic keys.
nf_account_datais better thannf_accountnf_plugin_updates_cacheis better thannf_plugins
Use singular equivalent to plural in loops
By using the singular variant of a plural, it becomes clear what comes from what. It’s also preferred to avoid using data types as names; please put those in documentation.
| ❌ Avoid | ✅ Preferred |
|---|---|
for post in items |
for post in posts |
for single in posts |
for post in posts |
for object in objects |
for user in users |
Related
-
Naming
General naming principles that apply before any language or platform convention
-
Naming in global namespaces
Defensive prefixing for names that land in a namespace we do not control