Naming variables

17 Apr 2021

1. Naming integers
    numberOf<something>
         numberOfFailures
    <something>Count   
         failureCount

2. Naming floating-point numbers
    <something>Amount
          rainfallAmount, moneyAmount
    If unit not clear, add description
          widthInCentimeters, rainFallAmountInInchesPerHour, failurePercent

3. Naming boolean
     isSomething, hasSomething, doesSomething, didSomething, shouldDoSomething, willDoSomething
     isDisabled, hasErrors, allowsWhitespace, didUpdate

4. Naming strings
    name, title, city, country
    If integer number as strings: <someValue>String, <someValue>AsString
    yearAsString

5. Naming arrays, lists
    Always use plural form of noun: customers, errors, tasks
    And specify implementation of name:  queueOfTasks, stackOfCards, orderedSetOfTimestamps
    ❌ non-plural form: customerList, handledOperationSet

6. Naming objects
    Person class -> object is person, Account class -> object is account, ...

7. Naming static
    snake_case in capital letters: TOOLTIP_SHOW_DELAY_IN_MILLISECS

Others:

Do not use:

❌ i or k in loops

✅ index or Index

❌ num, val, tmp

Link