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

Consider with() block/statement for "importing" methods into a namespace

    XMLWordPrintableJSON

Details

    • Wish
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.0-JSR-4
    • None
    • None

    Description

      For long variable names, it might be useful to have a with() block-oriented statement for doing naming.

      ie.:
      longVariableName.x();
      longVariableName.y();
      longVariableName.property.z();

      becomes:
      with( longVariableName )
      {
      x();
      y();
      property.z();
      }

      A global statement version could be used to import names and objects.

      with java.lang.Math;

      would have the effect of making all the Math.* fields and methods accessible without offset. That said, "import" might be the better keyword to use, in this case.

      There is a possibility that with() {} could be implemented as a closure, but I think a bare language feature would be more useful, as it is just syntactic sugar, and shouldn't incur any runtime penalty.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            cpoirier Chris Poirier
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: