<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
I agree completely with Wentao on the second comment. Mixing the two
styles would lead to confusion.<br>
<pre class="moz-signature" cols="72">--
Eric Newberry
Computer Science Undergraduate
The University of Arizona
Vice President, University of Arizona ACM Student Chapter</pre>
<div class="moz-cite-prefix">On 8/12/2015 11:56 AM, Wentao Shang
wrote:<br>
</div>
<blockquote
cite="mid:CAD4s1gQQWOch++VvdrZ7kup3=ZW=01b_Hs5nk2PW++gd2hba9Q@mail.gmail.com"
type="cite">Two comments:
<div><br>
</div>
<div>1) In terms of indentation and placement of curly braces, I
prefer option A or D but with extra indentation for statements
inside the switch block. This should fix the issue of having two
closing braces at the same level.</div>
<div><br>
</div>
<div>2) Mixing block and non-blocked statements under the same
case clause seems confusing. I would suggest we mandate that if
block is used inside the case clause, it should always cover the
entire case clause.</div>
<div><br>
</div>
<div>Wentao</div>
<div><br>
On Wednesday, August 12, 2015, Junxiao Shi <<a
moz-do-not-send="true"
href="mailto:shijunxiao@email.arizona.edu">shijunxiao@email.arizona.edu</a>>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US">
<div>
<p>Dear folks</p>
<p> </p>
<p>rule 1.10 gives two forms for switch statements. The
preferred form is:</p>
<p> </p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">switch (cond) {</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">case 1:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> stmts;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> // Fallthrough</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> </span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">case 2:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> stmts;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> break;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> </span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">default:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> stmts;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> break;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">}</span></p>
<p> </p>
<p>In reality, ‘stmts;’ may need to declare variables, but
declarations are disallowed directly under a ‘case’
label.</p>
<p>The solution is to use a compound statement <span
style="font-family:Consolas">{ stmts; }</span> ,
inside which declarations can be used.</p>
<p> </p>
<p>My question is, how to properly indent a switch
statement in which some ‘case’ labels have compound
statements?</p>
<p> </p>
<p>I prefer the following form:</p>
<p> </p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">// option A</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">switch (cond) {</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">case 1: {</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> int i = 1;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(i);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">} // Fallthrough</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> </span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">case 2:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(2);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> break;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> </span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">case 3: {</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> int j = 3;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(j);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">} break;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> </span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">default:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(0);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> break;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">}</span></p>
<p> </p>
<p>I have also seen:</p>
<p> </p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">// option B</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">switch (cond) {</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">case 1:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> {</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> int i = 1;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(i);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> }</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> // Fallthrough</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> </span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">case 2:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(2);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> break;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> </span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">case 3:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> {</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> int j = 3;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(j);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> }</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> break;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> </span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">default:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(0);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> break;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">}</span></p>
<p> </p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">// option C</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">switch (cond) {</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">case 1:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> {</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> int i = 1;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(i);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> // Fallthrough</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> }</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> </span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">case 2:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(2);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> break;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> </span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">case 3:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> {</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> int j = 3;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(j);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> break;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> }</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> </span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">default:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(0);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> break;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">}</span></p>
<p> </p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">// option D</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">switch (cond) {</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">case 1:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">{</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> int i = 1;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(i);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> // Fallthrough</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">}</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> </span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">case 2:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(2);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> break;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> </span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">case 2:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">{</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> int j = 3;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(j);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> break;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">}</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> </span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">default:</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> doSomething(0);</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas"> break;</span></p>
<p style="margin-left:.5in"><span
style="font-family:Consolas">}</span></p>
<p> </p>
<p>Option B exactly matches rule 1.10 because a compound
statement, by definition, is a statement. However, it’s
less readable than option A because the actual
statements under a ‘case’ label with a compound
statement is indented more than the statements under a
‘case’ label without a compound statement.</p>
<p>Option C has the same problem as option B, and also has
hides ‘break’ or ‘// Fallthrough’ inside the compound
statement making them less visible.</p>
<p>Option D looks okay but in case the last ‘case’ or
‘default’ label contains a compound statement, two ‘}’
would be indented at the same level at the bottom, which
is confusing.</p>
<p> </p>
<p>What do others on the mailing list think about this?</p>
<p>I intend to amend rule 1.10 when a consensus is
reached.</p>
<p> </p>
<p>Yours, Junxiao</p>
</div>
</div>
</blockquote>
</div>
<br>
<br>
-- <br>
<div dir="ltr">PhD @ IRL, CSD, UCLA</div>
<br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Nfd-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Nfd-dev@lists.cs.ucla.edu">Nfd-dev@lists.cs.ucla.edu</a>
<a class="moz-txt-link-freetext" href="http://www.lists.cs.ucla.edu/mailman/listinfo/nfd-dev">http://www.lists.cs.ucla.edu/mailman/listinfo/nfd-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>