├── .github └── FUNDING.yml ├── LICENSE.md ├── README.md └── naming-cheatsheet.png /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: kettanaito 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018—preset Artem Zakharchenko 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Naming cheatsheet 4 | 5 |

6 | 7 | # Naming cheatsheet 8 | 9 | - [English language](#english-language) 10 | - [Naming convention](#naming-convention) 11 | - [S-I-D](#s-i-d) 12 | - [Avoid contractions](#avoid-contractions) 13 | - [Avoid context duplication](#avoid-context-duplication) 14 | - [Reflect the expected result](#reflect-the-expected-result) 15 | - [Naming functions](#naming-functions) 16 | - [A/HC/LC pattern](#ahclc-pattern) 17 | - [Actions](#actions) 18 | - [Context](#context) 19 | - [Prefixes](#prefixes) 20 | - [Singular and Plurals](#singular-and-plurals) 21 | 22 | --- 23 | 24 | Naming things is hard. This sheet attempts to make it easier. 25 | 26 | Although these suggestions can be applied to any programming language, I will use JavaScript to illustrate them in practice. 27 | 28 | ## English language 29 | 30 | Use English language when naming your variables and functions. 31 | 32 | ```js 33 | /* Bad */ 34 | const primerNombre = 'Gustavo' 35 | const amigos = ['Kate', 'John'] 36 | 37 | /* Good */ 38 | const firstName = 'Gustavo' 39 | const friends = ['Kate', 'John'] 40 | ``` 41 | 42 | > Like it or not, English is the dominant language in programming: the syntax of all programming languages is written in English, as well as countless documentations and educational materials. By writing your code in English you dramatically increase its cohesiveness. 43 | 44 | ## Naming convention 45 | 46 | Pick **one** naming convention and follow it. It may be `camelCase`, `PascalCase`, `snake_case`, or anything else, as long as it remains consistent. Many programming languages have their own traditions regarding naming conventions; check the documentation for your language or study some popular repositories on GitHub! 47 | 48 | ```js 49 | /* Bad */ 50 | const page_count = 5 51 | const shouldUpdate = true 52 | 53 | /* Good */ 54 | const pageCount = 5 55 | const shouldUpdate = true 56 | 57 | /* Good as well */ 58 | const page_count = 5 59 | const should_update = true 60 | ``` 61 | 62 | ## S-I-D 63 | 64 | A name must be _short_, _intuitive_ and _descriptive_: 65 | 66 | - **Short**. A name must not take long to type and, therefore, remember; 67 | - **Intuitive**. A name must read naturally, as close to the common speech as possible; 68 | - **Descriptive**. A name must reflect what it does/possesses in the most efficient way. 69 | 70 | ```js 71 | /* Bad */ 72 | const a = 5 // "a" could mean anything 73 | const isPaginatable = a > 10 // "Paginatable" sounds extremely unnatural 74 | const shouldPaginatize = a > 10 // Made up verbs are so much fun! 75 | 76 | /* Good */ 77 | const postCount = 5 78 | const hasPagination = postCount > 10 79 | const shouldPaginate = postCount > 10 // alternatively 80 | ``` 81 | 82 | ## Avoid contractions 83 | 84 | Do **not** use contractions. They contribute to nothing but decreased readability of the code. Finding a short, descriptive name may be hard, but contraction is not an excuse for not doing so. 85 | 86 | ```js 87 | /* Bad */ 88 | const onItmClk = () => {} 89 | 90 | /* Good */ 91 | const onItemClick = () => {} 92 | ``` 93 | 94 | ## Avoid context duplication 95 | 96 | A name should not duplicate the context in which it is defined. Always remove the context from a name if that doesn't decrease its readability. 97 | 98 | ```js 99 | class MenuItem { 100 | /* Method name duplicates the context (which is "MenuItem") */ 101 | handleMenuItemClick = (event) => { ... } 102 | 103 | /* Reads nicely as `MenuItem.handleClick()` */ 104 | handleClick = (event) => { ... } 105 | } 106 | ``` 107 | 108 | ## Reflect the expected result 109 | 110 | A name should reflect the expected result. 111 | 112 | ```jsx 113 | /* Bad */ 114 | const isEnabled = itemCount > 3 115 | return