編程精粹(編寫高質量C語言代碼)

《編程精粹(編寫高質量C語言代碼)》是由人民郵電出版社出版的圖書。

基本信息

內容簡介

編程精粹(編寫高質量C語言代碼)

軟體日趨複雜,編碼錯誤隨之而來。要在測試前發現程式的錯誤,開發出無錯誤的程式,關鍵是弄清楚錯誤為何產生,又是如何產生。《編程精粹編寫高質量C語言代碼》給出了多條編程方面的指導,這些指導看似簡單,卻是作者多年思考及實踐的結果,是對其編程經驗的總結。書中解決問題的思考過程對於程式開發人員尤顯珍貴。

《編程精粹編寫高質量C語言代碼》適於各層次程式開發人員閱讀。

編輯推薦

編寫高質量的、沒有bug的程式,是每位程式設計師所追求的目標。但隨著軟體規模越來越大,功能日趨複雜,這一目標變得越來越困難。

《編程精粹編寫高質量C語言代碼》揭示了微軟公司應對質量挑戰、開發出世界級代碼的技術內幕,作者在自己不斷探索、實踐和思考的基礎上,系統總結了多年來指導微軟各團隊的經驗,將其凝聚為許多切實可行的編程實踐指導,可謂字字珠璣。正因如此,《編程精粹編寫高質量C語言代碼》被公認為與《代碼大全》齊名的編程技術名著,曾於1993年榮獲有軟體開發奧斯卡獎之稱的Jolt生產效率大獎。書中內容主要針對C語言,但其中的思想對目前的各主流語言編程也完全適用。

StephenA.Maguire,世界著名的技術專家和技術作家。曾在微軟公司供職多年,領導開發了Mac版的Excel和眾多重要的跨平台項目,並多次扮演救火隊員的角色,成功拯救那些陷入困境的團隊。現為Web開發公司StormDevelopment的高級副總裁。他的另一部名著DebuggingtheDevelopmentProcess繼《編程精粹編寫高質量C語言代碼》之後第二年再次摘得Jolt生產效率大獎,成為空前絕後的傳奇。

與《代碼大全》齊名的經典著作

提示微軟成功的技術奧秘

C語言高手的秘籍

目錄

1AHYPOTHETICALCOMPILER.

Ifyourcompilercoulddetecteverybuginyourprogram——nomatterthetype——andissueanerrormessage,riddingyourcodeofbugswouldbesimple.Suchomniscientcompilersdon'texist,butbyenablingoptionalcompilerwarnings,usingsyntaxandportabilitycheckers,andusingautomatedunittests,youcanincreasethenumberofbugsthataredetectedforyouautomatically.

2ASSERTYOURSELF

Agooddevelopmentstrategyistomaintaintwoversionsofyourprogram:onethatyoushipandonethatyouusetodebugthecode.Byusingdebuggingassertionstatements,youcandetectbugscausedbybadfunctionarguments,accidentaluseofundefinedbehavior,mistakenassumptionsmadebyotherprogrammers,andimpossibleconditionsthatneverthelesssomehowshowup.Debug-onlybackupalgorithmshelpverifyfunctionresultsandthealgorithmsusedinfunctions.

3FORTIFYYOURSUBSYSTEMS

Assertionswaitquietlyuntilbugsshowup.Evenmorepowerfularesubsystemintegritychecksthatactivelyvalidatesubsystemsandalertyoutobugsbeforethebugsaffecttheprogram.TheintegritychecksforthestandardCmemorymanagercandetectdanglingpointers,lostmemoryblocks,andillegaluseofmemorythathasnotbeeninitializedorthathasalreadybeenreleased.Integritycheckscanalsobeusedtoeliminaterarebehavior,whichisresponsibleforuntestedscenarios,andtoforcesubsystembugstobereproduciblesothattheycanbetrackeddownandfixed.

4STEPTHROUGHYOURCODE

Thebestwaytofindbugsistostepthroughallnewcodeinadebugger.Bysteppingthrougheachinstructionwithyourfocusonthedataflow,youcanquicklydetectproblemsinyourexpressionsandalgorithms.Keepingthefocusonthedata,nottheinstructions,givesyouasecond,verydifferent,viewofthecode.Steppingthroughcodetakestime,butnotnearlyasmuchasmostprogrammerswouldexpectitto.

5CANDY-MACHINEINTERFACES

It'snotenoughthatyourfunctionsbebug-free;functionsmustbeeasytousewithoutintroducingunexpectedbugs.Ifbugratesaretobereduced,eachfunctionneedstohaveonewell-definedpurpose,tohaveexplicitsingle-purposeinputsandoutputs,tobereadableatthepointwhereitiscalled,andideallytoneverreturnanerrorcondition.Functionswiththeseattributesareeasytovalidateusingassertionsanddebugcode,andtheyminimizetheamountoferrorhandlingcodethatmustbewritten.

6RISKYBUSINESS

Giventhenumerousimplementationpossibilitiesforagivenfunction,itshouldcomeasnosurprisethatsomeimplementationswillbemoreerrorpronethanothers.Thekeytowritingrobustfunctionsistoexchangeriskyalgorithmsandlanguageidiomsforalternativesthathaveproventobecomparablyefficientyetmuchsafer.Atoneextremethiscanmeanusingunambiguousdatatypes;attheotheritcanmeantossingoutanentiredesignsimplybecauseitwouldbedifficult,orimpossible,totest.

7TREACHERIESOFTHETRADE

Someprogrammingpracticesaresoriskytheyshouldneverbeused.Mostsuchpracticesareobviouslyrisky,butsomeseemquitesafe,evendesirable,becausetheyfillaneedwithoutapparenthazard.Thesetreacherouscodingpracticesarethewolvesinsheep'sclothing.Whyshouldn'tyoureferencememoryyou'vejustreleased?Whyisitriskytopassdatainglobalorstaticstorage?Whyshouldyouavoidparasiticfunctions?Whyitisunwisetorelyoneverynit-pickydetailoutlinedintheANSIstandard?

8THERESTISATTITUDE

Aprogrammercanfolloweveryguidclineinthisbook,butwithouttheproperattitudeandasetofgoodprogramminghabits,writingbug-freecodewillbemuchharderthanitneedstobe.Ifaprogrammerbelievesthatabugcansimply"goaway,"orthatfixingbugs"later"won'tbeharmfultotheproduct,bugswillpersist,ffaprogrammerregularly"cleansup"code,allowsunnecessaryflexibilityinfunctions,welcomesevery"free"featurethatpopsoutofadesign,orsimply"tries"haphazardsolutionstoproblemshopingtohituponsomethingthatworks,writingbug-freecodewillbeanuphillbattle.Havingagoodsetofhabitsandattitudesispossiblythemostimportantrequirementforconsistentlywritingbug-freecode.

EPILOGUEWHEREDOYOUGOFROMHERE?

APPENDIXACODINGCHECKLISTS

APPENDIXBMEMORYLOGGINGROUTINES

APPENDIXCANSWERS

REFERENCES

INDEX

……

相關詞條

相關搜尋

熱門詞條

聯絡我們