What should I name my variable instead of temp or data?

← Variable Naming Rules and Conventions · Ref: Q297

Ask yourself: what does this variable REPRESENT? The answer to that question IS the name. Here are specific alternatives for every banned name.

RENAMING TIER 1 NAMES (E11031)

- temp, tmp -> temporaryUser, calculationResult
- flag, flg -> isValid, hasPermission, wasProcessed
- data, dat -> customerData, configData, requestPayload
- object, obj -> user, order, session
- value, val -> price, count, threshold
- buffer, buf -> inputBuffer, responseBuffer
- arg -> other, item, amount, message

RENAMING OPERATOR KEYWORDS (E11032)

  - empty: isBlank, emptyBasket, noResults, clearedQueue
  - length: nameLength, pathSize, messageCount, arrayExtent
  - contains: hasItem, includesKey, foundMatch, holdingEntry
  - abs: absoluteDistance, magnitude, positiveAmount
  - sqrt: squareRoot, rootApproximation
  - close: closeFile, shutdownConnection, terminateSession
  - matches: foundItems, matchingRecords, searchHits, filteredResults

THE TECHNIQUE

When you reach for a generic name, pause and ask three questions: 1. What kind of thing is this? (a price, a name, a sensor reading) 2. Where did it come from? (user input, database query, calculation) 3. What will it be used for? (display, comparison, accumulation). Any of these answers produces a better name than temp or data.

See Q290 for the complete banned list. See Q296 for why these names are banned. See Q292 for naming conventions.

Example

defines module qa.naming.renameguide

  defines function

    performSwap() as pure
      ->
        firstItem as String
        secondItem as String
      <-
        swappedPair as String: `${secondItem}, ${firstItem}`

    isWidgetItem()
      -> item as String
      <- isMatch as Boolean?

      widgetLabel <- "Widget"
      isMatch: item contains widgetLabel

    retryConnection()
      -> maxAttempts as Integer
      <- connectionAttempts as Integer: 0

      isRetryNeeded <- Boolean(true)
      while isRetryNeeded and connectionAttempts < maxAttempts
        connectionAttempts++
        if connectionAttempts >= maxAttempts
          isRetryNeeded: false

  defines program

    RenamingGuideDemo()
      stdout <- Stdout()

      // === SCENARIO 1: SWAP (temp -> swapHolder) ===

      firstPrice <- 100.0
      secondPrice <- 200.0
      swapHolder <- firstPrice
      firstPrice := secondPrice
      secondPrice := swapHolder
      stdout.println(`Swapped: ${firstPrice}, ${secondPrice}`)

      // === SCENARIO 2: CONDITION (flag -> isRetryNeeded) ===

      connectionAttempts <- retryConnection(3)
      stdout.println(`Connected after ${connectionAttempts} attempts`)

      // === SCENARIO 3: PROCESSING (data -> customerOrders) ===

      customerOrders <- ["Laptop", "Mouse", "Keyboard"]
      orderSummary <- ""
      for orderItem in customerOrders
        if length orderSummary > 0
          orderSummary: orderSummary + ", "
        orderSummary: orderSummary + orderItem
      stdout.println(`Orders: ${orderSummary}`)

      // === SCENARIO 4: COLLECTION STATE (empty -> emptyBasket) ===

      shoppingBasket <- List() of String
      emptyBasket <- length shoppingBasket == 0
      stdout.println(`Basket empty: ${emptyBasket}`)

      widgetName <- "Widget"
      shoppingBasket += widgetName
      hasItems <- length shoppingBasket > 0
      stdout.println(`Has items: ${hasItems}`)

      // === SCENARIO 5: STRING MEASUREMENT (length -> nameLength) ===

      customerName <- "Alice Wonderland"
      nameLength <- length customerName
      longNameThreshold <- 10
      isLongName <- nameLength > longNameThreshold
      stdout.println(`Name: ${customerName}, Length: ${nameLength}, Long: ${isLongName}`)

      // === SCENARIO 6: SEARCH RESULTS (matches -> searchHits) ===

      inventory <- ["Widget", "Gadget", "Widget Pro", "Sprocket"]
      searchTerm <- widgetName
      searchHits <- List() of String
      for inventoryItem in inventory
        if inventoryItem contains searchTerm
          searchHits += inventoryItem
      stdout.println(`Found ${length searchHits} items matching '${searchTerm}'`)

Common mistakes

E11031 — The name 'temp' is non-descriptive and banned. Use 'swapHolder' to describe the variable's role in the swap operation. See ek9 -h E11031 for details.

Incorrect:

      temp <- firstPrice
      firstPrice := secondPrice
      secondPrice := temp

Correct:

      swapHolder <- firstPrice
      firstPrice := secondPrice
      secondPrice := swapHolder

E11032 — The name 'empty' shadows a built-in operator keyword and is rejected. Use a descriptive alternative like 'emptyBasket'. See ek9 -h E11032 for details.

Incorrect:

      empty <- length shoppingBasket == 0
      stdout.println(`Basket empty: ${empty}`)

Correct:

      emptyBasket <- length shoppingBasket == 0
      stdout.println(`Basket empty: ${emptyBasket}`)

E11032 — The name 'matches' shadows a built-in operator keyword and is rejected. Use a descriptive alternative like 'searchHits'. See ek9 -h E11032 for details.

Incorrect:

      matches <- List() of String
      for inventoryItem in inventory
        if inventoryItem contains searchTerm
          matches += inventoryItem
      stdout.println(`Found ${length matches} items matching '${searchTerm}'`)

Correct:

      searchHits <- List() of String
      for inventoryItem in inventory
        if inventoryItem contains searchTerm
          searchHits += inventoryItem
      stdout.println(`Found ${length searchHits} items matching '${searchTerm}'`)
Other ways to ask this
  • How do I rename temp, data, flag, and value in EK9?
  • What are good alternatives to banned variable names in EK9?
  • What descriptive name should I use instead of obj or buf?

Coming from another language?

Java: rename via IDE refactoring (IntelliJ Shift+F6), no compile-time naming enforcement. Python: rename manually or with rope refactoring, no naming enforcement. Rust: rename via rust-analyzer, no naming enforcement for descriptive quality. Go: rename via gopls, no naming enforcement. C/C++: rename via clangd or manual find-replace, no naming enforcement. Kotlin: rename via IntelliJ, no naming enforcement. JavaScript: rename via IDE, ESLint naming rules are optional. EK9: compiler forces you to think about naming at the point of declaration, alternatives shown in error messages.

Keywords: naming, rename, flag, buffer, temp, convention, value, descriptive, guide, instead, practical, identifier, replace, migrate, object, data, alternative