Skip to content

Style Guide

Santhosh Kumar Devadoss edited this page Oct 27, 2023 · 1 revision

The 3 Cs of Great Naming

Concise and Consistent Naming paper

  • Consistent ( Identifier needs to be unique enough to convey the concept )
  • Concise ( Identifier needs to accurately convey the concept and minimize related concept space as much as possible )
  • Correct ( Identifier needs to convey what is actually being assigned. )

Great code is understood; rarely is it interpreted.

Variable Variables

Booleans

can only be one of two values: true or false

isSomething
Examples: isUpgrade, isApproval, isProMember
doesSomething
Examples: allowWhitespace, willUpdate, didRestart
hasSomething
Examples: hasMoreThanOneWarning, hasMultipleDiscounts, hasException

Condition: return True if at least one user is active
const {something} = users.some(user => user.isActive);

isUsersActive
isAtLeastOneUserActive
isOneUserActive
isSomeUserActive
isAnyUserActive
hasActiveUsers

Integers

Things understood to be numbers; counts/number of something.

{integer itself}
age, year, MAXIMUM_ALLOWED_LOGIN_ATTEMPTS, tooltipDisplayMilliseconds
numberOfSomething
numberOfRetries, numberofDescendants, numberOfAccounts, numberOfDaysWithoutRain
somethingCount
failureCount, retryCount, currentCakeInventoryCount

condition: return number of eligible discount items that are part of a customer's order.
numberOfEligibleItemsWithinTransaction
numberOfEligibleItemsInTransaction
numberOfEligibleItems
numberOfEligibleDiscountItems

Floating-Point Numbers

Unordered measures, numbers that are not integers

{{floating-point itself}}
height, weight, priceInDanishKrone, angleInDegrees, highTemperatureInFarenheit
somethingAmount
discountAmount, transferAmount, refundAmount

Strings

Labels: typically a sequence of characters

{entity itself} fullGivenName, city, shortSpeakerBiography, playerSelectedClass, definition
somethingAsString monthAsString, timeZoneAsString

Collections

Arrays, Lists, or sets, groups of things

{plural form of thing}
robots, sentientRobots, discountedProducts, customers, newlyReleasedBooks
implementationOfThings
unOrderedListOfCustomers, queueOfFirstPriorityTasks, orderedSetOfTimeStamps

Maps

Accessing values by keys

keyToValueMap
bookIdToAuthorMap, customerTooOrderTotalMap, productIdToSupplierMap

Pairs & Tuples

Typically stored together and items of the same type

firstPairAndSecondPair
lengthAndWidth, setsAndRepititions, currentAndLifetimeXP, genusAndSpecies

firstSecondAndThirdThing
heightWidthAndDepthInCentimeters, saturatedTransAndTotalFatInGrams, redGreenBlueAndAlpha

Clone this wiki locally