Yourfrustrationjustkeepsrising, andthebugthatyouthoughtwouldbe a quickfiveminutefixrightbeforelunchisnowrunningonhourfourandyouhavenointentionofeating.
I thinkthattheperceptionthatwehaveofwhatcleancodeisandhowit's writteniskindofflawed, and I thinkthatthatperceptionissomethingthatcanscareoff a lotofbeginnersthat, thatisthestandardthattheircodeismeanttobeheldto.
Whentherealityofprogrammingisoftenfarmoremessy, whereyouprettymuchwrite a lineofcode, andallof a suddenanerroroccursintheoldpartofthecodebasethatsomeonereallyshouldtake a lookatandrefactor.
Butyou'reunder a timeconstraint, soyoudon't havethetimetoactuallydothat.
Soyoujustwrite a quickfix.
Andallof a sudden, thattinyfeaturethatyouweregoingtoimplementhasbecome a completemess.
That's usuallyhowitworksunlessyou'reworkingon a projectwhereyou'vedoneallofitbefore, whereyouknowexactlywhattowritenextandwhereitshouldgo, Whichissometimesthecaseifyou'veworkedsomewhereforagesdoingthesamething.
Butifyou'redoinganythingthat's newtoyouorthatyouhaven't done 1000 timesbefore, thenthestoryis a lotdifferent, andtheremaybecodereviewersand a signeddocumentsandwhateverelsethat's createdtohelpyouwritecleancode.
Youdidwritethetestwiththatbasic.
Oh, beforeheshippeditright.
You'renotlyingtome, right?
Soifwetake a lookatyourcode, theunittestwillbethere, then.
Yeah.
No, exactly.
Soyoudidwritethetest.
Maybe.
I thinkmaybeyoushouldtalktoJoebecausehe's becausehe's inyou.
Butinmostcosit's notonlyyourjobtowrite a cleanpieceofcode, it's actuallyyouandyourcodereviewersjobtoproduce a cleanpieceofcode.
There's also a tradeoffbetweenwritingcleancodeandbeingefficient, thinkingthateverypieceofcodethatyouwritehastobeperfectionitselfisneitherrealisticnorwhatanyoneexpectsfromyou.
I wouldsaythatingeneral, tryingtowriteperfectcodeissuperinefficient, becauseinordertodothat, youneedtospendsomuchtimethinkingthrougheverythingthatyoudothatyoubecomeveryslowthewaythatyoushouldusuallyworkorthinkaboutyourworkisrightrefactorandreview.
Andthenfinally, onceyou'vespent a bitoftimerefactoringandessentiallycleaningupyourcodebecausesenditinforcodereviewafterit's beenreviewed, I wouldsaythatyouhavesuccessfullywritten a prettysolidpieceofcodewhilealsomaintaining a reasonablelevelofefficiency.
What I'm mostlytryingtosayisthattheperceptionthatwehavethatcleancodeisequaltoperfectcodeisusuallyfarfromtrue.
Andthenonceyou'veworkedonthatfor a while, youcansenditinforcodereview, andthenthecodereviewercancheckoutyourcodeandyourmessandgiveyousomeadviceandtipsforhowtorefactoritfurtherandmakeitevencleaner.
Andthenonceallthatisdone, that's when I wouldsayyouhave a cleanpieceofcode.
Gotonorawalkerdotnetslashholdenanduse a couponcodeHoldentogetnorthlookingforfreeandtoalsoget a 32% discountonthepremiumversion, eventhoughitmaybeinefficienttowritecleancodefromthestart.
Insteadofwritingthreenestedfourloops, itmaybeworthspending a coupleminutestryingtofigureoutifyoucouldcomeupwithorGoogle a recursivefunctionthatcouldremovesomeofthefourloops.
I dothinkthatmostofusknowwhatwe'rebeingsloppyandjustcan't bebothereddoingthingstherightway, eventhoughweknowhowtodoittherightway.
Andthat's what I wouldsuggest, spendingthatextraamountoftime, doingittherightwayfromthestart.
Butontheotherhand, let's saythatwe'reimplementing a newfeature.
Andthat's what I wouldsay, thatitdoesn't makesensetospendseveralhourstryingtoresearchthemostoptimalwayofimplementingthatfeature.
Instead, I wouldsuggestjustimplementingthefeatureinthebestwaythatyoucan, andthenspendingsometimerefactoringthatandmakingyourimplementation a lotmoreelegant, becausethenatleastyoumadesomethingthatworks.
A trendytermrightnowisactionbias, whichmeansthatyou'rebiasedtowardstakingactionoverinaction, and I thinkthatthatishowyoushouldbethinking.
Ifyoukeepthatinmindasyouwritecodethan I thinkyou'llbewelloff.
Sowritingcleancodeinthewaythatweperceivecleancodeis a myth.
Usuallycleancodeistheproductofseveralpeopleworkingon a projecttogetherandnotjustoneindividual.
Soifyou'refeelinglike I believe a lotofpeoplearefeelinglike a crappyprogrammerbecauseyourcodeusuallylookslike a giantmess, thenyou'renotalone.
Andespeciallyifyouhaven't workedat a companybefore, writingsufferprofessionallywheretheyhavetherightsystemsinplaceforit.
I wouldsaythatformostofus, ourownpersonalprojectsaresupermessy, andthey'rekindoflikethecloserthatwehave, wherewejustshoveallourshiftintoandtrytoshutitandhopethatnoonelooksinthere.
I'm goingtogettothat, I promise.
That's itforthisone.
I hopeyouenjoyedit.
Andbeforeyougo, I justwanttomentionthat I'vecreatedsomethingcalledCleanCodeFriday, whichisveryfittingwiththisvideo, whichis a shortemailthat I sentoutonceeveryweek.
SoeveryFridaythatcontains a fewofthemostinterestingthingsthat I foundthroughoutthatweek, andthatwouldbethingslikebooks.
I'm readingarticlesofredproductivitytips, codingtipsandtricksandreallyjustanythingthat I thinkyoumightenjoy.
Butthen I wasworried, cause I'm like, Oh, myGod, I'm, like, sounproductiveAnd I'm gettingwallowinginthislikeguilt.
Um, I wasraisedCatholic.
So, likethisCatholicguiltoflikenot, youknow, I'm notworkinghardenough.
Thiscompany's notsuccessful, and I foundmydaughteratitandjust, like, totallynothelpful, butandso I'm like, OhmyGod, Oh, mybrokenlike, Am I notcapableofworkinghard?
What's wrongwithme?
Um, butthen I wouldlikeonegoodnews.
I startedworkingonthislikepokerbahtthatstarted, anditplayedwithrealmoneylike a likegotpastthesecurityonthepokerclientthisJohnsix.
So I figureouthowtomakeallthatworkandthenwatchkindofmyFrankensteinmomentasthethoughtcomestolifeandstartsplayingonrielpokertables.
Andsothisideayoucan't pokerboxwasliketotallyfalse, butandbut I waspossessed.
ItwaslikeWereyouwinning?
WasthebodywasFrankenstein's monsterwinning?
Well, I mean, frankly, Frankensteinwaslike, notnottoosmartinthebeginning.
So, like, there's youit, that's thething, startsmovingthemouseandplayingcar, playingthehand, thengetsconfusedbecauseithas.
There's some, like, obscuremultiplesplitpotorsomethingthat I justdidn't writethecodetohandlethatsituation.