Você está na página 1de 10

Chapter2Meaningfulnames

useintentionrevealingnames
avoiddisinformation
beawareofnamethatvaryinsmallways
makemeaningfuldistinctions
distinguishnamesinsuchawaythatthereaderknowswhatthedifference
offers
usepronounceablenames
usesearchablenames
usesingleletternameONLYforlocalvariablesinsideshortmethods
thelengthofanameshouldcorrespondtothesizeofitsscope
avoidencodings
avoidmentalmapping
clarityisking
classnames
nounornounphrases
shouldnotbeaverb
methodnames
verborverbphrase
useJavaBeanstandards
whenconstructorsareoverloadedusestaticfactorymethodswithnamesthat
describethearguments
makeconstructorsprivate
dontbecute
chooseclarityoverentertainmentvalue
saywhatyoumean
meanwhatyousay
pickonewordperconcept
consistentlexiconisagreatboon
dontpun
avoidusingthesameworkfortwopurposes
usesolutiondomainnames
useproblemdomainnames
addmeaningfulcontext
dontaddgratuitouscontext
Chapter3Functions
small
theyshouldbesmallerthansmall
blocksandindenting
if,else,whilestatementsshouldbeonelinelong
theyshouldbeafunctioncall
theindentlevelshouldnotbegreaterthanoneortwo
doonething
theyshoulddoitwell
theyshoulddoitonly
functionsthatdoonethingcannotbereasonablydividedintosections
onelevelofabstractionperfunction
usedescriptivenames
youknowyouareworkingoncleancodewheneachroutineturnsoutpretty
muchwhatyouexpected
alongdescriptivenameisbetterthanashortenigmaticname
functionarguments
idealnumberis0
threeormoreargumentsshouldbeavoidedifpossible
havenosideeffects
outputarguments
ifyourfunctionmustchangethestateofsomething,haveitchangethestate
ofitsowningobject
commandqueryseparation
functionsshould
dosomething
OR
answersomething
preferexceptionstoreturningerrorcodes
dontrepeatyourself
Chapter4Comments
commentsdonotmakeupforbadcode
explainyourselfincode
Chapter5Formatting
sticktoaformattingstyle
Chapter6ObjectsandDataStructures
data/objectantisymmetry
proceduralcodemakesithardtoaddnewdatastructuresbecauseallthe
functionsmustchange
OOcodemakesithardtoaddnewfunctionsbecausealltheclassesmust
change
lawofDemeter
amethodfofaclassCshouldonlycallthemethodsofthese
C
anobjectcreatedbyf
anobjectpassedasanargumenttof
anobjectheldinaninstancevariableofC
Chapter7ErrorHandling
useexceptionsratherthanreturncodes
startcodewithtrycatchfinally
useuncheckedexceptions
dontreturnnull
dontpassnullintomethods
Chapter8Boundaries
usethirdpartycode
learningtestsverifythatthethirdpartypackagesweareusingworkthewaywe
expectthemto
Chapter9UnitTests
threelawsoftestdrivendevelopment
youmaynotwriteproductioncodeuntilyouhavewrittenafailingtestunit
youmaynotwritemoreofatestunitthanissufficienttofail,andnot
compilingisfailing
youmaynotwritemoreproductioncodethanissufficienttopassthe
currentlyfailingtests
havingdirtytestsisworsethannotests
testcodeisjustasimportantasproductioncode
thenumberassertspertestshouldbeminimized
FIRST
fast
independent
repeatable
selfvalidating
booleanoutput
timely
Chapter10Classes
classesshouldbesmall
nameoftheclassshoulddescribewhatresponsibilitiesitfulfills
singleresponsibilityprinciple
aclassshouldhaveonlyonereasontochange
cohesion
classesshouldhaveasmallnumberofinstancevariables
isolatingfromchange
Chapter11Systems
separateconstructingasystemfromusingit
softwaresystemsshouldseparatethestartupprocess,whentheapplication
objectsareconstructedandthedependenciesarewiredtogether,fromthe
runtimelogicthattakesoverafterstartup
factories
dependencyinjection
Chapter12Emergence
simpledesign
runsallthetests
writingtestsleadstobetterdesign
containsnoduplication
expressestheintentoftheprogrammer
minimizesthenumberofclassesandmethods
Chapter13Concurrency
mythsandmisconceptions
concurrencyalwaysimprovedperformance
designdoesnotchangewhenwritingconcurrentprograms
understandingconcurrencyissuesisnotimportantwhenworkingwitha
container
concurrentsoftware
concurrencyincurssomeoverhead
correctconcurrencyiscomplex
concurrencybugsarentusuallyrepeatable
concurrencyoftenrequiresafundamentalchangeindesignstrategy
defenseprinciples
singleresponsibility
concurrencyrelatedcodehasitsowncycleofdevelopment,change
andtuning
concurrencyrelatedcodehasitsownchallenges,whicharedifferent
fromandoftenmoredifficultthannonconcurrencyrelatedcode
keepyourconcurrencyrelatedcodeseparatefromothercode
limitthescopeofdata
takedataencapsulationtoheart,severelylimittheaccessofanydata
thatmaybeshared
usecopiesofdata
threadsshouldbeasindependentaspossible
knowyourlibrary
threadsafecollections
executionmodels
boundresource
mutualexclusion
starvation
onethreadorgroupisprohibitedfromproceedingforanexcesively
longtime
deadlock
twoormorethreadswaitingforeachothertofinish
livelock
threadstryingtodowork,butfindinganotheroneintheway
learnthebasicalgorithmsandunderstandtheirsolution
consumerproducer
diningphilosophers
readerswriters
bewaredependenciesbetweensynchronizedmethods
avoidusingmorethanonemethodonasharedobject
clientbasedlocking
serverbasedlocking
adaptedserver
keepsynchronizedsectionssmall
shutdown
thinkaboutshutdownandgetitworkingearly
itsgonnatakelongerthanyouexpect
testing
writeteststhathavethepotentialtoexposeproblemsandrunthemfrequently
dontignorefailures
getyournonthreadedcodeworkingfirst
makeyourthreadedcodepluggable
makeyourthreadedcodetunable
runwithmorethreadsthanprocessors
runondifferentplatforms
tryandforcefailures
Chapter17SmellsandHeuristics
comments
inappropriateinformation
obsolete
redundant
poorlywritten
ifyoutaketimetowritecommentswritethemwell
commentedout
deleteit
environment
buildrequiredmorethanonestep
abuildshouldbeasingletrivialoperation
testsrequiremorethanonestep
onebutton=test
functions
toomanyarguments
outputarguments
donthavefunctionschangearguments
usefunctionsonobjectsifyouhavetochangetheobject
flagarguments
deadfunction
general
multiplelanguagesinonesourcefile
obviousbehaviourisnotimplemented
incorrectbehaviourattheboundaries
dontrelyonyourintuition
overriddensafeties
duplication
duplication=missedopportunityforabstraction
once,andonlyonce
findandeliminateduplicationwhereveryoucan
codeatthewronglevelofabstraction
baseclassesdependingontheirderrivates
toomuchinformation
fewermethods=better
hideyourdata
hideyourutilityfunctions
dontcreateclasseswithlotsofmethodsorlotsofinstancevariables
concentrateonkeepinginterfacesverytightandverysmall
deadcode
codethatisntexecuted
deleteitfromthesystem
verticalseparation
localvariablesshouldbedeclaredjustabovetheirfirstuse
privatefunctionsshouldbedefinedjustbelowtheirfirstusage
inconsistency
doallthingsinasimilarway
clutter
variablesneverused
functionsnevercalled
commentsthataddnoinformation
artificialcoupling
featureenvy
selectorarguments
argumentsthatselectthebehaviourofthefunction
bettertohavemanyfunctions
obscuredindent
misplacedresponsibility
inappropriatestatic
makesureyoudontwantyourstaticfunctiontobehave
polymorphically
useexplanatoryvariables
morearebetterthanfewer
functionsnamesshouldsaywhattheydo
understandthealgorithm
makelogicaldependenciespsychical
preferpolymorphismtoif/elseorswitchstatements
followstandardconventions
replacemagicnumberswithnamedconstants
beprecise
structureoverconvention
encapsulateconditionals
avoidnegativeconditionals
functionsshoulddoonething
hiddentemporalcouplings
dontbearbitrary
encapsulateboundaryconditions
functionsshoulddescendonlyonelevelofabstraction
keepconfigurabledataathighlevels
avoidtransitivenavigation
Java
avoidlongimportlistsbyusingwildcards
dontinheritconstants
constantsvsenums
names
choosedescriptivenames
choosenamesattheappropriatelevelofabstraction
usestandardnomenclaturewherepossible
unambiguousnames
uselongnamesforlongscopes
avoidencoding
namesshoulddescribesideeffects
tests
insufficienttests
useacoveragetool
dontskiptrivialtests
anignoredtestisaquestionaboutambiguity
testboundaryconditions
exhaustivelytestnearbugs
patternsoffailurearerevealing
testcoveragepatternscanberevealing
testsshouldbefast

Você também pode gostar