You are on page 1of 6

3/18/2017 ThreeAttitudesthatLeadtoMaintainableCode

March7,2017 by:BrianVanderwal 8Comments

ThreeAttitudesthatLeadtoMaintainableCode

ABOUTTHISAUTHOR
Whenwritingcode,therearemanyspecificprinciplesthataimtomakeyourcodemore
maintainable:DRY,thesingleresponsibilityprinciple,theLawofDemeter,theopen/closed
principle,etc.Thesearegreatprinciplestofollow,butitcanbedifficulttokeepallofthem
inyourheadatonce.Ivefounditsofteneasiertokeepafewbroaderideasinmind.

ChangeYourPerspective
AsImwritingcode,Itrytoconstantlyreviewitfromtheperspectiveofanewdeveloper
joiningtheproject.Iimaginewhatitwouldbeliketoreadthiscodeforthefirsttime.

WouldIunderstandtheoverallflow?HaveIusedtermsinawaythatisconsistentwiththe
restoftheproject?IfIhadtosearchforthisthingwithoutknowingwhatitiscalled,wouldI
beabletofinditquickly?

AtAtomicObject,weoftendopairprogramming,whichisagreatwaytoimmediatelyget
answerstothesequestionsfromsomeonewhoisnotyou.

Oneofthebestwaystoensurethatyourcodeismaintainablebysomeoneelse(oryour
futureself)istomakeitselfdocumenting.Idontmeanthatyoushouldaddcommentsall
overtheplace.Commentsshouldbereservedfortherarebitsofcodethatareinfluencedby
factorsbeyondthecodeitself(forexample,acustomerrequirementorabitofhistorical
context).Butrather,putseriousthoughtintothenamingofeverything.Afterall,

Thereareonlytwohardthingsincomputerscience:cacheinvalidationand
namingthings.
PhilKarlton

NeatnessMatters
https://spin.atomicobject.com/2017/03/07/attitudesmaintainablecode/?utm_source=hackernewsletter&utm_medium=email&utm_term=code 1/6
3/18/2017 ThreeAttitudesthatLeadtoMaintainableCode

Haveyoueverseenanobfuscatedcodecontest?Yes,itispossibletowritecodethatdoes
somethingusefulandyetiscompletelyunreadableitself.Thosecontestsarejustforfun,of
course,butitcanbeeasytoslipintobadformattinghabits(orapathytowarditaltogether).
Codethatispleasingtolookatalsotendstobeeasiertoscanquickly.

Compilersareactuallyprettygoodatparsingandoptimizingcode,whilehumansarenot.
Takepityonthepunyhumans,andwritecodeforthemfirst,withthemachineasonlya
secondaryconcern.

Preferclarityovercleverness.Readabilitycountsforfarmorethansmalloptimizations.
BrianKernighansaiditbest:

Everyoneknowsthatdebuggingistwiceashardaswritingaprograminthefirst
place.Soifyoureascleverasyoucanbewhenyouwriteit,howwillyouever
debugit?

AvoidSpecialCases
Fewthingswillwreckyourcodefasterthanspecialcases.Thesearethethingsthattakeyour
nicelyconstructedmachineandpokeholesinafewofitstubes.Itmightseemeasierinthe
shorttermtojustslapsomeducttapeonitandtrytoignoreit,butifyoudontfixtheroot
issue,itsjustgoingtospringaleakagainlaterondowntheroad.

Thismightlooklikeaquickanddirtyfixtogetsomethingworkingintimeforarelease.It
mightlooklikereusingacomponentforsomethingitdefinitelywasntdesignedtodo.Its
thosethingsthatmostlyworkbuthaveafewnastyjaggededges.

Itcanbetemptingtosimplyusesomethingthatgetsyoumostofthewaythere,butittakes
disciplinetorefactorthatthingsoitgetsyouallofthewaythere.Itsworthit!

inDevelopmentPractices

https://spin.atomicobject.com/2017/03/07/attitudesmaintainablecode/?utm_source=hackernewsletter&utm_medium=email&utm_term=code 2/6
3/18/2017 ThreeAttitudesthatLeadtoMaintainableCode

8Comments

michaelrice

March8,2017

Greatarticle,thanksfortakingthetimetowriteitup.Im
curiouswhatyourexperienceiswhendiscussingthese
pointswithourdevelopersorclientshowdoyougo
aboutit?

