Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.8-beta-2
-
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
Attachments
Issue Links
- duplicates
-
GROOVY-3401 Ternary operator ?: does not handle newline before ":" gracefully
- Closed