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

Loosen white space restrictions

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.8-beta-2
    • 2.3.0-beta-1
    • syntax
    • None

    Description

      Coming from Java, certain white space requirements seem overly restrictive to me. Not sure whether these are always mandatory to make the parser happy, or whether there is still some leeway that is just not used yet.

      One prominent example is the handling of ternary expressions. Groovy does not allow line breaks before ? and :

      // valid
      script = script.exists() ? script : new File("${name}.groovy")
      
      // INVALID
      script = script.exists()
          ? script
          : new File("${name}.groovy")
      

      No problem in the case, but when the expressions are longer, how do you wrap these guys?

      I find

      potentialScript = potentialScript.exists() ? potentialScript :
          new File("${grailsHome}/scripts/${name}_.groovy")
      

      way more confusing than

      potentialScript = potentialScript.exists()
          ? potentialScript
          : new File("${grailsHome}/scripts/${name}_.groovy")
      

      or even

      potentialScript =
          potentialScript.exists() ? potentialScript
                                   : new File("${grailsHome}/scripts/${name}_.groovy")
      

      It's also not possible to have a comment appear after the first expression

      // INVALID
      script = script.exists() // TODO bug #158462
          ? script : new File("${name}.groovy")
      

      It's merely a style issue, therefore a matter of taste, and certainly no show stopper, but when technically possible, I would really like to be able to layout code according to my personal preference.

      Attachments

        1. Bug4464.groovy
          0.4 kB
          Marco Hunsicker

        Issue Links

          Activity

            People

              paulk Paul King
              marcohu Marco Hunsicker
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: