1IntroductiontoProgrammingSystemsCS217Goals• Mastertheartofprogramminglearnhowtobe“good”programmers• LearnCandtheUnixdevelopmenttoolsCisthesystemslanguageofchoiceUnixhasarichdevelopmentenvironment• IntroductiontocomputersystemsmachinearchitectureoperatingsystemscompilersOutline• FirstfourweeksCprogramming• SecondfourweeksMachinearchitecture• ThirdfourweeksUnixoperatingsystem2Coursework• Sixprogrammingassignments(60%)stringlibrarycollectionADTtableADTSparcassemblyassemblershell• Twomidterms(30%)5thweek10thweek• Classparticipation(10%)Materials• “Required”textbooksC:AReferenceManual. Harbison &SteeleSPARCArchitecture,etc.Paul• “Recommended”textbooksCInterfacesandImplementations.HansonProgrammingwithGNUSoftware. Loukides & Oram• OthertextbooksTheCProgrammingLanguage,Kernighan&RitchieCProgramming:AModernApproach,King• Webpageswww.cs.princeton.edu/courses/cs217/Facilities• UnixmachinesCIT’s arizona clusterSPARClabinFriend016• Yourownlaptopssh accesstoarizonarunGNUtoolsonWindowsrunGNUtoolsonLinux3Logistics• LecturesMW10AM,CS102,10:00AMintroduceconceptsworkthroughprogrammingexamples• PreceptsTuesdays&Thursdays,10:00AMor1:30PMdemonstratetools(gdb, makefiles,emacs,…)workthroughprogrammingexamplesCanwehaveonlyoneprecept?Canwehaveonlyoneprecept?SoftwareisHard“WhatwerethelessonsIlearnedfromsomanyyearsofintensive workonthepracticalproblemofsettingtypebycomputer?Oneofthemostimportantlessons,perhaps,isthefactthatSOFTWAREISHARD.FromnowonIshallhavesignificantlygreaterrespectforeverysuccessfulsoftwaretoolthatIencounter.DuringthepastdecadeIwassurprisedtolearnthatthewritingofprogramsfor TeX andMetafontprovedtobemuchmoredifficultthanalltheotherthingsIhad done(likeprovingtheoremsorwritingbooks).Thecreationofgoodsoftwaredemandsasignificantlyhigherstandardofaccuracythanthoseotherthingsdo,anditrequiresalongerattentionspanthanotherintellectualtasks.”DonaldKnuth,1989SoftwareinCOS126SpecificationDesignProgrammingDebuggingTesting1Person102LinesofCode1TypeofMachine0Modifications1Week1Person102LinesofCode1TypeofMachine0Modifications1Week4SoftwareintheRealWorldSpecificationDesignProgrammingDebuggingTestingLotsofPeople106LinesofCodeLotsofMachinesLotsofModifications1DecadeormoreLotsofPeople106LinesofCodeLotsofMachinesLotsofModifications1DecadeormoreGoodSoftwareintheRealWorld• UnderstandableWell-designedConsistentDocumented• RobustWorksforanyinputTested• ReusableComponents• EfficientOnlymattersfor1%Writecodeinmoduleswithwell-definedinterfacesWritecodeinmoduleswithwell-definedinterfacesWritecodeinmodulesandtestthemseparatelyWritecodeinmodulesandtestthemseparatelyWritecodeinmodulesthatcanbeusedelsewhereWritecodeinmodulesthatcanbeusedelsewhereWritecodeinmodulesandoptimizetheslowonesWritecodeinmodulesandoptimizetheslowonesModules• Programsaremadeupofmanymodules• Eachmoduleissmallanddoesonethingstringmanipulationmathematicalfunctionsset,stack,queue,list,etc.• Decidinghowtobreakupaprogramintomodulesisakeytogoodsoftwaredesign5Interfaces• Aninterface defineswhat themoduledoesdecoupleclientsfromimplementationhideimplementationdetails• Aninterfacespecifies…datatypesandvariablesfunctionsthatmaybeinvokedStringList *StringList_new(void);voidStringList_free(StringList *list);voidStringList_insert(StringList *list,char*string);voidStringList_remove(StringList *list,char*string);voidStringList_print(StringList *list);intStringList_getLength(StringList *list);StringList *StringList_new(void);voidStringList_free(StringList *list);voidStringList_insert(StringList *list,char*string);voidStringList_remove(StringList *list,char*string);voidStringList_print(StringList *list);intStringList_getLength(StringList *list);Implementations• Animplementation defineshow themoduledoesit• Canhavemanyimplementationsforoneinterfacedifferentalgorithmsfordifferentsituationsmachinedependencies,efficiency,etc.StringList *StringListCreate(void){StringList *list=malloc(sizeof(StringList));list->entries=NULL;list->size=0;}voidStringListDelete(StringList *list){free(list);}etc.StringList *StringListCreate(void){StringList *list=malloc(sizeof(StringList));list->entries=NULL;list->size=0;}voidStringListDelete(StringList *list){free(list);}etc.Clients• Aclient usesamoduleviaitsinterface• Clientsseeonlytheinterfacecanusemodulewithoutknowingitsimplementation• Clientisunaffectedifimplementationchangesaslongasinterfacestaysthesameint main(){StringList *list=StringListCreate();StringListInsert(list,“CS217”);StringListInsert(list,“is”);StringListInsert(list,“fun”);StringListPrint(list);StringListDelete(list);}int main(){StringList
View Full Document