<br><br>On Wednesday, August 12, 2015, Junxiao Shi <<a 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" link="blue" vlink="#954F72"><div><p>Dear folks</p><p><u></u> <u></u></p><p>It seems that I misunderstood Wentao’s opinion about not to mix compound and non-compound ‘case’ labels.</p><p>It indeed meant that when a compound statement is used, the ‘break’ or ‘// Fallthrough’ should be inside the compound.</p><p>So:</p><p><u></u> <u></u></p><p style="margin-left:.5in"><span style="font-family:Consolas">// option F<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">switch (cond) {<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">  case 1:<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">  {<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">    int i = 1;<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">    doSomething(i);<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">    // Fallthrough<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">  }<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas"><u></u> <u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">  case 2:<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">    doSomething(2);<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">    break;<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas"><u></u> <u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">  case 3:<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">  {<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">    int j = 3;<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">    doSomething(j);<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">    break;<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">  }<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas"><u></u> <u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">  default:<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">    doSomething(0);<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">    break;<u></u><u></u></span></p><p style="margin-left:.5in"><span style="font-family:Consolas">}<u></u><u></u></span></p><p><u></u> <u></u></p><p><u></u><span style="font-family:Symbol"><span>·<span style="font:7.0pt "Times New Roman"">         </span></span></span><u></u>When a ‘case’ or ‘default’ contains a declaration and therefore needs a compound statement, all statements under this label should be placed inside the compound statement, including ‘break’ or ‘// Fallthrough’.</p><p><u></u><span style="font-family:Symbol"><span>·<span style="font:7.0pt "Times New Roman"">         </span></span></span><u></u>When any ‘case’ or ‘default’ label is using a compound statement, all ‘case’ and ‘default’ labels should be indented two spaces after ‘switch’, ‘{‘ and ‘}’ of the compound statements are indented at the same level as ‘case’ and ‘default’, and statements within the compound statements are indented two spaces after ‘case’ and ‘default’.</p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">A ‘switch’ statement without compound statements may still be formatted in the current way, i.e. no extra indentation for ‘case’ and ‘default’.<u></u><u></u></p><p><u></u> <u></u></p><p>However, if we allow a mix of compound and non-compound labels, we should also permit (but not require) 2-space indented ‘case’ and ‘default’ labels even if none of the labels contains a compound statement. Otherwise, the addition or removal of a label with compound statement would require indenting or unindenting the entire switch statement, which is unnecessary.</p></div></div></blockquote><div>Agree. It definitely should not be forbidden. Actually I'm leaning towards having a uniform format for both cases, i.e., always indent inner statements of switch.</div><div><br></div><div>Wentao <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="#954F72"><div><p><u></u> <u></u></p><p>Yours, Junxiao</p><p><u></u> <u></u></p><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in"><p style="border:none;padding:0in"><br><b>From: </b>Wentao Shang<br><b>Sent: </b>Wednesday, August 12, 2015 16:01<br><b>To: </b>Junxiao Shi<br><b>Cc: </b>;Eric Newberry<br><b>Subject: </b>Re: [Nfd-dev] code-style: switch with compound statement</p></div><p class="MsoNormal"><span style="font-family:"Times New Roman",serif"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Times New Roman",serif"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><br><br>On Wednesday, August 12, 2015, Junxiao Shi <<a href="javascript:_e(%7B%7D,'cvml','shijunxiao@email.arizona.edu');" target="_blank">shijunxiao@email.arizona.edu</a>> wrote:</span><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><u></u><u></u></span></p><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt"><div><div><p><span style="font-family:Symbol">·</span><span style="font-size:7.0pt">         </span>When any ‘case’ or ‘default’ contains a declaration and therefore needs a compound statement, all ‘case’s and ‘default’ must use compound statements.</p></div></div></blockquote><div><p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">I wouldn't go that far as to require all cases to have the same format. I think it's ok to mix blocked case and non-blocked case, as long as the block covers the entire single case branch. But the current specification (option E by Junxiao) also looks fine to me.<u></u><u></u></span></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt"><div><div><p><span style="font-family:Symbol">·</span><span style="font-size:7.0pt">         </span>‘break’ and ‘// Fallthrough’ should be placed inside compound statements.</p></div></div></blockquote><p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman",serif">I would suggest one more readability requirement: any intentional fall-through MUST be explicitly annotated in the code. (Do we have this rule already? I can't remember.)<u></u><u></u></span></p></div></div></blockquote><br><br>-- <br><div dir="ltr">PhD @ IRL, CSD, UCLA</div><br>