Common coupling and pointer variables, with applic

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

CommonCouplingandPointerVariables,withApplicationtoaLinuxCaseStudyStephenR.SchachTokunboO.S.AdeshiyanDanielBalasubramanianGaborMadlEstebanP.OssesSameerSinghKarlkimSuwanmongkolMinhuiXieDrorG.FeitelsonDepartmentofElectricalEngineeringandComputerScienceVanderbiltUniversity,Nashville,TN37235June29,2005AbstractBothcommoncouplingandpointervariablescanexertadeleteriouse ectonthequalityofsoftware.Thesituationisexacerbatedwhenpointervariablesareassignedtoglobalvariables,thatis,whenanaliastoaglobalvariableiscreated.Whenthisoccurs,thenumberofglobalvariablesincreases,anditbecomesconsiderablyhardertocomputequalitymetricscorrectly.However,unlessaliasingistakenintoaccount,variablesmayincorrectlyappeartobeunreferenced(neitherde nednorused),ortobeusedwithoutbeingde ned.TheseideasareillustratedbymeansofacasestudyofcommoncouplingintheLinuxkernel.OnsabbaticalleavefromHebrewUniversity1Keywords:Commoncoupling,aliasing,pointervariables,Linux,globalvariables,de nition{useanalysis.1IntroductionThegoalofsoftwareengineeringistoproducehigh-qualitymaintainablesoftware.Butthereislittleagreementregardinghowqualityandmaintainabilityshouldbemeasured,andwhethertheycanbemeasureddirectly.Overtheyears,variousindi-rectmeasureshavethereforebeenproposed.Thedegreeofcommoncouplingisoneofthem:Signi cantcommoncouplingisconsideredbad,solowlevelsofcommoncouplingaretakentoindicatehighqualityandmaintainability[Schach,2005].Suchmetricsareespeciallyusefulforthecomparisonofcontendingsoftwaredevelopmentpractices,suchasopen-sourcevs.closedsource.Commoncouplingreferstotheuseofglobalvariables.Usingglobalvariablesisbadbecauseitviolatestheprinciplesofencapsulation,informationhiding,andabstraction.Globalvariablesarevolatile,inthesensethattheirvaluemaybechangedinunpredictableways,duetosidee ectsofcalledfunctions.Usingglobalvariablesisbadpractice;allowingpointervariablestopointtoglobalvariablesisevenworse.Whenglobalvariablesareuseddirectly,itisrelativelystraightforwardto ndallinstancesoftheseglobalvariablesandchecktheire ect.Butwithpointervariables,aglobalvariablemayhaveseveralaliases.Thismakesitimpracticaltotrackthepossibleinteractionsamongdi erentmodules,andincreasestheriskofundesirablee ects.WedemonstratetheproblemsthatstemfromusingpointerstoglobalvariablesbymeansofacasestudyofcommoncouplingintheLinuxkernel.Theremainderofthispaperisorganizedasfollows:InSection2wediscusscou-2plingissues,especiallyglobalvariablesandcommoncoupling.Thee ectsofpointervariablesoncommoncouplingaredescribedinSection3.TheLinuxcasestudyispresentedinSection4,andtheresultsofthecasestudyinSection5.OurconclusionsappearinSection6.2CouplingofSoftwareModulesSuccessfulsoftwareprojectsarethosethatmeettheirspeci cationswithinprede nedbudgetandtimeconstraints.Thismetricisapplicabletotraditionalclosed-sourcesoftwaredevelopment,andhasbeenmeasuredformanythousandsofprojects.Infact,suchmeasurementsarethebasisfortheclaimthatthesoftwareindustryisinacrisis;studiesroutinelyshowthatthemajorityofprojectsfailtomeettheirtargets[Jones,1995,Johnsonet.al.,2001].Regrettably,thisstraightforwardmetriccannotbeappliedtoopen-sourcesoftwareprojects,becausetheytypicallyhavenodetailedspeci cations,nobudget,andnodeadlines.Therefore,indirectmetricshavetobefound.Giventheavailabilityofthesourcecode,itisnaturaltoconsidermetricsthatarebasedonthecodeitself,thatis,metricsforcodequality.Thesehavetheadditionalappealofbeingquantitative,objective,andamenabletomechanizedevaluation.Onesuchmetricisthedegreeofcouplingfoundinthecode.Couplingbetweensoftwaremodulesmeasuresthedegreetowhichtheyaredependentoneachother.Oneofthebasictenetsofsoftwareengineeringisthatmodulesshouldbeonlyweaklycoupledtogether,becausethispromoteseasiermaintenanceandreuse[Schach,2005,O uttet.al.,1993];contrariwise,strongcouplingmakesmoduleshardertounder-standandincreasesthepropensityforerrors[BinkleyandSchach,1998,RillingandKlemola,2003].Therearemanydi erenttypesofcouplingthatcanoccurbetweensoftwaremod-3ules[O uttet.al.,1993].Couplingmeansthatonemoduledependsontheother,typicallyintheformofusingdatathatareproducedbytheothermodule.Thedistinctionsarebasedonwhetherpasseddataarealsousedforcontrolornot,andwhethertheyarepasseduni-directionallyorbi-directionally.Someformofcouplingisobviouslyneededinordertoallowthemodulestoworktogetheraspartsofasingleapplication.Butnotallformsofcouplingareequal.Inparticular,itiswidelyagreedthatsocalled\commoncouplingshouldbeavoided.Thisreferstotheuseofglobal(shared)variables,harkingbacktotheCOMMONkeywordfromFORTRAN.Globalvariablesarebadmainlybecausetheyallowforsidee ects.Consideramodulethatusesaglobalvariableg,andcallsafunctionf()fromanothermod-ule.Whenthefunctionreturns,thevalueofgmayhavechanged.Moreover,futurechangestof()maycausenewandunexpectedbehaviorofg.Consequently,thepro-grammercannotrelyongremainingconsistent,andneedstohandleitwithextremecare.Anotherreasonthatcommoncouplingisconsideredbadisthatitissuscepti-bletoclandestineincrease,wherethecouplingofagivenmoduleincreaseswithoutthemoduleitselfbeingmodi edinanyway,justbecauseothermodulesha

1 / 16
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功