Re: Ternary operator formatting

Gianluca Sartori <[email protected]> Tue, 28 Jul 2026 11:17:36 +0200
Newsgroups gmane.comp.lang.groovy.devel
Message-ID <CAEJ7v=kix2DcK0J_oRhBxaaQZ_ZvnvuBUeL-nM4GagBvk+hRhw@mail.gmail.com>
--00000000000027d5e50657a85044
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

That makes sense. I assumed the Grails project was using the
`groovy-developer` skill from the Groovy project, my mistake.

Thank you for the clarification!

Gianluca Sartori
--
https://dueuno.com


On Tue, 28 Jul 2026 at 11:07, Paul King <[email protected]> wrote:

> It probably is a Grails thing at this point. The Groovy project does
> have some general formatting guidelines but currently hasn't tried to
> provide a fixed recommended coding style across all language
> constructs. It is actually one of the things one agent has suggested
> we adopt to make life easier for AI agents, but we haven't look at
> that yet.
>
> On Tue, Jul 28, 2026 at 6:00=E2=80=AFPM Gianluca Sartori <g.sartori@gmail=
.com>
> wrote:
> >
> > 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 (whic=
h
> we in our code do not have) - but as a general formatting rule, I would b=
e
> 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 =3D condition
> >>         ? "Value when true"
> >>         : "Value when false"
> >>
> >> Would you accept such PR on the groovy-developer skill?
> >>
> >> Cheers,
> >> Gianluca
> >>
> >> Gianluca Sartori
> >> --
> >> https://dueuno.com
> >>
> >>
>

--00000000000027d5e50657a85044
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>That makes sense. I assumed the Grails project was us=
ing the `groovy-developer` skill from the Groovy project, my mistake.=C2=A0=
</div><div><br></div><div>Thank you for the=C2=A0clarification!</div><div><=
br></div><div><div dir=3D"ltr" class=3D"gmail_signature" data-smartmail=3D"=
gmail_signature"><div dir=3D"ltr">Gianluca Sartori<div>--</div><div><a href=
=3D"https://dueuno.com" target=3D"_blank">https://dueuno.com</a></div></div=
></div></div><br></div><br><div class=3D"gmail_quote gmail_quote_container"=
><div dir=3D"ltr" class=3D"gmail_attr">On Tue, 28 Jul 2026 at 11:07, Paul K=
ing &lt;<a href=3D"mailto:[email protected]">[email protected]</a>&gt; wr=
ote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px=
 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">It probably=
 is a Grails thing at this point. The Groovy project does<br>
have some general formatting guidelines but currently hasn&#39;t tried to<b=
r>
provide a fixed recommended coding style across all language<br>
constructs. It is actually one of the things one agent has suggested<br>
we adopt to make life easier for AI agents, but we haven&#39;t look at<br>
that yet.<br>
<br>
On Tue, Jul 28, 2026 at 6:00=E2=80=AFPM Gianluca Sartori &lt;<a href=3D"mai=
lto:[email protected]" target=3D"_blank">[email protected]</a>&gt; wrot=
e:<br>
&gt;<br>
&gt; That&#39;s the idea, to use the multiline style only when there are lo=
nger expressions like strings, method calls, etc.<br>
&gt;<br>
&gt; Anyway I just realized there is no `groovy-developer` skill in the gro=
ovy project, maybe Grails is the right place to work on it?<br>
&gt;<br>
&gt;<br>
&gt; Gianluca Sartori<br>
&gt; --<br>
&gt; <a href=3D"https://dueuno.com" rel=3D"noreferrer" target=3D"_blank">ht=
tps://dueuno.com</a><br>
&gt;<br>
&gt;<br>
&gt; On Mon, 27 Jul 2026 at 19:03, MG &lt;<a href=3D"mailto:mgbiz@arscreat.=
com" target=3D"_blank">mgbiz-yvYIh6MZAuFWk0Htik3J/[email protected]</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi Gianluca,<br>
&gt;&gt;<br>
&gt;&gt; I might misuderstand what you propose here, but for me the whole i=
dea behind cond ? trueBranch : falseBranch is that it is a one-liner.<br>
&gt;&gt; Otherwise it is better suited for if-else-...<br>
&gt;&gt;<br>
&gt;&gt; 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>
&gt;&gt;<br>
&gt;&gt; Cheers,<br>
&gt;&gt; mg<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Am 27.07.2026 um 14:38 schrieb Gianluca Sartori:<br>
&gt;&gt;<br>
&gt;&gt; Hi people,<br>
&gt;&gt;<br>
&gt;&gt; I&#39;ve proposed the following PR to the Grails project in a rush=
, but I guess its proper place is the Groovy project.<br>
&gt;&gt;<br>
&gt;&gt; <a href=3D"https://github.com/apache/grails-core/pull/16055" rel=
=3D"noreferrer" target=3D"_blank">https://github.com/apache/grails-core/pul=
l/16055</a><br>
&gt;&gt;<br>
&gt;&gt; We usually format ternary operators like this for readability:<br>
&gt;&gt;<br>
&gt;&gt; String message =3D condition<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0? &quot;Value when true&quot;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0: &quot;Value when false&quot;<br=
>
&gt;&gt;<br>
&gt;&gt; Would you accept such PR on the groovy-developer skill?<br>
&gt;&gt;<br>
&gt;&gt; Cheers,<br>
&gt;&gt; Gianluca<br>
&gt;&gt;<br>
&gt;&gt; Gianluca Sartori<br>
&gt;&gt; --<br>
&gt;&gt; <a href=3D"https://dueuno.com" rel=3D"noreferrer" target=3D"_blank=
">https://dueuno.com</a><br>
&gt;&gt;<br>
&gt;&gt;<br>
</blockquote></div>

--00000000000027d5e50657a85044--