groovy
  1. groovy
  2. GROOVY-2892

Unless / If expressions support

    Details

    • Type: Wish Wish
    • Status: Open Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 4.0
    • Component/s: syntax
    • Labels:
      None
    • Number of attachments :
      0

      Description

      I would love to see Groovy support right-side unless / if expressions like in Python or Ruby as they make the code often more readable.

      Here is a small example:

      doSomething() unless (x > 10)
      
      (...)
      
      triggerSomethingNasty() if (x < 10)
      

        Activity

        Hide
        Russel Winder added a comment -

        I think having conditions as right-hand side properties of an expression is awful – especially in a read left-to-right language. Just because Perl and Ruby do it doesn't make it good and desirable – Python doesn't have the structure as was originally stated.

        Show
        Russel Winder added a comment - I think having conditions as right-hand side properties of an expression is awful – especially in a read left-to-right language. Just because Perl and Ruby do it doesn't make it good and desirable – Python doesn't have the structure as was originally stated.
        Hide
        Julien Ponge added a comment -

        My mistake, Python indeed doesn't have those constructs.

        Show
        Julien Ponge added a comment - My mistake, Python indeed doesn't have those constructs.
        Hide
        Russel Winder added a comment -

        No problem, I just wanted to ensure no mistakes got turned into facts

        It seems the debate is lively and alive on the mailing list, so I guess the best bet is to wait for things to iterate to a conclusion there and then post a summary item here.

        Show
        Russel Winder added a comment - No problem, I just wanted to ensure no mistakes got turned into facts It seems the debate is lively and alive on the mailing list, so I guess the best bet is to wait for things to iterate to a conclusion there and then post a summary item here.
        Hide
        John Fletcher added a comment -

        What was the conclusion on the user list? If this is all too hard, why not just create a separate issue to add 'unless' and confine this issue to the idea of reverse-syntax.

        Show
        John Fletcher added a comment - What was the conclusion on the user list? If this is all too hard, why not just create a separate issue to add 'unless' and confine this issue to the idea of reverse-syntax.
        Hide
        Guillaume Laforge added a comment -

        The conclusion is that it's not a very natual style for Groovy to have that conditional after the statement.
        So we're not really fond of implementing this feature.
        We're keeping old feature requests open in our bug tracker though, hence why this issue is still open.

        Show
        Guillaume Laforge added a comment - The conclusion is that it's not a very natual style for Groovy to have that conditional after the statement. So we're not really fond of implementing this feature. We're keeping old feature requests open in our bug tracker though, hence why this issue is still open.

          People

          • Assignee:
            Unassigned
            Reporter:
            Julien Ponge
          • Votes:
            6 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated: