关闭

关闭

封号提示

内容

首页 API Design for C++.pdf

API Design for C++.pdf

API Design for C++.pdf

上传者: tangwei19811102 2013-09-16 评分1 评论0 下载31 收藏0 阅读量1007 暂无简介 简介 举报

简介:本文档为《API Design for C++pdf》,可适用于专题技术领域,主题内容包含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

类似资料

编辑推荐

Lonely-Planet-Hong-Kong-Macau-City-Travel-Guide-.PDF

行政管理学.ppt

[天哪!数学原来可以这样学].(日)野口哲典.扫描版.pdf

Business Law, Fundamentals (cases) 8ed 2010.pdf

工程亮化合同.doc

职业精品

精彩专题

中国制造,引领“世界第一”

近十年来,我国制造业持续快速发展,总体规模大幅提升,综合实力不断增强,不仅对国内经济和社会发展做出了重要贡献,而且成为支撑世界经济的重要力量。你绝对想不到,中国制造有这么多“世界第一”

用户评论

0/200
    暂无评论
上传我的资料

精选资料

热门资料排行换一换

  • 多复变函数(Narasimhan…

  • 多复变函数(陆启铿).pdf

  • 权力之争.pdf

  • 女性如何在30岁创业成功.pdf

  • 汉书艺文志讲疏.pdf

  • 个人简历范文、大量的个人求职信、…

  • 情剑神龙 司马沧澜.pdf

  • 裘锡圭:文字学概要.pdf

  • 盲派正宗(手抄本).pdf

  • 资料评价:

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

    意见
    反馈

    返回
    顶部