comp61511 (fall 2017) software engineering concepts in...
TRANSCRIPT
1
COMP61511(Fall2017)SoftwareEngineeringConcepts
InPracticeWeek4
BijanParsia&ChristosKotselidis< , @manchester.ac.uk>
(bugreportswelcome!)bijan.parsia christos.kotselidis
3.2
WhatIsConstruction?Adefinition:
Software construction is the creation, assembly, ormodification of executable programs typically viamodificationofthesourcecode.
3.3
AbstractionHierarchyOfASystem
Nottheonlyformulationofsuchahierarchy!
3.4
ArchitectureVs.Construction
3.5
CodingAsProblemSolvingSoftwareengineeringisproblemsolving
Hence,thefoundationalnatureofproblemdefinitionWritingormodifyingcode
IsalsoaformofproblemsolvingWehopesmallerproblems.
Protip:Alwaysknowtheproblemyou'resolving!
3.6
TheBigFour(PlusTwo)Fourprimaryactivities1. Creating
Weneedfunctionality2. Debugging
Weneedcorrectness3. Refactoring(lastweek!)
Weneedcomprehensibility4. Optimising
Weneedefficiency(wrttosomeresource)Plustwo
Testing&Reading
3.7
TestingIsEverywhereAllprimaryactivitiesinvolvetesting
WhetherformalorinformalE.g.,Creation(whethertestfirstornot)
3.8
ReadingIsEverywhereReadingcodeisakeyskill
Otherpeople'scodethatyouareusingthatyouaremodifying
Yourowncode!whetherusingormodifying
"Reading"(understanding)systemsisakeyskillGraspingtheproblem,requirements,architectureRelatingcodetothose
3.9
10 lines of code = 10 issues.
500 lines of code = "looks fine."
Code reviews.10:58 AM - Nov 5, 2013
106 8,033 4,409
I Am Devloper @iamdevloper
Follow
Reviews
4.2
WhatIs(Code)Creation?Code creation (or coding) is the addition of newfunctionality by the generation of new code and units ofcode
Keyactivity!Oftendirectlymeasured
ProductivityasLOC/day(Though,deletingcodemightbebetter!)
DoesnothavetobeexnihiloCut-paste-modifyreusecountsReusecounts!
4.3
PrerequisitesRememberthe !
What'syouroverallproblemdefinitionWhatpartareyoutackling
WhatarethepertinentrequirementsUnderstandthearchitecture
AndhowyourcurrentcodefitsinKnowthelocalstandards
E.g.,codeformattingstyle
prerequisites
4.4
ArchitectureAgoodarchitectureshould:1. helpyoudeterminewhereyourcodeshouldgo2. constrainhowfunctionalityisdivvyedup3. determineyourcommunicationchannels4. giveyouasenseofthingsfittingtogether
thatissharedCode-Architectureconflictsindicate
AproblemwithoneortheotherAlimit
4.5
TechnologyChoicesDifferenttechnologychoicesaffectcode
LanguageMono-vs.poly-glotTypingregime"Batteries"Mindshareetc.
Frameworks,libraries,OSs,etc.
4.6
ToolsDevelopmentenvironments
EditorsIDEsSourcecontrol
DynamictoolsCompilersDebuggers&TestersProfilers
StatictoolsLint,syntax,stylecheckersetc.
4.7
AwarenessesSituationalAwareness
YourperceptionofthecurrentpertinentfactorsfordecisionmakingGoodsituationalawareness
Tracksallpertinentfactorstotherightdegreeinamannertodriveappropraitereactionsatlowcost
DrivestacticsandthusactionUnderstanding
YoursystematicgraspofallfactorsrelatedtodecisionmakingResultsfromsensemakingMorecognitive(indirectlydrivesaction)
4.8
GettingInTheZoneGivenaproblem,oursolvingcanbe
focusedwehavetightsituationalawarenessthe"situation"istheproblemandsolutionspacewereactratherthanact
unfocusedourawarenessisscattered
distracted/multitaskingdisengagedconfused
The"zone"isamuchhigherproductivitystate
4.9
AdminRecord-keepingisextremelyhelpful
Andsometimesrequired,e.g.,billablehoursTrackinghelps!(alotcanbeautomated)
TimeEffort(andsenseofeffort)Whatwasdone(andwhy,bywhome)MoodDiscussionsanddecisions
Someisbetterthannone;enoughisbetterstill;thereistoomuch
4.10
ProgrammerCredosThree Virtues
AccordingtoLarryWall(1),theoriginalauthorofthePerlprogramminglanguage,therearethreegreatvirtuesofaprogrammer;Laziness,ImpatienceandHubris
1. Laziness: The quality that makes you go to great effortto reduce overall energy expenditure. It makes you writelabor-saving programs that other people will find usefuland document what you wrote so you don't have toanswer so many questions about it.
2. Impatience: The anger you feel when the computer isbeing lazy. This makes you write programs that don'tjust react to your needs, but actually anticipate them. Orat least pretend to.
3. Hubris: The quality that makes you write (andmaintain) programs that other people won't want to saybad things about.
(1)Quotedfrom"ProgrammingPerl",2ndEdition,O'Reilly&Associates,1996
5.1
Debugging
—GraceHopper'sBugReport
5.2
DefectsAgainRecall:
A defect in a software system is a quality level (for somequality)thatisnotacceptable.
Wefocuson defectsprimarily
ThoughrobustnessisalsokeyMorestability,i.e.,doesn'tcrash
functionalCorrectness
5.3
WhatIsDebugging?Debugging is the modification of code to remove (ormitigate)correctnessdefects.
Wedon'tcountmissingfunctionalitydefectsDebuggingstartsafterapurporteddetection
Input:aresultoftestingorabugreportWeallowmitigation
NotproperlyfixingthebugButenoughsoit'slessdamagingMuststillinvolvecodemodification
Otherworkaroundsdon'tcount!
5.4
FunctionalLandscape(Enhanced)
5.5
DebugCycleInput:Anindicationofadefect
Stabilise—MakereliabilyrepeatableIsolate(orlocalise)—TothesmallestunitExplain—What'swrongwiththecodeRepair—ReplacethebrokencodeTest—Verifythefix
CheckforRegressionsMaskedbugsNearbybugs
5.6
IndicationAnindicationofadefectisatangiblerecordofabehaviourcontrarytothe(explicitorimplicit)functionalspecificationinadesignatedsituation.
Keyparts:Situation
Preferably,sufficientlydescribedforreplicationExpectedBehaviourWitnessedBehaviour
Typicallywithsomeexplanationwhyit'swrongOftenveryvague
5.7
Indication?Oftenveryvague
Programcrashedsometimeduringthistest
Actually,onlyon !OpenOfficeonUbuntuwon'tprint
Tuesdays
FromJohnRegehr," "ClassicBugReports
5.8
StabiliseBugsareoftenverysituationdependent
Preciseinput+stateOS,hardwareSequenceofactionsLengthofoperating
Astabilsedbugisreliablyrepeatablepreferrablywithminimalsufficientconditions
5.9
Isolate(Localise)Bugsareoftenverylocal
SingleLOCSingleroutineParticularclass
Theydon'thavetobe!Communicationpointsarevulnerable
Adefectisisolatedifyouhaveidentifiedtheminimumsubsystemnecessarytoexhibitthedefectforantriggerinputandsitutation
5.10
Explain&RepairExplainingthebug
YoucanarticulatethemechanismofthebugYourbugtheory
YoucanmanipulatethebugTriggeroravoiditProducevariantsPredictitsbehaviourFixit
RepairingthebugModifyingthecodesothedefectiseliminatedMaynotbepossible!
5.11
TestPostfix
YouneedtoverifyYourtheoryYour*executionofthefix
YouneedtoguardagainstUnintendedconsequences!
"New"bugsariseBugsinthefix
ThefixisincompleteThefixtriggersaregression
Maskedbugs
5.12
CheckNearbyBugscomeinfamilies
SimilarmistakesYoudiditonce,youmighthavedoneittwicePersistentmisunderstandingwithmultiplemanifestations
ClusteredmistakesSomebugshidden
AcrashconcealsmuchSomeroutinesarebroken
Lotsofdebt!Abugisapredictorofmorebugs!
5.13
BugReportsToWONTFIXSometimes,afixisn'tgoingtohappen
ThebugistoosmallOrinsignificantOrambiguous
ThebugistoobigItwouldchangetoomuchbehavior
WhichsomepeoplerelyonOtherdebtincreasestherisk
Thebutistoohard
6.2
ResourcesSize
RunningspaceAtalllevesl
PersistenceandtransmissionCode
TimeResponsevs.thourghput
Instantvs.OverallWall/CPUTime/Instructions
6.3
WhatIsOptimisation?Optmisiationisatransformationofcodeintosufficientlyfunctionally equivalent code that has "better" resourceutilisation.
"Sufficientlyfunctionallyequivalent"Userobservable/desirablebehaviourispreservedUptosomepointItmaybespecialisedtoacertainparticularscenario
ResourceutilisationTypeandPatternmustbespecified
6.4
Where?
6.5
TuningTrade-OffsTimeforSpace(andthereverse)PerformanceforReadability(andthereverse)
AndothercomprehensionqualitiesNotalwaysatradeoffforalgorithmicimprovements
OrfatremovalPerformanceforCorrectnessPerformanceforCost
6.6
TuningAlternativesBuyMoreandFasterHardwareUsetheOptimiserBettercompilers/frameworks/librariesInputmanipulation
"It'sslowwhenIdothis""Don'tdothat!"
6.7
TuningSafetyTuningisrisky
Evenoptimisationcanberisky!It'seasytomakecodefast
BymakingitincorrectIt'seasytomodifythecodealot
AndnotimproveperformancemuchOrmakeworse
6.8
TuningAs(Performance)DebuggingInput:Anindicationofaperformancedefect
Stabilise—MakereliabilyrepeatableIsolate(orlocalise)—Tothesmallestunit
USEAPROFILER!TESTCASESARECRITICALExplain—What'swrongwiththecode
Repair—Replacethe"slow"codeTest—Verifytheimprovements
CheckforSufficiency(Wasthatenough?)Trade-offs(e.g.,spaceconsumption)(Correctness)Bugs
8.1
Boehm'sEvidence
FollowingslidesderivedfromMakingSoftware,Chapter10
8.2
ReadingPapersThesepapersarechallenging!
EvenmassagedabitforthepractitionerLotsoftechnicaljargonandtechniquesSummarizingavastliteratureChallengingstatsandpresentations
Don'tpanic!ThesearereadandrereadFirstreadingshouldfocusonkeypointsLaterreadingsshouldfocusontheevidence
8.3
TheRoleOfArchitectureKeychallenge(Boehm,MakingSoftware,Chp10)
Howmuchshouldyouinvestinarchitecture?Analogytobuilding
Wepaythearchitect10%ofthecostofabuildingWeshouldspend10%oftheprojectbudgetonarchitecture
Isthisenough?Howwouldweknow?
Note:statisticallygeneralconclusionsmaynotapplyinyourcase!
8.4
Bohem'sResearchQuestions:"Byhowmuchshouldyouexpectthecostof
makingchangesorfixingdefectstoincreaseasafunctionofprojecttimeorproductsize?"
"Howmuchshouldyouinvestinearlyarchitectingandevidence-basedprojectreviewsbeforeproceedingintoproductdevelopment?"
8.5
EconomiesCommoditymanufacturingexhibitseconomiesofscale
Making1chipmaybemuchmoreexpensivethan1000Theunitcostdiminishesasthenumberofunitsincreases
Softwareend-unitcostsare(canbe)zeroCheaptomakeacopy!
Installation&configurationmaynotbeSofocusonlinesofcodeorbitsoffunctionality
SoftwareexhibitsdiseconomiesofscaleTheunitcostrisesasthenumberofunitsincreases
Potentiallyexponential!Pgs166-167esp.useful
8.6
CostRatiosWhat'stheratioofcosttofixearlyvs.late?
1970s1inrequirementsto≈100postdelivery
19811:100forlargecodebases
But1:5forsmall(2,000-5,000LOC)1996survey
(70-125):12000s
Someevidenceofreductionfrom1:100to1:20Orevenflat(for1millionlinecodebase)
8.7
CostRatios(ForCoursework!)What'stheratioofcosttofixearlyvs.late?
Thinkofyourcoursework!Beforedeployment(akasubmission)
SmallfixesarecheapEsp.inthecurrencyofthecourse,i.e.,points
Afterdeployment(akasubmission)Even"small"fixesareexpensive(orimpossible)
Courseworkbuildsoverthesemester!Soproblemscanbuildup
8.8
TwoStrategiesAvoidlatebugsMakefixinglatebugscheaperFailuretodobothkillstheproject
FailuretodoonemaybemitigatedbytheotherAllouractivitiesshouldaimforthis
Thuswewantarchitecturesthatprecludesomebugsconfinetheeffectsofallbugs
8.9
TwoArchitectureBreakers(Pg376)"20%ofthedefectsaccountfor80%ofthecosts"
"these20%are...duetoinadequatearchitecture..."Twosortsofcosts
DirectcostsOpportunitycosts
TwoexamplebigfailurestheOSarchitecturedidn'tsupportfail-overwhenprocessorsfailed
lackedakeyfunctionalityassumingallmessagesareshort
thusborkingon1millioncharactermessages
8.10
TradeOffsMoreupfrontarch
Costs!Runsriskofoverruns
SincelesstimeforeverythingelsePotentially,gettingarchright
Reducesreworktime
Note,changingrequirementscankillgettingitright
8.11
SweetSpots
8.12
Summary(Pg403)"...thegreatertheproject'ssize,criticality,andstability,the greater the need for validated architecture feasibilityevidence.
"veryverysmalllow-criticalityprojectswithhighvolatility,thearchitectingeffortsmakelittledifference"
Note:Thereareothercostdrivers;checktheassumptions!
9.2
MargaretHamilton
NexttotheApolloprojectnavigationsoftwarecode
9.3
AbstractDataTypes(1)Adatatypeis
asetofvalueswithassociatedoperations
Anabstractdatatypeisadatatypecharacterisedentirelybytheoperations
independentofimplementationdetailsAconcretedatatype(orimplementationofanADT)is
arepresentationofasetofvalueswithparticularimplementationsoftheoperations
9.4
ADTExample:Lists
9.5
ADTExample:IntegersIntegers
AbstractValues:All(orfinatesubsetsof)integersOperations:+,-,*,/,<,=,>
Concrete(representation)32bit2s-complementor64bit2s-complementorarraysorfloats(Javascript)or
9.6
ADTExample:DatabasesCRUD
Create-Read-Update-DeleteVeryabstract!
SomeMappings(from ):Operation SQL HTTP DDSCreate / writeRead(Retrieve) read/takeUpdate(Modify) / writeDelete(Destroy) dispose
Wikipedia
INSERT PUT POSTSELECT GETUPDATE PUT PATCHDELETE DELETE
9.7
WhyADTs?Separateinterfaceandimplementation
TheclientonlyneedstothinkabouttheinterfaceUptoapoint!Abstractionsleak
SimplerandclearerFocusesonthesemanticsofthetype
Tellsyouthecriticalfunctionality
9.8
UnitsOfCreationA code unit is a syntactically complete(able) chunk of aprogramthatenactssomebehavior.
LineofCodeBlockorcontrolstructureRoutines/procedures/functions/methods/operationsClasses/modulesPackages/modules
Individualroutinesandclassesarewhatgetunittested