关闭

关闭

封号提示

内容

首页 API Design for C++.pdf

API Design for C++.pdf

API Design for C++.pdf

上传者: tangwei19811102 2013-09-16 评分 5 0 222 30 1009 暂无简介 简介 举报

简介:本文档为《API Design for C++pdf》,可适用于IT/计算机领域,主题内容包含APIDesignforCAPIDesignforCMartinReddyAMSTERDAM•BOSTON•HEIDELBERG•LONDONNEW符等。

APIDesignforCAPIDesignforCMartinReddyAMSTERDAM•BOSTON•HEIDELBERG•LONDONNEWYORK•OXFORD•PARIS•SANDIEGOSANFRANCISCO•SINGAPORE•SYDNEY•TOKYOMorganKaufmannPublishersisanimprintofElsevierAcquiringEditor:ToddGreenNopartofthispublicationmaybereproducedortransmittedinanyformorbyanymeans,electronicormechanical,includingphotocopying,recording,oranyinformationstorageandretrievalsystem,withoutpermissioninwritingfromthepublisherDetailsonhowtoseekpermission,furtherinformationaboutthePublisher’spermissionspoliciesandourarrangementswithorganizationssuchastheCopyrightClearanceCenterandtheCopyrightLicensingAgency,canbefoundatourwebsite:wwwelseviercompermissionsThisbookandtheindividualcontributionscontainedinitareprotectedundercopyrightbythePublisher(otherthanasmaybenotedherein)NoticesKnowledgeandbestpracticeinthisfieldareconstantlychangingAsnewresearchandexperiencebroadenourunderstanding,changesinresearchmethodsorprofessionalpracticesmaybecomenecessaryPractitionersandresearchersmustalwaysrelyontheirownexperienceandknowledgeinevaluatingandusinganyinformationormethodsdescribedhereinInusingsuchinformationormethodstheyshouldbemindfuloftheirownsafetyandthesafetyofothers,includingpartiesforwhomtheyhaveaprofessionalresponsibilityTothefullestextentofthelaw,neitherthePublishernortheauthors,contributors,oreditors,assumeanyliabilityforanyinjuryandordamagetopersonsorpropertyasamatterofproductsliability,negligenceorotherwise,orfromanyuseoroperationofanymethods,products,instructions,orideascontainedinthematerialhereinLibraryofCongressCataloginginPublicationDataApplicationsubmittedBritishLibraryCataloguinginPublicationDataAcataloguerecordforthisbookisavailablefromtheBritishLibraryISBN:PrintedintheUnitedStatesofAmericaEditorialAssistant:RobynDayProjectManager:AndreCuelloDesigner:EricDeCiccoMorganKaufmannisanimprintofElsevierCorporateDrive,Suite,Burlington,MA,USA#Elsevier,IncAllrightsreservedForinformationonallMKpublicationsvisitourwebsiteatwwwmkpcomForewordIshouldbeginbyconfessingthatIdonotconsidermyselfaworldclassAPIdesignerorsoftwareengineerIdo,however,considermyselfanexpertresearcherintheareasofcomputergraphicsandgeometricmodelingItwasinthislineofworkthatIfirstmetMartinatPixarAnimationStudiosxvAsagraphicsresearcherIwasaccustomedtowritingmathematicallysophisticatedpapersIwasalsoformallytrainedasacomputerscientistatamajoruniversityandhadwrittenmyshareofcodeArmedwiththisbackground,whenIwaspresentedwiththeopportunitytoleadagroupofsoftwareengineersworkingonanewgenerationofanimationsoftwareforPixar,Ifiguredthatitcouldn’tbeanymoredifficultthanresearchAfterall,researchis,bydefinition,thecreationoftheunknown,whereasengineeringistheimplementationofwellunderstoodsubjectsIcouldnothavebeenmorewrongIcametorealizethatsoftwareengineeringwas,withoutadoubt,themostdifficultchallengeIhadeverbeenpresentedwithAftermoreyearsthanIcaretoadmit,IeventuallygaveupandwentbacktographicsresearchIcan’ttellyouhowmuchIwouldhavebenefittedfromabooksuchas“APIDesignforC”ManyofthelessonswelearnedthehardwayhavebeencapturedbyMartininthisinsightful,easytousebookMartinapproachesthesubjectnotfromtheperspectiveofanacademicsoftwareresearcher(althoughhedrawsheavilyfromresultsandinsightsgainedthere),butfromtheperspectiveofaninthetrenchessoftwareengineerandmanagerHehasexperiencedfirsthandtheimportanceofgoodsoftwaredesignandhasemergedasanarticulatevoiceofwhat“good”meansInthisbookhepresentseffectivestrategiesforachievingthatgoalIparticularlylikethatMartinisnotfocusingjustonAPIdesign,butmorebroadlyonsoftwarelifecycles,allowinghimtocovertopicssuchasversioning,strategiesforbackwardcompatibility,andbranchingmethodologiesInshort,thisbookshouldbeofgreatvaluetothosecreatingormanagingsoftwareactivitiesItisacomprehensivecollectionofbestpracticesthathaveproventhemselvestimeandtimeagainTonyDeRoseSeniorScientistandResearchGroupLead,PixarAnimationStudiosAnAPIpresentsalogicalinterfacetoasoftwarecomponentandhidestheinternaldetailsrequiredtoimplementthatcomponentItoffersahighlevelabstractionforamoduleandpromotesmorecostlytofixthanabuginyourimplementationForinstance,aninterfacechangemayrequirealloftheapplicationsbasedonyourcodetobeupdated,whereasanimplementacanbeintegratedtransparentlyandeffortlesslyintoclientapplicationswhenthetiononlychangeyadoptthenewxviicodereusebyallowingmultipleapplicationstosharethesamefunctionalityModernsoftwaredevelopmenthasbecomehighlydependentonAPIs,fromlowlevelapplicationframeworkstodataformatAPIsandgraphicaluserinterface(GUI)frameworksInfact,commonsoftwareengineeringtermssuchasmodulardevelopment,codereuse,componentization,dynamiclinklibraryorDLL,softwareframeworks,distributedcomputing,andserviceorientedarchitectureallimplytheneedforstrongAPIdesignskillsSomepopularCandCAPIsthatyoumayalreadybeawareofincludetheStandardTemplateLibrary(STL),Boost,theMicrosoftWindowsAPI(Win),MicrosoftFoundationClasses(MFC),libtiff,libpng,zlib,libxml,OpenGL,MySQL,Trolltech’sQt,wxWidgets,GTK,KDE,SkypeKit,POSIXpthreads,Intel’sThreadingBuildingBlocks,theNetscapePluginAPI,andtheApachemoduleAPIInaddition,manyofGoogle’sopensourceprojectsareC,asismuchofthecodeonthesourceforgenet,bitbucketorg,andfreshmeatnetWebsitesAPIssuchastheseareusedinallfacetsofsoftwaredevelopment,fromdesktopapplications,tomobilecomputingandembeddedsystems,toWebdevelopmentForexample,theMozillaFirefoxWebbrowserisbuiltontopofmorethandynamiclibraries,eachofwhichprovidestheimplementationforoneormoreAPIsElegantandrobustAPIdesignisthereforeacriticalaspectofcontemporarysoftwaredevelopmentOneimportantwayinwhichthisdiffersfromstandardapplicationdevelopmentisthefargreaterneedforchangemanagementAsweallknow,changeisaninevitablefactorinsoftwaredevelopmentnewrequirements,featurerequests,andbugfixescausesoftwaretoevolveinwaysthatwereneveranticipatedwhenitwasfirstdevisedHowever,changestoanAPIthatissharedbyhundredsofenduserapplicationscancausemajorupheavalandultimatelymaycauseclientstoabandonanAPITheprimarygoalofgoodAPIdesignisthereforetoprovideyourclientswiththefunctionalitytheyneedwhilealsocausingminimalimpacttotheircodeideallyzeroimpactwhenyoureleaseanewversionWHYYOUSHOULDREADTHISBOOKIfyouwriteCcodethatanotherengineerreliesupon,you’reanAPIdesignerandthisbookhasbeenwrittenforyouInterfacesarethemostimportantcodethatyouwritebecauseaproblemwithyourinterfaceisfarPrefaceWritinglargeapplicationsinCisacomplexandtrickybusinessHowever,designingreusableCinterfacesthatarerobust,stable,easytouse,anddurableisevenmoredifficultThebestwaytosucceedinthisendeavoristoadheretothetenetsofgoodApplicationProgrammingInterface(API)designimplementation,testing,documentation,release,versioning,maintenance,anddeprecationIwillxviiiPrefaceevencoverspecializedAPItopicssuchascreatingscriptingandpluginAPIsWhilemanyofthesetopicsarealsorelevanttosoftwaredevelopmentingeneral,thefocusherewillbeontheparticularimplicationsforAPIdesignForexample,whendiscussingtestingstrategiesIwillconcentrateonautomatedAPItestingtechniquesratherthanattemptingtoincludeenduserapplicationtestingtechniquessuchasGUItesting,systemtesting,ormanualtestingIntermsofmyowncredentialstowritethisbook,IhaveledthedevelopmentofAPIsforresearchcodesharedbyseveralcollaboratinginstitutions,inhouseanimationsystemAPIsthathavebeenusedtomakeAcademyAwardwinningmovies,andopensourceclientserverAPIsthathavebeenusedbymillionsofpeopleworldwideThroughoutallofthesedisparateexperiences,IhaveconsistentlywitnessedtheneedforhighqualityAPIdesignThisbookthereforepresentsapracticaldistillationofthetechniquesandstrategiesofindustrialstrengthAPIdesignthathavebeendrawnfromarangeofrealworldexperiencesWHOISTHETARGETAUDIENCEWhilethisbookisnotabeginner’sguidetoC,IhavemadeeveryefforttomakethetexteasytoreadandtoexplainallterminologyandjargonclearlyThebookshouldthereforebevaluabletonewprogrammerswhohavegraspedthefundamentalsofCandwanttoadvancetheirdesignskills,aswellasseniorengineersandsoftwarearchitectswhoareseekingtogainnewexpertisetocomplementtheirexistingtalentsTherearethreespecificgroupsofreadersthatIhaveborneinmindwhilewritingthisbookPracticingsoftwareengineersandarchitectsJuniorandseniordeveloperswhoareworkingonaspecificAPIprojectandneedpragmaticadviceonhowtoproducethemostelegantandenduringdesignTechnicalmanagersProgramandproductmanagerswhoareresponsibleforproducinganAPIproductandwhowanttogaingreaterinsightintothetechnicalissuesanddevelopmentprocessesofAPIdesignAPIversionPutinmoreeconomicterms,apoorlydesignedinterfacecanseriouslyreducethelongtermsurvivalofyourcodeLearninghowtocreatehighqualityinterfacesisthereforeanessentialengineeringskill,andthecentralfocusofthisbookAsMichiHenningnoted,APIdesignismoreimportanttodaythanitwasyearsagoThisisbecausemanymoreAPIshavebeendesignedinrecentyearsThesealsoprovidericherandmorecomplexfunctionalityandaresharedbymoreenduserapplications(Henning,)Despitethisfact,nootherbookscurrentlyonthemarketconcentrateonthetopicofAPIdesignforCIt’sworthnotingthatthisbookisnotmeanttobeageneralCprogrammingguidetherearealreadymanygoodexamplesoftheseonthemarketIwillcertainlycoverlotsofobjectorienteddesignmaterialandpresentmanyhandyCtipsandtricksHowever,IwillfocusontechniquesforrepresentingcleanmodularinterfacesinCBycorollary,Iwillnotdiveasdeeplyintothequestionofhowtoimplementthecodebehindtheseinterfaces,suchasspecificalgorithmchoicesorbestpracticeslimitedtothecodewithinthecurlybracesofyourfunctionbodiesHowever,thisbookwillcoverthefullbreadthofAPIdevelopment,frominitialdesignthroughxixPrefaceCONVENTIONSWhileitismoretraditionaltoemploytheterm“user”tomeanapersonwhousesasoftwareapplication,suchasauserofMicrosoftWordorMozillaFirefox,inthecontextofAPIdesignIwillapplythetermtomeanasoftwaredeveloperwhoiscreatinganapplicationandisusinganAPItoachieveFOCUSINGONCWhiletherearemanygenericAPIdesignmethodologiesthatcanbetaughtskillsthatapplyequallywelltoanyprogramminglanguageorenvironmentultimatelyanAPIhastobeexpressedinaparticularprogramminglanguageItisthereforeimportanttounderstandthelanguagespecificfeaturesthatcontributetoexemplaryAPIdesignThisbookisthereforefocusedontheissuesofdesigningAPIsforasinglelanguage(C)ratherthandilutingthecontenttomakeitapplicableforalllanguagesWhilereaderswhowishtodevelopAPIsforotherlanguages,suchasJavaorC#,maystillgainmuchgeneralinsightfromthistext,thebookisdirectlytargetedatCengineerswhomustwriteandmaintainAPIsforotherengineerstoconsumeCisstilloneofthemostwidelyusedprogramminglanguagesforlargesoftwareprojectsandtendstobethemostpopularchoiceforperformancecriticalcodeAsaresult,therearemanydiverseCandCAPIsavailableforyoutouseinyourownapplications(someofwhichIlistedearlier)IwillthereforeconcentrateonaspectsofproducinggoodAPIsinCandincludecopioussourcecodeexamplestoillustratetheseconceptsbetterThismeansthatIwilldealwithCspecifictopicssuchastemplates,encapsulation,inheritance,namespaces,operators,constcorrectness,memorymanagement,useofSTL,thepimplidiom,andsoonAdditionally,thisbookwillbepublishedduringanexcitingtimeintheevolutionofCAnewversionoftheCspecificationiscurrentlyworkingitswaythroughtheISOIECstandardizationprocessMostCcompilerscurrentlyaimtoconformtothestandardthatwasfirstpublishedin,knownasCAlaterrevisionofthisstandardwaspublishedintocorrectseveraldefectsSincethattime,thestandardscommitteehasbeenworkingonamajornewversionofthespecificationThisversionisreferredtoinformallyasCx,untilsuchtimethatthestandardisratifiedandthedateofpublicationisknownBythetimeyoureadthisbook,thenewstandardwilllikelyhavebeenpublishedHowever,atthetimeofwriting,itisstillreferredtoasCxNonetheless,Cxhasreachedanadvancedstageofthestandardizationprocess,andmanyofthenewfeaturescanbepredictedwithrelativelyhighconfidenceInfact,someofthemajorCcompilershavealreadystartedtoimplementmanyoftheproposednewfeaturesIntermsofAPIdesign,severalofthesenewlanguagefeaturescanbeusedtoproducemoreelegantandsturdyinterfacesAssuch,IhaveendeavoredtohighlightandexplainthoseareasofCxthroughoutthebookThisbookshouldthereforeremainarelevantresourceforseveralyearstocomeStudentsandeducatorsComputerscienceandsoftwareengineeringstudentswhoarelearninghowtoprogramandareseekingathoroughresourceonsoftwaredesignthatisinformedbypracticalexperienceonlargescaleprojectsxxPrefacethisInotherwords,IwillgenerallybetalkingaboutAPIusersandnotapplicationusersTheterm“client”willbeusedsynonymouslyinthisregardNotethattheterm“client,”inadditiontoreferringtoahumanuserofyourAPI,canalsoreferimpersonallytootherpiecesofsoftwarethatmustcallfunctionsinyourAPIWhiletherearemanyfileformatextensionsusedtoidentifyCsourceandheaderfiles,suchascpp,cc,cxx,h,hh,andhpp,Iwillstandardizeontheuseofcppandhthroughoutthisbook“Iwillalsousethetermsmoduleandcomponent”interchangeablytomeanasinglecppandhfilepairThesearenotablynotequivalenttoaclassbecauseacomponentormodulemaycontainmultipleclassesIwillusethetermlibrarytorefertoaphysicalcollection,orpackage,ofcomponents,thatis,library>modulecomponent>classThetermmethod,whilegenerallyunderstoodintheobjectorientedprogrammingcommunity,isnotstrictlyaCtermitoriginallyevolvedfromtheSmalltalklanguageTheequivalentCtermismemberfunction,althoughsomeengineerspreferthemorespecificdefinitionofvirtualmemberfunctionBecauseIamnotparticularlyconcernedwiththesubtletiesofthesetermsinthisbook,IwillusemethodandmemberfunctioninterchangeablySimilarly,althoughthetermdatamemberisthemorecorrectCexpression,IwilltreatthetermmembervariableasasynonymIntermsoftypographicalconventions,Iwilluseafixedwidthfonttotypesetallsourcecodeexamples,aswellasanyfilenamesorlanguagekeywordsthatmayappearinthetextAlso,IwillpreferuppercamelcaseforallclassandfunctionnamesintheexamplesthatIpresent,thatis,CamelCaseinsteadofcamelCaseorsnakecase,althoughobviouslyIwillpreservethecaseforanyexternalcodethatIreference,suchasstd::foreach()Ifollowtheconventionofusingan“m”prefixinfrontofdatamembers,forexample,mMemberVar,and“s”infrontofstaticvariables,forexample,sStaticVarItshouldbepointedoutthatthesourceexampleswithinthebookareoftenonlycodesnippetsandarenotmeanttoshowfullyfunctionalsamplesIwillalsooftenstripcommentsfromtheexamplecodeinthebookThisisdoneforreasonsofbrevityandclarityInparticular,IwilloftenomitanypreprocessorguardstatementsaroundaheaderfileIwillassumethatthereaderisawarethateveryCCheadershouldencloseallofitscontentwithinguardstatementsandthatit’sgoodpracticetocontainallofyourAPIdeclarationswithinaconsistentnamespace(ascoveredinChaptersand)Inotherwords,itshouldbeassumedthateachheaderfilethatIpresentisimplicitlysurroundedbycode,suchasthefollowing#ifndefMYMODULEH#defineMYMODULEHrequired#includefilesnamespaceapibook{APIdeclarations}#endifTIPIwillalsohighlightvariousAPIdesigntipsandkeyconceptsthroughoutthebookThesecalloutsareprovidedtoletyousearchquicklyforaconceptyouwishtorereadIfyouareparticularlypressedfortime,youcouldsimplyscanthebookforthesetipsandthenreadthesurroundingtexttogaingreaterinsightforthosetopicsthatinterestyouthemostBOOKWEBSITEThisbookalsohasasupportingWebsite,http:APIBookcomOnthissiteyoucanfindgeneralinformationaboutthebook,aswellassupportingmaterial,suchasthecompletesetofsourcecodeexamplescontainedwithinthetextFeelfreetodownloadandplaywiththesesamplesyourselftheyweredesignedtobeassimpleaspossible,whilestillbeingusefulandillustrativeIhaveusedthecrossplatformCMakebuildsystemtofacilitatecompilingandlinkingtheexamplessotheyshouldworkonWindows,MacOSX,andUNIXoperatingsystemsIwillalsopublishanyinformationaboutnewrevisionsofthisbookandanyerrataonthisWebsite,aswellasusefullinkstootherrelatedAPIresourcesontheInternet,suchasinterestingtoolkits,xxiPrefacearticles,andutilitiesThebookWebsitealsoprovidesaccesstoautilitythatIwrotecalledAPIDiffThisprogramletsyoucomparetwoversionsofanAPIandreviewdifferencestocodeorcommentsinavisualsidebysideformatYoucanalsogenerateareportofeverythingthatchangedinaparticularreleasesothatyourclientsknowexactlywhattolookoutforThisutilityisavailableforWindows,MacOSX,andLinuxportedmethroughoutthewholeprocess,whilealsoknowingexactlywhentomakemepauseandtakeabreakThankyouGenevieveforyourconstantloveandsupportxxiiiAcknowledgmentsThisbookhasbenefitedgreatlyfromthetechnicalreviewandfeedbackofseveralofmyesteemedcolleaguesIamindebtedtothemfortakingthetimetoreadearlyversionsofthemanuscriptandprovidethoughtfulsuggestionsforimprovementInparticular,IthankPaulStrauss,EricGregory,RychardeHawkes,NickLong,JamesChalfant,BrettLevin,MarcusMarr,JimHumelsine,andGeo

类似资料

编辑推荐

日本学者中国词学论文集(上海古籍出版社).pdf

新东方俞敏洪词根词缀记忆大全.pdf

中国文学史(全三册)(钱基博;中华书局1993).pdf

一口气读完日本史.pdf

研究生英汉翻译教程.pdf

职业精品

精彩专题

上传我的资料

精选资料

热门资料排行换一换

  • 越南古代史 下册.pdf

  • 中国的四大家族(陈伯达).pdf

  • 【书法】千年藏帖——颜柳欧赵书法…

  • 【书法】启功书法作品选.pdf

  • 【书法】草书写法(邓散木).pdf

  • 大震之后:心理援助与疾病预防 四…

  • 化学工程计算手册.pdf

  • 武式太极拳.pdf

  • 【原典英语推荐中高级别素材5】T…

  • 资料评价:

    / 446
    所需积分:1 立即下载

    意见
    反馈

    返回
    顶部