Reply

Brian BrianVanderwal

March8,2017
Vanderwal

Internally,weoftenhaveopendiscussionsonall
sortsofdevelopmentrelatedtopics.Ithinkthis
comesnaturallyfromourcompanyvalues
(https://atomicobject.com/culture),oneofwhichis
TeachandLearn.Inmyexperience,nobodyknows
everythingandeverybodyknowssomething(thatis,
everyonehassomethingtoteach,andeveryonehas
somethingtolearn).

AnotheroneofourvaluesisActTransparently,
whichdrivesourinteractionswithclients.Inmy
(relativelyshort)experience,thesequestionsofcode
maintainabilitydontcomeuptoooften.Butwhen
theydo,weexplainwhyitsnecessaryandmake
suretheclientisinagreementbeforemovingon.

https://spin.atomicobject.com/2017/03/07/attitudesmaintainablecode/?utm_source=hackernewsletter&utm_medium=email&utm_term=code 3/6
3/18/2017 ThreeAttitudesthatLeadtoMaintainableCode

Reply

Matt

March8,2017

Writetestsandwritecodethatiseasytowritetestsfor.
Testsarebuiltinexamplesonhowthecodeisintended
toworkwhichcanoftenbemorehelpfulthanaptnaming
schemesorcommentsanddocumentation.Writing
functionsthatcaneasilybetestedalsoleadstomore
modular,lesscomplicatedarchitecturebecauseitforces
developerstobreakprocessingdownintoreasonably
sizedandscopedpieces.
Thispracticeisenforcibleandpracticalwheretheideaof
pretendyouveneverseenthiscodebeforeanddecide
ifitiseasytounderstandisnot.

Reply

tonykwong

March8,2017

Neatness,really?Codebeautifiershavebeenaround
sincethe60s,andallmodernIDEmakethisprettymuch
aoneclickoperation.

Reply

Prasadmhatre

March9,2017

https://spin.atomicobject.com/2017/03/07/attitudesmaintainablecode/?utm_source=hackernewsletter&utm_medium=email&utm_term=code 4/6
3/18/2017 ThreeAttitudesthatLeadtoMaintainableCode

4thpointistakeyourtimetocode.AsRomewasnot
buildinaday,similarlyyoucantwriteagood
maintainablecodewithdeadline.Whenyouhave
deadlinethenitsobviousthatthereishighpossibilityof
shittycode.

Soaskyourboss,clienttogiveyouampleoftimeto
writeacode.Becauseifyouarewritingacodewith
deadlineyouaremakingafraud,yourarecheating
yourself.Youaregoingtohaveimpostersyndrome.

Reply

GijsOvervliet

March9,2017

ThisisexactlywhatImtryingtoteachmyteam.
However,ourprojectmanagerandarchitectaretelling
methatIgotoofarwiththis.Theysayittakesmoretime
thanneeded,andthatweneedtofocusondelivered
functionality.Howwouldyoudealwiththissituation?

Reply

TomRutgers

March9,2017

Thewholepointofhavingaprojectmanageror
architectistoevaluatewhatcanbedoneinacertain
timeforacertainbudget.Itisnothowever,telling
individualteammembershowtheyshouldworkor
https://spin.atomicobject.com/2017/03/07/attitudesmaintainablecode/?utm_source=hackernewsletter&utm_medium=email&utm_term=code 5/6
3/18/2017 ThreeAttitudesthatLeadtoMaintainableCode

whatisneededtodeliveraproduct.Trytoexplain
themwhyyourwayofworkingisarequirementof
gettingthejobdonewell.

Ontheotherhand,maintainablecodeisapretty
basicrequirement.Ifyouwriteyourcodeinaway
yourfellowdevscanunderstandwhatitdoes,and
dosoinaconsistentmatter,chancesareyoure
doingjustfine.Itsnotanartformoranything..

Reply

DaveStagner

March9,2017

Theresaslightbuginthefirstsection.Thetwohard
thingincomputersciencearecacheinvalidation,naming
things,andoffbyoneerrors.

Reply

https://spin.atomicobject.com/2017/03/07/attitudesmaintainablecode/?utm_source=hackernewsletter&utm_medium=email&utm_term=code 6/6

You might also like