Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion go fmt and multi-line conditionals

Received: by 10.68.211.103 with SMTP id nb7mr5647831pbc.6.1337831705350;
        Wed, 23 May 2012 20:55:05 -0700 (PDT)
X-BeenThere: golang-nuts@googlegroups.com
Received: by 10.68.116.45 with SMTP id jt13ls5641132pbb.9.gmail; Wed, 23 May
 2012 20:54:59 -0700 (PDT)
Received: by 10.68.191.225 with SMTP id hb1mr5654503pbc.5.1337831699513;
        Wed, 23 May 2012 20:54:59 -0700 (PDT)
Received: by 10.68.191.225 with SMTP id hb1mr5654502pbc.5.1337831699499;
        Wed, 23 May 2012 20:54:59 -0700 (PDT)
Return-Path: <kball...@gmail.com>
Received: from mail-pb0-f51.google.com (mail-pb0-f51.google.com [209.85.160.51])
        by gmr-mx.google.com with ESMTPS id iq5si4997035pbc.1.2012.05.23.20.54.59
        (version=TLSv1/SSLv3 cipher=OTHER);
        Wed, 23 May 2012 20:54:59 -0700 (PDT)
Received-SPF: pass (google.com: domain of kball...@gmail.com designates 209.85.160.51 as permitted sender) client-ip=209.85.160.51;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of kball...@gmail.com designates 209.85.160.51 as permitted sender) smtp.mail=kball...@gmail.com; dkim=pass header...@gmail.com
Received: by pbbrp16 with SMTP id rp16so9364638pbb.10
        for <golang-nuts@googlegroups.com>; Wed, 23 May 2012 20:54:59 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:cc:message-id:in-reply-to:references:subject:x-mailer
         :mime-version:content-type;
        bh=tF6eGHBjOKsQ/eahqpBszUOBomeDfiErd0p0dMjPhyE=;
        b=yzKly44nwzabzubZV3GDz8BhGpSxqutVuSanQU7GuXIbfhCl3AXCTte92uDyTUWRic
         DG+5XJppB9ixqhswwaewBwaybcFrjpXF6Q2dC2zLzPTR7PryDMNHpTkJUTJlU7CaPyti
         M8OwvYMUuHyUWLg3VHNIxEk4c2Orr5HP9fPt8kdprKds77O+hOveWtTtnkJzXazP5l+Y
         38JIyEbZHSvW08m2DTujqR7WQGp0s+gFFvQFkITJtGV9OOV3E+iuOdKE/SDLIIsgHy0V
         Hsvff0WKmmd8EdbiZO73r8aKeQ6MjBvmjWpAeSoeYrHPs/pTIEc7blB96aKV9VG07c5Z
         Oh5g==
Received: by 10.68.225.170 with SMTP id rl10mr17016223pbc.13.1337831699295;
        Wed, 23 May 2012 20:54:59 -0700 (PDT)
Return-Path: <kball...@gmail.com>
Received: from [10.0.1.14] (c-67-180-198-185.hsd1.ca.comcast.net. [67.180.198.185])
        by mx.google.com with ESMTPS id rk4sm4006560pbc.48.2012.05.23.20.54.58
        (version=TLSv1/SSLv3 cipher=OTHER);
        Wed, 23 May 2012 20:54:58 -0700 (PDT)
Date: Wed, 23 May 2012 20:54:56 -0700
From: Kevin Ballard <kball...@gmail.com>
To: Michael Jones <m...@google.com>
Cc: Rodrigo Moraes <rodrigo.mor...@gmail.com>, golang-nuts
 <golang-nuts@googlegroups.com>
Message-ID: <F97703E644604671B65ED5930F5DB...@gmail.com>
In-Reply-To: <CAB3VzboNq7BcpVHsqi=gx3x0bxyvRJ_q_vwC4=eJcCR379i...@mail.gmail.com>
References: <a335f198-a14b-492d-b254-a824e0469...@e20g2000vbm.googlegroups.com>
 <e9eedfcb-cfb0-4792-a158-2fe8575ab...@w13g2000vbc.googlegroups.com>
 <9F9424852E454FD2A2A7E0CBE57C7...@gmail.com>
 <CAB3VzboNq7BcpVHsqi=gx3x0bxyvRJ_q_vwC4=eJcCR379i...@mail.gmail.com>
