Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-862

Declared variables in scripts shouldn't be added to the binding

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-JSR-5
    • 1.0-JSR-5
    • None
    • None

    Description

      When a variable is declared or defined in a script, it should not be added into the binding.

      def a = 1
      String b = "foo"

      Both these variables are local to the script and should not be in the binding.

      If someone wants to add a variable to the binding, we should use setProperty("foo", "bar") or simply write:

      a = 1
      b = "foo"

      Putting variables explicitely improves the readability of the code.

      And that way, we'll be able to provide type checking in scripts as well, because currently, even if you define a string, you can assign it an integer, because it's simply overriding the variable in the binding.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            guillaume Guillaume Sauthier
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: