CommonCouplingandPointerVariables,withApplicationtoaLinuxCaseStudyStephenR.SchachTokunboO.S.AdeshiyanDanielBalasubramanianGaborMadlEstebanP.OssesSameerSinghKarlkimSuwanmongkolMinhuiXieDrorG.FeitelsonDepartmentofElectricalEngineeringandComputerScienceVanderbiltUniversity,Nashville,TN37235June29,2005AbstractBothcommoncouplingandpointervariablescanexertadeleteriouseectonthequalityofsoftware.Thesituationisexacerbatedwhenpointervariablesareassignedtoglobalvariables,thatis,whenanaliastoaglobalvariableiscreated.Whenthisoccurs,thenumberofglobalvariablesincreases,anditbecomesconsiderablyhardertocomputequalitymetricscorrectly.However,unlessaliasingistakenintoaccount,variablesmayincorrectlyappeartobeunreferenced(neitherdenednorused),ortobeusedwithoutbeingdened.TheseideasareillustratedbymeansofacasestudyofcommoncouplingintheLinuxkernel.OnsabbaticalleavefromHebrewUniversity1Keywords:Commoncoupling,aliasing,pointervariables,Linux,globalvariables,denition{useanalysis.1IntroductionThegoalofsoftwareengineeringistoproducehigh-qualitymaintainablesoftware.Butthereislittleagreementregardinghowqualityandmaintainabilityshouldbemeasured,andwhethertheycanbemeasureddirectly.Overtheyears,variousindi-rectmeasureshavethereforebeenproposed.Thedegreeofcommoncouplingisoneofthem:Signicantcommoncouplingisconsideredbad,solowlevelsofcommoncouplingaretakentoindicatehighqualityandmaintainability[Schach,2005].Suchmetricsareespeciallyusefulforthecomparisonofcontendingsoftwaredevelopmentpractices,suchasopen-sourcevs.closedsource.Commoncouplingreferstotheuseofglobalvariables.Usingglobalvariablesisbadbecauseitviolatestheprinciplesofencapsulation,informationhiding,andabstraction.Globalvariablesarevolatile,inthesensethattheirvaluemaybechangedinunpredictableways,duetosideeectsofcalledfunctions.Usingglobalvariablesisbadpractice;allowingpointervariablestopointtoglobalvariablesisevenworse.Whenglobalvariablesareuseddirectly,itisrelativelystraightforwardtondallinstancesoftheseglobalvariablesandchecktheireect.Butwithpointervariables,aglobalvariablemayhaveseveralaliases.Thismakesitimpracticaltotrackthepossibleinteractionsamongdierentmodules,andincreasestheriskofundesirableeects.WedemonstratetheproblemsthatstemfromusingpointerstoglobalvariablesbymeansofacasestudyofcommoncouplingintheLinuxkernel.Theremainderofthispaperisorganizedasfollows:InSection2wediscusscou-2plingissues,especiallyglobalvariablesandcommoncoupling.TheeectsofpointervariablesoncommoncouplingaredescribedinSection3.TheLinuxcasestudyispresentedinSection4,andtheresultsofthecasestudyinSection5.OurconclusionsappearinSection6.2CouplingofSoftwareModulesSuccessfulsoftwareprojectsarethosethatmeettheirspecicationswithinpredenedbudgetandtimeconstraints.Thismetricisapplicabletotraditionalclosed-sourcesoftwaredevelopment,andhasbeenmeasuredformanythousandsofprojects.Infact,suchmeasurementsarethebasisfortheclaimthatthesoftwareindustryisinacrisis;studiesroutinelyshowthatthemajorityofprojectsfailtomeettheirtargets[Jones,1995,Johnsonet.al.,2001].Regrettably,thisstraightforwardmetriccannotbeappliedtoopen-sourcesoftwareprojects,becausetheytypicallyhavenodetailedspecications,nobudget,andnodeadlines.Therefore,indirectmetricshavetobefound.Giventheavailabilityofthesourcecode,itisnaturaltoconsidermetricsthatarebasedonthecodeitself,thatis,metricsforcodequality.Thesehavetheadditionalappealofbeingquantitative,objective,andamenabletomechanizedevaluation.Onesuchmetricisthedegreeofcouplingfoundinthecode.Couplingbetweensoftwaremodulesmeasuresthedegreetowhichtheyaredependentoneachother.Oneofthebasictenetsofsoftwareengineeringisthatmodulesshouldbeonlyweaklycoupledtogether,becausethispromoteseasiermaintenanceandreuse[Schach,2005,Outtet.al.,1993];contrariwise,strongcouplingmakesmoduleshardertounder-standandincreasesthepropensityforerrors[BinkleyandSchach,1998,RillingandKlemola,2003].Therearemanydierenttypesofcouplingthatcanoccurbetweensoftwaremod-3ules[Outtet.al.,1993].Couplingmeansthatonemoduledependsontheother,typicallyintheformofusingdatathatareproducedbytheothermodule.Thedistinctionsarebasedonwhetherpasseddataarealsousedforcontrolornot,andwhethertheyarepasseduni-directionallyorbi-directionally.Someformofcouplingisobviouslyneededinordertoallowthemodulestoworktogetheraspartsofasingleapplication.Butnotallformsofcouplingareequal.Inparticular,itiswidelyagreedthatsocalled\commoncouplingshouldbeavoided.Thisreferstotheuseofglobal(shared)variables,harkingbacktotheCOMMONkeywordfromFORTRAN.Globalvariablesarebadmainlybecausetheyallowforsideeects.Consideramodulethatusesaglobalvariableg,andcallsafunctionf()fromanothermod-ule.Whenthefunctionreturns,thevalueofgmayhavechanged.Moreover,futurechangestof()maycausenewandunexpectedbehaviorofg.Consequently,thepro-grammercannotrelyongremainingconsistent,andneedstohandleitwithextremecare.Anotherreasonthatcommoncouplingisconsideredbadisthatitissuscepti-bletoclandestineincrease,wherethecouplingofagivenmoduleincreaseswithoutthemoduleitselfbeingmodiedinanyway,justbecauseothermodulesha