📄 stylewars.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN"><!-- This collection of hypertext pages is Copyright 1995-2005 by Steve Summit. --><!-- Content from the book "C Programming FAQs: Frequently Asked Questions" --><!-- (Addison-Wesley, 1995, ISBN 0-201-84519-9) is made available here by --><!-- permission of the author and the publisher as a service to the community. --><!-- It is intended to complement the use of the published text --><!-- and is protected by international copyright laws. --><!-- The on-line content may be accessed freely for personal use --><!-- but may not be published or retransmitted without explicit permission. --><!-- --><!-- this page built Sat Dec 24 21:47:46 2005 by faqproc version 2.7 --><!-- from source file style.sgml dated Sat Jul 3 17:22:13 2004 --><!-- corresponding to FAQ list version 4.0 --><html><!-- Mirrored from c-faq.com/style/stylewars.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 07:59:01 GMT --><head><meta name=GENERATOR content="faqproc"><title>Question 17.10</title><link href="guides.html" rev=precedes><link href="vsefficiency.html" rel=precedes><link href="index.html" rev=subdocument></head><body bgcolor="#ffffff"><a href="guides.html" rev=precedes><img src="../images/buttonleft.gif" alt="prev"></a><a href="index.html" rev=subdocument><img src="../images/buttonup.gif" alt="up"></a><a href="vsefficiency.html" rel=precedes><img src="../images/buttonright.gif" alt="next"></a> <a href="../index-2.html"><img src="../images/buttontop.gif" alt="top/contents"></a><a href="../search.html"><img src="../images/buttonsrch.gif" alt="search"></a><hr><p><!-- qbegin --><h1>comp.lang.c FAQ list<font color=blue>·</font><!-- qtag -->Question 17.10</h1><p><font face=Helvetica size=8 color=blue><b>Q:</b></font>Some people say that <TT>goto</TT>'s are eviland that I should never use them.Isn't that a bit extreme?</p><p><hr><p><font face=Helvetica size=8 color=blue><b>A:</b></font>Programming style,like writing style,issomewhat ofan artandcannotbe codified by inflexible rules,although discussions about style often seem to center exclusively around such rules.</p><p>In the case of the <TT>goto</TT> statement,ithas long been observedthat unfettered useof <TT>goto</TT>'squickly leads to unmaintainable spaghetti code.However, a simple, unthinking ban on the <TT>goto</TT> statement does not necessarily lead immediately to beautiful programming:an unstructured programmer is just as capable of constructing a Byzantine tangle without using any <TT>goto</TT>'s(perhaps substituting oddly-nested loops andBooleancontrol variables, instead).Manyprogrammers adopt a moderate stance:<TT>goto</TT>'s are usually to be avoided,but are acceptable in a few well-constrained situations,if necessary:as multi-level <TT>break</TT> statements,to coalesce common actionsinside a <TT>switch</TT> statement,or to centralize cleanup tasksin a function with several error returns.</p><p>Most observations or ``rules''about programming style(Structured Programming is Good,<TT>goto</TT>'s are Bad,functions should fit on one page,etc.)usually work better as guidelines than rules,and work much betterif programmers understand whatthe guidelines are trying to accomplish.Blindly avoiding certain constructsor following rules without understanding themcan lead to just as many problemsas the rules were supposed to avert.</p><p>Furthermore, many opinions on programming style are just that: opinions.They may be strongly argued and strongly felt, they may be backed up by solid-seeming evidence and arguments,but the opposing opinions may be just as stronglyfelt, supported, and argued.It's usually futile to get dragged into ``style wars,'' becauseon certain issues(such as those referred to in questions<a href="../null/ptrtest.html">5.3</a>,<a href="../null/nullor0.html">5.9</a>,<a href="../bool/macros.html">9.4</a>,and<a href="../cpp/nestincl.html">10.7</a>),opponents can neverseem toagree,oragree to disagree, or stop arguing.</p><p>Finally,as William Strunk has written(quoted in the Introduction toStrunk and White's classic <I>Elements of Style</I>),<blockquote>It is an old observationthat the best writers sometimes disregard the rules of rhetoric.When they do, however,the reader will usually find in the sentencesome compensating merit,attained at the cost of the violation.Unless he is certain of doing as well,he will probably do best to follow the rules.</blockquote></p><p>References:K&R2 Sec. 3.8<br>E. Dijkstra, ``Go To Statement Considered Harmful'' <br>D.E. Knuth,``Structured Programming with goto Statements'' <br></p><!-- aend --><p><hr><a href="guides.html" rev=precedes><img src="../images/buttonleft.gif" alt="prev"></a><a href="index.html" rev=subdocument><img src="../images/buttonup.gif" alt="up"></a><a href="vsefficiency.html" rel=precedes><img src="../images/buttonright.gif" alt="next"></a> <a href="../questions.html"><img src="../images/buttontop.gif" alt="contents"></a><a href="../search.html"><img src="../images/buttonsrch.gif" alt="search"></a><br><!-- lastfooter --><a href="../about.html">about this FAQ list</a> <a href="../eskimo.html">about eskimo</a> <a href="../search.html">search</a> <a href="../feedback.html">feedback</a> <a href="copyright.html">copyright</a><p>Hosted by<a href="http://www.eskimo.com/"><img src="../../www.eskimo.com/img/link/eskitiny.gif" alt="Eskimo North"></a></body><!-- Mirrored from c-faq.com/style/stylewars.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 07:59:01 GMT --></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -