From 39fa584829f5ff4272eae33e5a22d6ba347c3645 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Sat, 16 Jan 2021 15:58:59 +0100 Subject: [PATCH] Provides grammar fixes --- README.md | 84 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 4fcbfed..079d1cd 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,14 @@

# Naming cheatsheet + Naming things is hard. This sheet attempts to make it easier. Although these suggestions can be applied to any programming language, I will use JavaScript to illustrate them in practice. ## Naming convention -Pick **one** naming convention and follow it. It may be `likeThis`, or `like_this`, or anyhow else, it does not matter. What matters is for it to remain consistent. + +Pick **one** naming convention and follow it. It may be `cammelCase`, or `snake_case`, or anyhow else, it does not matter. What matters is for it to remain consistent. ```js /* Bad */ @@ -28,21 +30,22 @@ const should_update = true ## S-I-D -A name must be *short*, *intuitive* and *descriptive*: - * **Short**. A name must not take long to type and, therefore, to remember; - * **Intuitive**. Name must read naturally, as close to the common speach as possible; - * **Descriptive**. Name must reflect what it does/possesses in the most efficient way. +A name must be _short_, _intuitive_ and _descriptive_: + +- **Short**. A name must not take long to type and, therefore, remember; +- **Intuitive**. A name must read naturally, as close to the common speech as possible; +- **Descriptive**. A name must reflect what it does/possesses in the most efficient way. ```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! +const isPaginatable = postsCount > 10 // "Paginatable" sounds extremely unnatural +const shouldPaginatize = postsCount > 10 // Made up verbs are so much fun! /* Good */ const postsCount = 5 -const hasPagination = (postsCount > 10) -const shouldDisplayPagination = (postsCount > 10) // alternatively +const hasPagination = postsCount > 10 +const shouldDisplayPagination = postsCount > 10 // alternatively ``` ## Avoid contractions @@ -65,7 +68,7 @@ A name should not duplicate the context in which it is defined. Always remove th class MenuItem { /* Method name duplicates the context (which is "MenuItem") */ handleMenuItemClick = (event) => { ... } - + /* Reads nicely as `MenuItem.handleClick()` */ handleClick = (event) => { ... } } @@ -77,11 +80,11 @@ A name should reflect the expected result. ```jsx /* Bad */ -const isEnabled = (itemsCount > 3) +const isEnabled = itemsCount > 3 return