<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
I would argue for Option D, as the alignment of the braces fits more
with the preferred style for statements in ndn-cxx (although with
the opening brace on a new line instead of the same one). Also,
unlike Option A, the break statement is inside the compound
statement. I feel that having the break outside of the statement
could lead to confusion.<br>
<br>
However, I do agree that having two closing braces at the bottom
could be confusing. As such, I'd suggest changing Option D to indent
the contents of the switch statement one level to avoid this
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 7:13 AM, Junxiao Shi
wrote:<br>
</div>
<blockquote cite="mid:55cb5494.e982440a.35c10.04c6@mx.google.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:SimSun;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
{font-family:"\@SimSun";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
p
{mso-style-priority:99;
margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
<div class="WordSection1">
<p>Dear folks</p>
<p><o:p> </o:p></p>
<p>rule 1.10 gives two forms for switch statements. The
preferred form is:</p>
<p><o:p> </o:p></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">switch
(cond) {<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">case
1:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
stmts;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
// Fallthrough<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">case
2:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
stmts;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
break;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">default:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
stmts;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
break;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">}<o:p></o:p></span></p>
<p><o:p> </o: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><o:p> </o:p></p>
<p>My question is, how to properly indent a switch statement in
which some ‘case’ labels have compound statements?</p>
<p><o:p> </o:p></p>
<p>I prefer the following form:</p>
<p><o:p> </o:p></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">//
option A<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">switch
(cond) {<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">case
1: {<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
int i = 1;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(i);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">}
// Fallthrough<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">case
2:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(2);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
break;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">case
3: {<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
int j = 3;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(j);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">}
break;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">default:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(0);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
break;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">}<o:p></o:p></span></p>
<p><o:p> </o:p></p>
<p>I have also seen:</p>
<p><o:p> </o:p></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">//
option B<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">switch
(cond) {<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">case
1:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
{<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
int i = 1;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(i);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
}<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
// Fallthrough<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">case
2:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(2);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
break;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">case
3:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
{<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
int j = 3;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(j);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
}<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
break;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">default:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(0);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
break;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">}<o:p></o:p></span></p>
<p><o:p> </o:p></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">//
option C<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">switch
(cond) {<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">case
1:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
{<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
int i = 1;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(i);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
// Fallthrough<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
}<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">case
2:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(2);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
break;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">case
3:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
{<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
int j = 3;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(j);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
break;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
}<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">default:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(0);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
break;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">}<o:p></o:p></span></p>
<p><o:p> </o:p></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">//
option D<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">switch
(cond) {<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">case
1:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">{<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
int i = 1;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(i);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
// Fallthrough<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">}<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">case
2:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(2);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
break;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">case
2:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">{<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
int j = 3;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(j);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
break;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">}<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas"><o:p> </o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">default:<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
doSomething(0);<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">
break;<o:p></o:p></span></p>
<p style="margin-left:.5in"><span style="font-family:Consolas">}<o:p></o:p></span></p>
<p><o:p> </o: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><o:p> </o: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><o:p> </o:p></p>
<p>Yours, Junxiao</p>
</div>
<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>