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 <<a href=3D"mailto:[email protected]">[email protected]</a>> 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'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't look at<br> that yet.<br> <br> On Tue, Jul 28, 2026 at 6:00=E2=80=AFPM Gianluca Sartori <<a href=3D"mai= lto:[email protected]" target=3D"_blank">[email protected]</a>> wrot= e:<br> ><br> > That's the idea, to use the multiline style only when there are lo= nger expressions like strings, method calls, etc.<br> ><br> > 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> ><br> ><br> > Gianluca Sartori<br> > --<br> > <a href=3D"https://dueuno.com" rel=3D"noreferrer" target=3D"_blank">ht= tps://dueuno.com</a><br> ><br> ><br> > On Mon, 27 Jul 2026 at 19:03, MG <<a href=3D"mailto:mgbiz@arscreat.= com" target=3D"_blank">mgbiz-yvYIh6MZAuFWk0Htik3J/[email protected]</a>> wrote:<br> >><br> >> Hi Gianluca,<br> >><br> >> 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> >> 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> >> Am 27.07.2026 um 14:38 schrieb Gianluca Sartori:<br> >><br> >> Hi people,<br> >><br> >> I've proposed the following PR to the Grails project in a rush= , but I guess its proper place is the Groovy project.<br> >><br> >> <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> >><br> >> We usually format ternary operators like this for readability:<br> >><br> >> String message =3D condition<br> >>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0? "Value when true"<br> >>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0: "Value when false"<br= > >><br> >> Would you accept such PR on the groovy-developer skill?<br> >><br> >> Cheers,<br> >> Gianluca<br> >><br> >> Gianluca Sartori<br> >> --<br> >> <a href=3D"https://dueuno.com" rel=3D"noreferrer" target=3D"_blank= ">https://dueuno.com</a><br> >><br> >><br> </blockquote></div> --00000000000027d5e50657a85044--