Subject: Re: [go-nuts] Re: go fmt and multi-line conditionals
X-Mailer: sparrow 1.6 (build 1081.28)
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="4fbdb110_b03e0c6_d493"

--4fbdb110_b03e0c6_d493
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Your suggestion upstream seems to be to insert a `true` as the first expression, so all the actual conditional expressions line up. But the real issue with the go fmt style is the conditionals line up with the body too, which means indentation cannot be used as a visual cue of where the body starts. The idea is to reintroduce indentation as a visual cue without making the conditional ugly.

I rather like

if conditionA &&
   conditionB &&
   conditionC {
bodyOfStatement()
}

for 3 reasons:

1. The conditionals all line up, including the one on the first line (with the `if`).
2. The conditionals have a lower indentation level than the body of the `then` clause. This makes it clear that they exist outside of the nested scope.
3. The usage of spaces for the subsequent lines in the conditional mean that they will line up regardless of the tab width of your editor.

-Kevin 


On Wednesday, May 23, 2012 at 7:19 PM, Michael Jones wrote:

> Did you miss my suggestion upstream about "true" or just disagree with it?
> 
> On Wed, May 23, 2012 at 6:10 PM, Kevin Ballard <kball...@gmail.com (mailto:kball...@gmail.com)> wrote:
> > Why not just indent the subsequent lines using 3 spaces instead of a tab, so all 3 conditionals line up? 
> > 
> > if conditionA &&
> >    conditionB &&
> > 
> >    conditionC && {
> > bodyOfStatement()
> > }
> > 
> > -Kevin
> > 
> > On Wednesday, May 23, 2012 at 5:42 PM, Rodrigo Moraes wrote:
> > 
> > > On May 21, 5:56 am, wmpalmer wrote:
> > > > After a brief discussion in #go-nuts on freenode, the suggestion of an
> > > > alternative formatting was made:
> > > > 
> > > > if              conditionA &&
> > > >                 conditionB &&
> > > >                 conditionC {
> > > >         bodyOfStatement()
> > > > 
> > > > }
> > > 
> > > That looks exotic to me. I like it the way it is. Honestly.
> > > 
> > > -- rodrigo 
> > 
> 
> 
> 
> -- 
> Michael T. Jones | Chief Technology Advocate  | m...@google.com (mailto:m...@google.com) |  +1 650-335-5765 


--4fbdb110_b03e0c6_d493
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline


                <div>
                    Your suggestion upstream seems to be to insert a =60t=
rue=60 as the first expression, so all the actual conditional expressions=
 line up. But the real issue with the go fmt style is the conditionals li=
ne up with the body too, which means indentation cannot be used as a visu=
al cue of where the body starts. The idea is to reintroduce indentation a=
s a visual cue without making the conditional ugly.</div><div><br></div><=
div>I rather like</div><div><br></div><div>if conditionA &amp;&amp;</div>=
<div>&nbsp; &nbsp;conditionB &amp;&amp;</div><div>&nbsp; &nbsp;conditionC=
 =7B</div><div><span class=3D=22Apple-tab-span=22 style=3D=22white-space:=
pre=22>	</span>bodyOfStatement()</div><div>=7D</div><div><br></div><div>f=
or 3 reasons:</div><div><br></div><div>1. The conditionals all line up, i=
ncluding the one on the first line (with the =60if=60).</div><div>2. The =
conditionals have a lower indentation level than the body of the =60then=60=
 clause. This makes it clear that they exist outside of the nested scope.=
</div><div>3. The usage of spaces for the subsequent lines in the conditi=
onal mean that they will line up regardless of the tab width of your edit=
or.</div><div><br></div><div>-Kevin</div>
                <div><div><br></div></div>
                =20
                <p style=3D=22color: =23A0A0A8;=22>On Wednesday, May 23, =
2012 at 7:19 PM, Michael Jones wrote:</p>
                <blockquote type=3D=22cite=22 style=3D=22border-left-styl=
e:solid;border-width:1px;margin-left:0px;padding-left:10px;=22>
                    <span><div><div>Did you miss my suggestion upstream a=
bout =22true=22 or just disagree with it=3F<br><br><div>On Wed, May 23, 2=
012 at 6:10 PM, Kevin Ballard <span dir=3D=22ltr=22>&lt;<a href=3D=22mail=
to:kballard=40gmail.com=22 target=3D=22=5Fblank=22>kballard=40gmail.com</=
a>&gt;</span> wrote:<br><blockquote type=3D=22cite=22><div>
                <div>Why not just indent the subsequent lines using 3 spa=
