The Elements of Programming Style.pdf

The Elements of Programming Style.pdf

ID:34974865

大小:39.69 KB

页数:3页

时间:2019-03-15

The Elements of Programming Style.pdf_第1页
The Elements of Programming Style.pdf_第2页
The Elements of Programming Style.pdf_第3页
资源描述:

《The Elements of Programming Style.pdf》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

1、TheElementsofProgrammingStyleThefollowingrulesofprogrammingstyleareexcerptedfromthebookTheElementsofProgrammingStyle"byKernighanandPlauger,publishedbyMcGrawHill.Hereisquotefromthebook:ToparaphraseanobservationinTheElementsofStylebyStrunkandWhite,ther

2、ulesofprogrammingstyle,likethoseofEnglish,aresometimesbroken,evenbythebestwriters.Whenaruleisbroken,however,youwillusually ndintheprogramsomecompensatingmerit,attainedatthecostoftheviolation.Unlessyouarecertainofdoingaswell,youwillprobablydobesttofollo

3、wtherules."1.Writeclearly{don'tbetooclever.2.Saywhatyoumean,simplyanddirectly.3.Uselibraryfunctionswheneverfeasible.4.Avoidtoomanytemporaryvariables.5.Writeclearly{don'tsacri ceclarityforeciency."6.Letthemachinedothedirtywork.7.Replacerepetitiveexpre

4、ssionsbycallstocommonfunctions.8.Parenthesizetoavoidambiguity.9.Choosevariablenamesthatwon'tbeconfused.10.Avoidunnecessarybranches.11.Ifalogicalexpressionishardtounderstand,trytransformingit.12.Chooseadatarepresentationthatmakestheprogramsimple.13.Writ

5、e rstineasy-to-understandpseudolanguage;thentranslateintowhateverlanguageyouhavetouse.14.Modularize.Useproceduresandfunctions.15.Avoidgotoscompletelyifyoucankeeptheprogramreadable.16.Don'tpatchbadcode{rewriteit.17.Writeandtestabigprograminsmallpieces.1

6、8.Userecursiveproceduresforrecursively-de neddatastructures.19.Testinputforplausibilityandvalidity.20.Makesureinputdoesn'tviolatethelimitsoftheprogram.21.Terminateinputbyend-of- lemarker,notbycount.22.Identifybadinput;recoverifpossible.23.Makeinputeasy

7、toprepareandoutputself-explanatory.24.Useuniforminputformats.25.Makeinputeasytoproofread.26.Useself-identifyinginput.Allowdefaults.Echobothonoutput.27.Makesureallvariableareinitializedbeforeuse.28.Don'tstopatonebug.29.Usedebuggingcompilers.30.watchoutf

8、oro -by-oneerrors.31.Takecaretobranchtherightwayonequality.32.Becarefulifaloopexitstothesameplacefromthemiddleandthebottom.33.Makesureyourcodedoesothing"gracefully.34.Testprogramsattheirboundaryvalues.35.Checksomeanswersbyhand.236.10.

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。