1IntroductiontoProgrammingSystemsCS217ThomasFunkhouser&BobDonderoPrincetonUniversityGoals• MastertheartofprogrammingLearnhowtobe“good”programmersIntroductiontosoftwareengineering• LearnCandtheUnixdevelopmenttoolsCisthesystemslanguageofchoiceUnixhasarichdevelopmentenvironment• IntroductiontocomputersystemsMachinearchitectureOperatingsystemsCompilers2Outline• FirstfourweeksCprogramming• SecondfourweeksMachinearchitecture• ThirdfourweeksUnixoperatingsystemCoursework• Sixprogrammingassignments(60%)StringlibraryHashtableADTCircuitsimulatorSparc assemblyAssemblerShell• Exams(30%)MidtermFinal• Classparticipation(10%)3Materials• RequiredtextbooksCProgramming:AModernApproach,KingSPARCArchitecture,etc.Paul• RecommendedtextbooksThePracticeofProgramming, Kernighan &PikeProgrammingwithGNUSoftware. Loukides & Oram• OthertextbooksTheCProgrammingLanguage,Kernighan&RitchieC:AReferenceManual. Harbison &SteeleCInterfacesandImplementations.HansonTheUNIXProgrammingEnvironment.Kernighan &Pike• Webpageswww.cs.princeton.edu/courses/cs217/Facilities• UnixmachinesCIT’s arizona clusterSPARClabinFriend016• Yourownlaptopssh accesstoarizonarunGNUtoolsonWindowsrunGNUtoolsonLinux4Logistics• LecturesIntroduceconceptsWorkthroughprogrammingexamples– M,W10AM CS105• PreceptsReviewconceptsDemonstratetools(gdb, makefiles,emacs,…)Workthroughprogrammingexamples– T,Th 1:30 Friend110– M,W1:30 Friend111– TBASoftwareisHard“WhatwerethelessonsIlearnedfromsomanyyearsofintensive workonthepracticalproblemofsettingtypebycomputer?Oneofthemostimportantlessons,perhaps,isthefactthatSOFTWAREISHARD.FromnowonIshallhavesignificantlygreaterrespectforeverysuccessfulsoftwaretoolthatIencounter.DuringthepastdecadeIwassurprisedtolearnthatthewritingofprogramsfor TeX andMetafontprovedtobemuchmoredifficultthanalltheotherthingsIhad done(likeprovingtheoremsorwritingbooks).Thecreationofgoodsoftwaredemandsasignificantlyhigherstandardofaccuracythanthoseotherthingsdo,anditrequiresalongerattentionspanthanotherintellectualtasks.”DonaldKnuth,19895SoftwareinCOS126SpecificationDesignProgrammingDebuggingTesting1Person102LinesofCode1TypeofMachine0Modifications1Week1Person102LinesofCode1TypeofMachine0Modifications1WeekSoftwareintheRealWorldSpecificationDesignProgrammingDebuggingTestingLotsofPeople106LinesofCodeLotsofMachinesLotsofModifications1DecadeormoreLotsofPeople106LinesofCodeLotsofMachinesLotsofModifications1Decadeormore6GoodSoftwareintheRealWorld• UnderstandableWell-designedConsistentDocumented• RobustWorksforanyinputTested• ReusableComponents• EfficientOnlymattersfor1%Writecodeinmoduleswithwell-definedinterfacesWritecodeinmoduleswithwell-definedinterfacesWritecodeinmodulesandtestthemseparatelyWritecodeinmodulesandtestthemseparatelyWritecodeinmodulesthatcanbeusedelsewhereWritecodeinmodulesthatcanbeusedelsewhereWritecodeinmodulesandoptimizetheslowonesWritecodeinmodulesandoptimizetheslowonesGoodSoftwareintheRealWorld• UnderstandableWell-designedConsistentDocumented• RobustWorksforanyinputTested• ReusableComponents• EfficientOnlymattersfor1%Writecodeinmoduleswithwell-definedinterfacesWritecodeinmoduleswithwell-definedinterfacesWritecodeinmodulesandtestthemseparatelyWritecodeinmodulesandtestthemseparatelyWritecodeinmodulesthatcanbeusedelsewhereWritecodeinmodulesthatcanbeusedelsewhereWritecodeinmodulesandoptimizetheslowonesWritecodeinmodulesandoptimizetheslowones7Modules• Programsaremadeupofmanymodules• Eachmoduleissmallanddoesonethingstringmanipulationmathematicalfunctionsset,stack,queue,list,etc.• DecidinghowtobreakupaprogramintomodulesisakeytogoodsoftwaredesignReadStringsStringListSortStringsPrintStringsInterfaces• Aninterface defineswhat themoduledoesdecoupleclientsfromimplementationhideimplementationdetails• Aninterfacespecifies…datatypesandvariablesfunctionsthatmaybeinvokedStringList *StringList_create(void);voidStringList_delete(StringList *list);voidStringList_insert(StringList *list,char*string);voidStringList_remove(StringList *list,char*string);intStringList_write(StringList *list);StringList *StringList_create(void);voidStringList_delete(StringList *list);voidStringList_insert(StringList *list,char*string);voidStringList_remove(StringList *list,char*string);intStringList_write(StringList *list);8Implementations• Animplementation defineshow themoduledoesit• Canhavemanyimplementationsforoneinterfacedifferentalgorithmsfordifferentsituationsmachinedependencies,efficiency,etc.StringList *StringList_create(void){StringList *list=malloc(sizeof(StringList));list->entries=NULL;list->size=0;}voidStringList_delete(StringList *list){free(list);}etc.StringList *StringList_create(void){StringList
View Full Document