Naming cheatsheet

# Naming cheatsheet Naming things is hard. Let's make it easier. The purpose of this document is to break down and systematize the concepts and patterns commonly used for variable naming. Beware that *variable* in this document refers to variables, methods, and generally anything created during your programming work. ## Summary * [Guidelines](#guidelines) * [HC/LC Pattern](#hclc-pattern) * **[Actions](#actions)** * [get](#get) * [fetch](#fetch) * [set](#set) * [reset](#reset) * [remove](#remove) * [delete](#delete) * [compose](#compose) * [handle](#handle) * **[Prefixes](#prefixes)** * [is](#is) * [has](#has) * [should](#should) * [min/max](#minmax) * [prev/next](#prevnext) ## Guidelines * Pick **one** naming convention and follow it. Whether it is `likeThis`, or `like_this`, or anyhow else, it does not matter. What matters is consistency in your work. ```js /* Bad */ const pages_count = 5; const shouldUpdate = true; /* Good */ const pagesCount = 5; const shouldUpdate = true; /* Good as well */ const pages_count = 5; const should_update = true; ``` * Name, whether of a variable, method, or something else, should be *short*, *descriptive* and *intuitive*: * **Short**. Variable should not take long to type and, therefore, to remember, * **Descriptive**. Name of the variable should reflect what it does/possesses in the most efficient way, * **Intuitive**. Name of the variable should read naturally, as close to the common speach as possible ```js /* Bad */ const a = 5; // "a" could mean anything const isPaginatable = (postsCount > 10); // "Paginatable" sounds extremely unnatural const shouldPaginatize = (postsCount > 10); // Made up verbs are so much fun! /* Good */ const postsCount = 5; const shouldDisplayPagination = (postsCount > 10); ``` * Do *not* use contractions. The latter contribute to nothing but decreased code readability. Finding a short, descriptive name may be hard, but don't think contractions help you in any way. ```js /* Bad */ const onItmClck = () => {}; /* Good */ const onItemClick = () => {}; ``` * Name should not duplicate the context when the latter is known, and when removing the context does not decrease the name's readability: ```js class MenuItem { /* Method name duplicates the context it is in (which is "MenuItem") */ handleMenuItemClick = (event) => { ... } /* This way it reads as MenuItem.handleClick() */ handleClick = (event) => { ... } } ``` * Name should reflect the expected result: ```js /* Bad */ const isEnabled = (itemsCount > 3); return (