📄 x-tclsumm3.html
字号:
<dl class="margin"><dd><div class="Indent"><a name="84773"> </a>The <b class="keyword">if</b> statement is not an exception. The conditionally executed statement always goes on a separate line from the conditional expression:</div><br></dl><dl class="margin"><dd><pre class="Code2"><b><a name="84774">if {$i > $count} { set i $count }</a></b></pre></dl><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84775"> </a>Opening braces (<b class="operator">{</b>), defining a command body, are always on the same line as the command itself.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84776"> </a>Closing braces (<b class="operator">}</b>) and <b class="keyword">switch </b>patterns always have their own line.</li></ul></p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84777">Horizontal Spacing</a></i></h4></font><dl class="margin"><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84778"> </a>Put spaces around binary operators. Put spaces before an open parenthesis, open brace and open square bracket if it follows a command or assignment statement. For example:</li></ul></p><dl class="margin"><dd><pre class="Code2"><b><a name="84779">set status [fooGet $foo [expr $i + 3] $value] if {&value & &mask} {</a></b></pre></dl><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84780"> </a>Line up continuation lines with the part of the preceding line they continue:</li></ul></p><dl class="margin"><dd><pre class="Code2"><b><a name="84781">set a [expr ($b + $c) * \ ($d + $e)] set status [fooList $foo $a $b $c \ $d $e] if {($a == $b) && \ ($c == $d)} { ... }</a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84783">Indentation</a></i></h4></font><dl class="margin"><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84784"> </a>Indentation levels are every four characters (columns 1, 5, 9, 13, ).</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84785"> </a>The module and procedure headings and the procedure declarations start in column one.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84786"> </a>The closing brace of a command body is always aligned on the same column as the command it is related to:</li></ul></p><dl class="margin"><dd><pre class="Code2"><b><a name="84787">while { <i class="textVariable">condition</i> }{ <i class="textVariable">statements </i>} foreach i $elem { <i class="textVariable">statements </i>}</a></b></pre></dl><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84788"> </a>Add one more indentation level after any of the following:</li></ul></p><dl class="margin"><ul class="DashSingle2" type="circle"><li><a name="84789"> </a>procedure declarations</li></ul><ul class="DashSingle2" type="circle"><li><a name="84790"> </a>conditionals (see below)</li></ul><ul class="DashSingle2" type="circle"><li><a name="84791"> </a>looping constructs</li></ul><ul class="DashSingle2" type="circle"><li><a name="84792"> </a>switch statements</li></ul><ul class="DashSingle2" type="circle"><li><a name="84793"> </a>switch patterns</li></ul></dl><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84794"> </a>The <b class="keyword">else </b>of a conditional is on the same line as the closing brace of the first command body. It is followed by the opening brace of the second command body. Thus the form of the conditional is:</li></ul></p><dl class="margin"><dd><pre class="Code2"><b><a name="84795">if {<i class="textVariable"> condition </i>} { <i class="textVariable">statements </i>} else { <i class="textVariable">statements </i>}</a></b></pre></dl><dl class="margin"><dd><div class="Indent"><a name="84796"> </a>The form of the conditional statement with an <b class="keyword">elseif</b> is:</div><br></dl><dl class="margin"><dd><pre class="Code2"><b><a name="84797">if { <i class="textVariable">condition </i>} { <i class="textVariable">statements </i>} elseif {<i class="textVariable"> condition </i>} { <i class="textVariable">statements </i>} else { <i class="textVariable">statements </i>}</a></b></pre></dl><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84798"> </a>The general form of the <b class="keyword">switch</b> statement is:</li></ul></p><dl class="margin"><dd><pre class="Code2"><b><a name="84799">switch <i class="textVariable">[flags]</i> <i class="textVariable">value</i> { a { <i class="textVariable">statements </i> } b { <i class="textVariable">statements </i> } default { <i class="textVariable">statements </i> } }</a></b></pre></dl><dl class="margin"><dd><div class="Indent"><a name="84800"> </a>If the actions are very short and nearly identical in all cases, an alternate form of the switch statement is acceptable:</div><br></dl><dl class="margin"><dd><pre class="Code2"><b><a name="84801">switch <i class="textVariable">[flags]</i> <i class="textVariable">value</i> { a {set x $aVar} b {set x $bVar} c {set x $cVar} }</a></b></pre></dl><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84802"> </a>Comments have the same indentation level as the section of code to which they refer (see <a href="x-tclsumm3.html#84808"><i class="title">Comments</i></a>).</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84806"> </a>Opening body braces<b class="operator"> </b>(<b class="operator">{</b>) have no specific indentation; they follow the command on the same line.</li></ul></p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84808">Comments</a></i></h4></font><dl class="margin"><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84809"> </a>Place comments within code so that they precede the section of code to which they refer and have the same level of indentation. Separate such comments from the code by a single blank line.</li></ul></p><dl class="margin"><p class="listspace"><ul class="Dash2" type="circle"><li><a name="84810"> </a>Begin single-line comments with the pound symbol as in the following:</li></ul></p><dl class="margin"><dd><pre class="Code3"><b><a name="84811"># This is the correct format for a single-line comment set foo 0</a></b></pre></dl><p class="listspace"><ul class="Dash2" type="circle"><li><a name="84812"> </a>Multi-line comments have each line beginning with the pound symbol as in the example below. Do not use a backslash to continue a comment across lines.</li></ul></p><dl class="margin"><dd><pre class="Code3"><b><a name="84813"># This is the CORRECT format for a multiline comment # in a section of code. set foo 0 # This is the INCORRECT format for a multiline comment \ in a section of code. set foo 0</a></b></pre></dl></dl><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84814"> </a>Comments on global variables appear on the same line as the variable declaration, using the semicolon (<b class="operator">;</b>) character:</li></ul></p><dl class="margin"><dd><pre class="Code2"><b><a name="84816">set day night ;# This is a global variable</a></b></pre></dl></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84817">B.3.6 Naming Conventions</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84819"> </a>The following conventions define the standards for naming modules, routines and variables. The purpose of these conventions is uniformity and readability of code.</p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84820"> </a>When creating names, remember that code is written once but read many times. Make names meaningful and readable. Avoid obscure abbreviations.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84821"> </a>Names of routines and variables are composed of upper- and lowercase characters and no underbars. Capitalize each "word" except the first:</li></ul></p><dl class="margin"><dd><div class="Indent"><a name="84822"> </a><b class="symbol_lc">aVariableName</b></div><br></dl><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84823"> </a>Every module has a short prefix (two to five characters). The prefix is attached to the module name and to all externally available procedures and variables. (Names that are not available externally need not follow this convention.)<p class="table"><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84826"> </a><b class="symbol_lc">fooLib.tcl</b> </p></td><td width="10"> </td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84828"> </a>module name</p></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84830"> </a><b class="symbol_lc">fooObjFind</b> </p></td><td width="10"> </td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84832"> </a>procedure name</p></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84834"> </a><b class="symbol_lc">fooCount</b> </p></td><td width="10"> </td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84836"> </a>variable name</p></td><td width="10"> </td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84837"> </a>Names of procedures follow the <i class="emphasis">module</i>-<i class="emphasis">noun</i>-<i class="emphasis">verb</i> rule. Start the procedure name with the module prefix, followed by the noun or object that the procedure manipulates. Conclude the name with the verb or action that the procedure performs:<p class="table"><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84840"> </a><b class="symbol_lc">fooObjFind</b> </p></td><td width="10"> </td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84842"> </a>foo - object - find</p></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84844"> </a><b class="symbol_lc">sysNvRamGet</b> </p></td><td width="10"> </td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84846"> </a>system - non volatile RAM - get</p></td><td width="10"> </td></tr><tr valign="top"><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84848"> </a><b class="symbol_lc">taskInfoGet</b> </p></td><td width="10"> </td><td colspan=1 rowspan=1><p class="BodyLeft"><a name="84851"> </a>task - info - get</p></td><td width="10"> </td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></li></ul></p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84852">B.3.7 Tcl Style</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84854"> </a>The following conventions define additional standards of programming style:</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -