explaingit

kettanaito/naming-cheatsheet

14,205Audience · developerComplexity · 1/5Setup · easy

TLDR

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.

Mindmap

mindmap
  root((naming-cheatsheet))
    Core rules
      Use English
      Stay consistent
      Short and descriptive
    A/HC/LC pattern
      Action verb
      High context
      Low context
    Action verbs
      get vs fetch
      set and reset
      remove vs delete
    What to avoid
      Abbreviated names
      Repeating context
    Audience
      All developers
      Code reviewers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Reference the A/HC/LC pattern when naming a new function to choose a clear, consistent name

USE CASE 2

Use the action verb list to decide whether a function should be named get, fetch, set, remove, or delete

USE CASE 3

Share with your team as a style guide to reduce code review debates about variable and function names

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

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.

Copy-paste prompts

Prompt 1
Using the A/HC/LC naming pattern from the naming-cheatsheet, suggest names for a function that fetches the current user's profile from an API.
Prompt 2
I have a function that removes an item from a shopping cart in memory. According to naming-cheatsheet conventions, what should it be called and why?
Prompt 3
Review this JavaScript code: [paste code]. Are the variable and function names following naming-cheatsheet conventions? Suggest specific improvements.
Prompt 4
What is the difference between get, fetch, and request as action verbs in function names according to the naming-cheatsheet?
Open on GitHub → Explain another repo

← kettanaito on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.