Skip to content

Guide · Open source

How to use naming-cheatsheet: rules for variable and function names

Updated · written with AI from the project's own documentation and checked against our catalogue data

naming-cheatsheet is a written style guide by kettanaito that explains how to choose clear names for variables and functions. It is a reference document, not a program, so there is nothing to install beyond getting a copy of the repository or reading it online. After this guide you will know the main naming rules it teaches and how to apply the A/HC/LC pattern to function names.

Naming cheatsheetkettanaito/naming-cheatsheet · ★ 14.2k · MIT

Quick start

  1. 1Open the guide. Read the README on GitHub or clone the repository with the given git command.
  2. 2Pick one naming convention. Choose camelCase, PascalCase, snake_case or another style and use it consistently.
  3. 3Check names against S-I-D. Make each name short, intuitive and descriptive, and remove contractions.
  4. 4Remove duplicated context. Drop words that the surrounding class or module already states.
  5. 5Build function names with A/HC/LC. Add an action verb, then high context, then optional low context and prefix.
  6. 6Pick the right verb. Use get, set, reset, remove, delete, compose or handle according to the definitions in the guide.

Get the naming-cheatsheet guide

The guide is a README document, so you can simply read it online on GitHub. If you prefer a local copy, the README gives a clone command for the repository.

git clone https://github.com/kettanaito/naming-cheatsheet

Start with the core naming rules

The first sections set the baseline. Use English for names. Pick one naming convention, such as camelCase, PascalCase or snake_case, and keep it consistent across your code. Avoid contractions, so write onItemClick rather than onItmClk.

  • Use English when naming variables and functions.
  • Pick one naming convention and follow it everywhere.
  • Make names Short, Intuitive and Descriptive (S-I-D).
  • Do not use contractions.
  • Do not repeat the surrounding context in a name, such as handleClick inside a MenuItem class instead of handleMenuItemClick.
  • Make the name reflect the expected result, such as isDisabled instead of a negated isEnabled when that reads better in the code.

Name functions with the A/HC/LC pattern

The guide gives this pattern for function names: an optional prefix, then an action (A), then high context (HC), then an optional low context (LC). The order matters because high context carries the main meaning. The README's example is that shouldUpdateComponent means you are about to update a component, while shouldComponentUpdate means the component updates itself.

  • getUser: action get, high context User.
  • getUserMessages: action get, high context User, low context Messages.
  • handleClickOutside: action handle, high context Click, low context Outside.
  • shouldDisplayMessage: prefix should, action Display, high context Message.
prefix? + action (A) + high context (HC) + low context? (LC)

Choose the right action verb

The guide defines several action verbs. Use get for direct access to data, set to assign a value, and reset to return a value to its initial state. Use remove when taking something out of a collection and delete when erasing something completely. Use compose to create new data from existing data, and handle for callbacks.

  • get: accesses data immediately, including async reads.
  • set: sets a variable from value A to value B.
  • reset: returns a variable to its initial value or state.
  • remove: takes something from somewhere, such as removeFilter.
  • delete: completely erases something, such as deletePost.
  • compose: creates new data from existing data.
  • handle: handles an action, often a callback like handleLinkClick.

Use prefixes for booleans and limits

Prefixes make a variable's meaning clearer. The guide uses is for a characteristic or state, has for whether something holds a value, and should for a positive condition tied to an action. It also covers min and max, which the excerpt you have cuts off before explaining.

  • is: isBlue, isPresent.
  • has: hasProducts is preferred over isProductsExist or areProductsPresent.
  • should: shouldUpdateUrl.

Apply the guide during code review

Teams can link the guide in review comments when a name is unclear. Each section pairs a Bad and a Good example, so a reviewer can point to the rule and show the fix. The guide says its ideas apply to any language, though its examples are in JavaScript and it defers to each language's own conventions.

  • Quote the section heading that matches the problem.
  • Show the Bad and Good example pair from that section.
  • Check your language's documentation for official conventions.

What people use it for

  • Writing a consistent naming rule set for a team's shared codebase.
  • Reviewing a pull request and linking the relevant section for a unclear name.
  • Choosing between remove and delete for a UI action such as clearing a filter.
  • Naming boolean variables with is, has and should prefixes.
  • Teaching students how to name variables and functions in a course.

Frequently asked questions

Is naming-cheatsheet free to use?

The repository is released under the MIT licence, according to its listing. The guide is a README document you can read online without an install step.

Do I need to install anything to use naming-cheatsheet?

No. It is a written reference with no install step, and the README lists no prerequisites. The only command it gives is git clone for getting a local copy.

Is naming-cheatsheet only for JavaScript?

No. The examples are written in JavaScript, but the author states the suggestions can be applied to any programming language.

What is the A/HC/LC pattern?

It is the function naming pattern in the guide: an optional prefix, an action (A), high context (HC) and optional low context (LC). The guide says high context carries the main meaning, so word order matters.

When should I use remove instead of delete?

The guide says remove takes something out of somewhere, such as removeFilter from a set of selected filters. Delete completely erases something, such as deletePost in a CMS.

Are there alternatives to naming-cheatsheet?

The listing does not name any comparable projects, so this page does not recommend specific alternatives. For official conventions, the README points readers to each language's own documentation.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Use naming-cheatsheet if you want a short, example-driven reference for consistent names, especially for a team review or a shared style guideline. Skip it if you need a tool to install or rules specific to one language's official conventions, since the guide defers to each language's documentation on those.

Install options & downloads