Rename Symbol

Rename Symbol renames a name and every use of it, wherever it is. Here temp says nothing of what it holds, so EK9 refuses it - E11031, explained in the Hovers panel - as it refuses flag, data, value and the others below it. To play it in the IDE: Help > Lessons > Refactoring…, or ek9 -ide -lesson rename-symbol.

The EK9 IDE as the lesson opens: the code to read and, in the Hovers panel, its error explained

Start from

The code the lesson starts from: copy it into a file of your own and follow the steps.

Fails with E11031: non-descriptive variable name - use meaningful identifier

#!ek9
defines module error.e11031.bad

  defines function

    process1()
      <- result as String: ""
      temp <- "mainValue"
      result: temp

    process2()
      <- result as Boolean: false
      flag <- true
      result: flag

    process3()
      <- result as String: ""
      data <- "info"
      result: data

    process4()
      <- result as Integer: 0
      value <- 42
      result: value

    process5()
      <- result as String: ""
      obj <- "something"
      result: obj

    process6()
      <- result as String: ""
      buf <- ""
      result: buf

    process7()
      ->
        tmp as String
      <-
        result as String: ""

      result: tmp

    process8()
      ->
        val as Integer
      <-
        result as Integer: 0

      result: val

Step 1: Where it is

Put the caret on temp, on line 8.

The EK9 IDE once this is done: Put the caret on temp, on line 8

Step 2: Rename Symbol

Choose Refactor > Rename Symbol…

The EK9 IDE once this is done: Choose Refactor > Rename Symbol…

Type the new name, mainText - what it holds - and choose Preview.

The EK9 IDE just before choosing Preview: Type the new name, mainText - what it holds - and choose Preview

Step 3: Preview and apply

The preview shows every change the refactoring makes; then the IDE formats each file it changed. Choose Apply.

The EK9 IDE just before choosing Apply: The preview shows every change the refactoring makes; then the IDE formats each file it changed

The result

That is Rename Symbol: temp is mainText, at its declaration and its use. The seven names below it are the same refactoring - try one yourself. Shift+F6 opens it; AI assistants use the ek9_rename_symbol tool.

The EK9 IDE when the lesson has finished

Where this lesson comes from