欢迎来到天天文库
浏览记录
ID:33933611
大小:1.51 MB
页数:12页
时间:2019-03-01
《3d游戏编程:编码规范》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、CodingStandardsYanciZhangGameProgrammingIIExtremeProgrammingCodemustbewrittentoagreedstandardCodemustbeformattedtoagreedcodingstandards.Codingstandardskeepthecodeconsistentandeasyfortheentireteamtoreadandrefactor.Codethatlooksthesameencouragescollectiveownership.Commonmis
2、taketoavoidCodingstandardisunnecessarybecauseIamworkingaloneGameProgrammingIIGoodPointsProgrammerscangointoanycodeandfigureoutwhat'sgoingonPeoplenewtoC++aresparedtheneedtodevelopapersonalstyleanddefendittothedeathPeoplenewtoC++aresparedmakingthesamemistakesoverandoveraga
3、inPeoplemakefewermistakesinconsistentenvironmentsGameProgrammingIIBadPointsStandardisusuallystupidIt’smadebysomeoneelseIt'snotwhatIdoStandardsreducecreativityStandardsareunnecessaryaslongaspeopleareconsistentThenew/borrowedcodewon'tfollowthestandardGameProgrammingIINa
4、mingRulesAnameInformingwhatsortofthingthenamedentityisResultoflongdeepthoughtprocessabouttheecologyitlivesinConsistencyismoreimportantthanindividualpreferencesrulesthemselvesTherulesaretherules!GameProgrammingIIFunctionOnefunctionshouldonlyimplementonetaskRefactoryo
5、urfunctionifitislongerthan100linesFunctionnameshouldStartwithasmallletterHaveacapitalletterforeachnewwordNounderscoresPreciselydescribetheworkdoneinthefunctionvoidinit();voidinitComponent();GameProgrammingIIClassThefunctionofclassshouldbesimpleRefactoryourclassifitisl
6、ongerthan500linesClassnameshouldStartwithacapitalletter“C”HaveacapitalletterforeachnewwordNounderscoresclassCRenderer;classCRenderComponent;GameProgrammingIIVariableTypePrefixExamplesstaticvariables_s_Counterglobalvariableg_g_Counterclassmembervariablem_m_IsDirtypointerp
7、pBufferFunctionparametervariablevvBufferGameProgrammingIIConstant1/2Avoidusingnumbersdirectlyinsourcecode(magicnumber)DisadvantagesofmagicnumberIncreaseopportunitiesforsubtleerrorsMakeprogramdifficulttobeextendedinthefuturefloatr=10.0;floatarea=3.14*r*r//badstyleconstflo
8、atPI=3.14;floatr=10.0;floatarea=PI*r*r//goodstyleGameProgrammingIIConstant2
此文档下载收益归作者所有