ces instead of a tab, so all 3 conditionals line up=3F
                </div>
                <div><div><div><br></div><div>if conditionA &amp;&amp;</d=
iv><div>&nbsp; &nbsp;conditionB &amp;&amp;</div></div><div>&nbsp; &nbsp;c=
onditionC &amp;&amp; =7B</div><div><span style=3D=22white-space:pre-wrap=22=
>	</span>bodyOfStatement()</div>

<div>=7D</div><span><font color=3D=22=23888888=22><div><br></div><div>-Ke=
vin</div></font></span></div><div><div>
                 =20
                <p style=3D=22color:=23a0a0a8=22>On Wednesday, May 23, 20=
12 at 5:42 PM, Rodrigo Moraes wrote:</p><blockquote type=3D=22cite=22><di=
v>
                    <span><div><div><div>On May 21, 5:56&nbsp;am, wmpalme=
r wrote:</div><blockquote type=3D=22cite=22><div><div>After a brief discu=
ssion in =23go-nuts on freenode, the suggestion of an</div><div>alternati=
ve formatting was made:</div>

<div><br></div><div>if &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;co=
nditionA &amp;&amp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &=
nbsp; &nbsp; conditionB &amp;&amp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp; conditionC =7B</div><div>&nbsp; &nbsp; &nbsp;=
 &nbsp; bodyOfStatement()</div><div><br></div><div>=7D</div></div></block=
quote><div><br></div><div>That looks exotic to me. I like it the way it i=
s. Honestly.</div><div><br></div><div>-- rodrigo</div></div></div></span>=

                 =20
                 =20
                 =20
                 =20
                </div></blockquote><div>
                    <br>
                </div>
            </div></div></div></blockquote></div><br><br clear=3D=22all=22=
><div><br></div>-- <br><div dir=3D=22ltr=22><div><div style=3D=22line-hei=
ght:1.5em;padding-top:10px;margin-top:10px;color:rgb(85,85,85);font-famil=
y:sans-serif=22><font size=3D=221=22><span style=3D=22border-top-width:2p=
x;border-right-width:0px;border-bottom-width:0px;border-left-width:0px;bo=
rder-top-style:solid;border-right-style:solid;border-bottom-style:solid;b=
order-left-style:solid;border-top-color:rgb(213,15,37);border-right-color=
:rgb(213,15,37);border-bottom-color:rgb(213,15,37);border-left-color:rgb(=
213,15,37);padding-top:2px;margin-top:2px=22>Michael T. Jones&nbsp;=7C</s=
pan><span style=3D=22border-top-width:2px;border-right-width:0px;border-b=
ottom-width:0px;border-left-width:0px;border-top-style:solid;border-right=
-style:solid;border-bottom-style:solid;border-left-style:solid;border-top=
-color:rgb(51,105,232);border-right-color:rgb(51,105,232);border-bottom-c=
olor:rgb(51,105,232);border-left-color:rgb(51,105,232);padding-top:2px;ma=
rgin-top:2px=22>&nbsp;Chief Technology Advocate &nbsp;=7C</span><span sty=
le=3D=22border-top-width:2px;border-right-width:0px;border-bottom-width:0=
px;border-left-width:0px;border-top-style:solid;border-right-style:solid;=
border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(0,=
153,57);border-right-color:rgb(0,153,57);border-bottom-color:rgb(0,153,57=
);border-left-color:rgb(0,153,57);padding-top:2px;margin-top:2px=22>&nbsp=
;<a href=3D=22mailto:mtj=40google.com=22 target=3D=22=5Fblank=22>mtj=40go=
ogle.com</a>&nbsp;=7C</span><span style=3D=22border-top-width:2px;border-=
right-width:0px;border-bottom-width:0px;border-left-width:0px;border-top-=
style:solid;border-right-style:solid;border-bottom-style:solid;border-lef=
t-style:solid;border-top-color:rgb(238,178,17);border-right-color:rgb(238=
,178,17);border-bottom-color:rgb(238,178,17);border-left-color:rgb(238,17=
8,17);padding-top:2px;margin-top:2px=22>&nbsp; +1 650-335-5765</span></fo=
nt></div>

</div></div><br>
</div></div></span>
                =20
                =20
                =20
                =20
                </blockquote>
                =20
                <div>
                    <br>
                </div>
            
--4fbdb110_b03e0c6_d493--