Re: Ternary operator formatting

MG <mgbiz-yvYIh6MZAuFWk0Htik3J/[email protected]> Tue, 28 Jul 2026 22:31:32 +0200
Newsgroups gmane.comp.lang.groovy.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------dWLnPLBZP5UHFRJA3YW0kU6u
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Paul already cleared this up, so just a quick reply: I assumed from your 
post saying "We usually format ternary operators like this for 
readability" that you meant in general - but if you meant only for 
longer (to be defined, so an LLM-bot gets it ;-) ) expressions, yes, why 
not G-)

Cheers,
mg

Am 28.07.2026 um 10:00 schrieb Gianluca Sartori:
> That's the idea, to use the multiline style only when there are longer 
> expressions like strings, method calls, etc.
>
> Anyway I just realized there is no `groovy-developer` skill in the 
> groovy project, maybe Grails is the right place to work on it?
>
>
> Gianluca Sartori
> --
> https://dueuno.com
>
>
> On Mon, 27 Jul 2026 at 19:03, MG <mgbiz-yvYIh6MZAuFWk0Htik3J/[email protected]> wrote:
>
>     Hi Gianluca,
>
>     I might misuderstand what you propose here, but for me the whole
>     idea behind cond ? trueBranch : falseBranch is that it is a one-liner.
>     Otherwise it is better suited for if-else-...
>
>     Having said that, I can see that this way of formatting might make
>     sense, if trueBranch and falseBranch are long(ish)
>     String/GString|s (which we in our code do not have) - but as a
>     general formatting rule, I would be against this.
>
>     Cheers,
>     mg
>
>
>     Am 27.07.2026 um 14:38 schrieb Gianluca Sartori:
>>     Hi people,
>>
>>     I've proposed the following PR to the Grails project in a rush,
>>     but I guess its proper place is the Groovy project.
>>
>>     https://github.com/apache/grails-core/pull/16055
>>
>>     We usually format ternary operators like this for readability:
>>
>>     String message = condition
>>             ? "Value when true"
>>             : "Value when false"
>>
>>     Would you accept such PR on the groovy-developer skill?
>>
>>     Cheers,
>>     Gianluca
>>
>>     Gianluca Sartori
>>     --
>>     https://dueuno.com
>

--------------dWLnPLBZP5UHFRJA3YW0kU6u
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    Paul already cleared this up, so just a quick reply: I assumed from
    your post saying "We usually format ternary operators like this for
    readability" that you meant in general - but if you meant only for
    longer (to be defined, so an LLM-bot gets it ;-) ) expressions, yes,
    why not G-)<br>
    <br>
    Cheers,<br>
    mg<br>
    <br>
    <div class="moz-cite-prefix">Am 28.07.2026 um 10:00 schrieb Gianluca
      Sartori:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAEJ7v=kgZRKAgR1ojojAeF9tYWk0JKbVa3gHw5RZY3+j02FapA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div>That's the idea, to use the multiline style only when there
          are longer expressions like strings, method calls, etc.</div>
        <div><br>
        </div>
        <div>Anyway I just realized there is no `groovy-developer` skill
          in the groovy project, maybe Grails is the right place to work
          on it?</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>
          <div dir="ltr" class="gmail_signature"
            data-smartmail="gmail_signature">
            <div dir="ltr">Gianluca Sartori
              <div>--</div>
              <div><a href="https://dueuno.com" target="_blank"
                  moz-do-not-send="true" class="moz-txt-link-freetext">https://dueuno.com</a></div>
            </div>
          </div>
        </div>
        <br>
      </div>
      <br>
      <div class="gmail_quote gmail_quote_container">
        <div dir="ltr" class="gmail_attr">On Mon, 27 Jul 2026 at 19:03,
          MG &lt;<a href="mailto:mgbiz-yvYIh6MZAuFWk0Htik3J/[email protected]"
            moz-do-not-send="true" class="moz-txt-link-freetext">mgbiz-yvYIh6MZAuFWk0Htik3J/[email protected]</a>&gt;
          wrote:<br>
        </div>
        <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div> Hi Gianluca,<br>
            <br>
            I might misuderstand what you propose here, but for me the
            whole idea behind cond ? trueBranch : falseBranch is that it
            is a one-liner.<br>
            Otherwise it is better suited for if-else-...<br>
            <br>
            Having said that, I can see that this way of formatting
            might make sense, if trueBranch and falseBranch are
            long(ish) String/GString|s (which we in our code do not
            have) - but as a general formatting rule, I would be against
            this.<br>
            <br>
            Cheers,<br>
            mg<br>
            <br>
            <br>
            <div>Am 27.07.2026 um 14:38 schrieb Gianluca Sartori:<br>
            </div>
            <blockquote type="cite">
              <div dir="ltr">
                <div>Hi people,<br clear="all">
                </div>
                <div><br>
                </div>
                <div>I've proposed the following PR to the Grails
                  project in a rush, but I guess its proper place is the
                  Groovy project.</div>
                <div><br>
                </div>
                <div><a
href="https://github.com/apache/grails-core/pull/16055" target="_blank"
                    moz-do-not-send="true" class="moz-txt-link-freetext">https://github.com/apache/grails-core/pull/16055</a></div>
                <div><br>
                </div>
                <div>We usually<span
                    style="background-color:transparent"> format ternary
                    operators like this for readability:</span></div>
                <div><br>
                </div>
                <div>String message = condition<br>
                          ? "Value when true"<br>
                          : "Value when false"</div>
                <div><br>
                </div>
                <div>Would you accept such PR on the groovy-developer
                  skill?</div>
                <div><br>
                </div>
                <div>Cheers,</div>
                <div>Gianluca</div>
                <div><br>
                </div>
                <div>
                  <div dir="ltr" class="gmail_signature">
                    <div dir="ltr">Gianluca Sartori
                      <div>--</div>
                      <div><a href="https://dueuno.com" target="_blank"
                          moz-do-not-send="true"
                          class="moz-txt-link-freetext">https://dueuno.com</a></div>
                    </div>
                  </div>
                </div>
              </div>
            </blockquote>
            <br>
          </div>
        </blockquote>
      </div>
    </blockquote>
    <br>
  </body>
</html>

--------------dWLnPLBZP5UHFRJA3YW0kU6u--