naming-cheatsheet
Comprehensive language-agnostic guidelines on variables naming. Home of the A/HC/LC pattern.
A practical written guide to naming variables and functions clearly in any programming language, covering naming rules and a structured A/HC/LC pattern, documentation only, no software to install.
This project is a written guide about how to name variables and functions in your code. Naming things clearly is one of the harder parts of programming, and this cheatsheet collects practical suggestions for doing it well. The examples use JavaScript, but the advice is meant to apply to any programming language.
The guide starts with some general rules. Write names in English, since that is the common language across programming tools and documentation. Pick one naming style, such as camelCase or snake_case, and stay consistent with it. A good name is described as short, easy to read naturally, and descriptive of what the thing holds or does. The author also recommends avoiding shortened words like 'onItmClk', because they make code harder to read for little benefit.
A few more rules cover common mistakes. Do not repeat the surrounding context inside a name, so a method on a MenuItem class can just be called handleClick rather than handleMenuItemClick. Names that describe a state should reflect the result you actually expect, so a button might use isDisabled instead of isEnabled depending on how it reads in the code.
The longest section explains a pattern for naming functions, which the author calls A/HC/LC. The idea is to build a function name from an optional prefix, an action, a high context, and an optional low context. For example, getUserMessages breaks down into the action 'get', the high context 'User', and the low context 'Messages'. The guide then lists common action verbs and what each one signals: get reads data, set assigns a value, reset returns to an initial value, remove takes something out of a collection, delete erases it entirely, compose builds new data from existing data, and handle responds to an event.
There is no software to install here. The repository is documentation only, a reference you read and apply to your own projects. It is widely starred, which suggests many developers find these naming conventions useful as a shared reference.
Where it fits
- Reference the A/HC/LC pattern when naming a new function to choose a clear, consistent name
- Use the action verb list to decide whether a function should be named get, fetch, set, remove, or delete
- Share with your team as a style guide to reduce code review debates about variable and function names