Global Namespaces
Sometimes we need to execute code in a global namespace in PHP or JavaScript, or key data in databases and caches in environments we don’t control.
Common database keys like api_url
, plugin_config
or system_status
could be set by another codebase – so we need to be defensive with our naming.
General Best Practice
- Most constants, variables and methods should receive an
nfd
prefix. - This is a global namespace. Be defensive, clear and courteous. Safety and clarity over brevity.
- Consistiently use a product prefix after the company prefix to aid locating code (i.e. searching
nfd_performance_module_
to find all hooks). - Avoid jargon and acronyms in handles. Save it for inline documentation!
Examples
nfd_api_url
nfd_system_status
nfd_brand_config
nfd-brand-widget
nfd_register_modules()
The notable exception being something well-prefixed where the nfd
is overly-verbose:
wp-plugin-bluehost-admin
is a fine asset handle, a nfd-
prefix is overkill.