Sothere's a pictureoftheboardandfolksmightbuildtoseeitunderneaththechatwithvaryingease.
Sure, weenhance.
Yeah, that's enhance a littletoomuchenhancementwayGoesoit's It's verysimilarto, and I haven't playedthismyselflooktoodeeplyintoit.
Butit's a versionofpool, essentiallywithwhatlookedlikecheckerpieces, wherethere's a sortof a Q piecethatyougetknockingattheveryendofthequeenpiece, sotospeak.
Andtheappthatwillbelookingatissortof a CLIversionofthis.
UNDERSCOREequalsMaineisPython's wayofsayinglike, If I amrunningthispipeonfiletryingtoexecuteit, thisisthecodethatshouldrun, anditlookslikeitdoessomeinitialsetupandthendownonline 89 itactuallycalled.
Sothisactuallyinsideofthis I thinkBrianhasanopinionhere.
Itdoesseemlikeit's perhaps a littlebitlessconventionaltobeputting a lotoflogicandunderscoreunderscorenameequalsMaineandthenrunthrough a wholebunchoflogicandthencallthemainfunction.
Itseemslike a lotofinformationaboutinitializingthepartsarecheckingthearguments, loadingtheend.
Allright, Sojusttobeclear, inmostcases, whatwecouldevendoifyoudowanttohave a mainfunction, isjustliterallyinthelastlineofyourcode.
JustcallmainitselftherebykickingoffthewholeprocessofrunningthisfiletheadditionalpresenceofthisconditionherethatBrianisdescribingreallyonlysolves a problemformoresophisticatedprogramswhereyouindeedmightwanttoimportthemifyou'remaking a libraryorpythonpackageormoduleofyourown.
ButhavingthatifnameEagle's maingreatfor a testcases, Doyoumentionedthatalready?
No, I don't thinkwecan.
Doyoumeanbytestcases, likehavingIfyouweretohavethetestfor a modulewithin a modelsohecouldrunitandtestitscorrectness, youcouldhaveallofthosetestcasesbewithinmainwithinthatmoduleandthenrunthemthatwayinthefile.
Inthefunctionwithin.
Ifyouweretotestthismoduleandhave a setoftestcasesthat, forexample, saythiscamewith a bunchoffunctions.
Youcouldimportitinsomeassomelibrary.
Oryouwanttotestthismoduleforcorrectnessonitsown.
Yougetexecutethismodulebyitselfandwithinitsmainfunctionwouldexecute a setoftestcase.
There's justsortof a sloppinessthattheriskofreadingintoittoomuchjustjustHey, ifyou'renotevengettingthebasicsrightlikethat, maybethecodeitselfisn't a strongisthatshouldbe.
And I thinkyouwanttobeputtingyourbestfootforwardhere, too.
So I wouldkeepthissimpleandmorepythonIQandjusthave a deafmainopenprintclothesprint.
Andthat's it.
I doseethathe's changedcommentingstyleshere, butthisisprobably a goodthing.
Doyoumindspeakingtothisconvention?
Yeah, Thesetriplequotationmarksthatyoumighthaveseenbeforearewhat's called a docstringinpython, andthisisoftenconventionalfordocumentingthebehaviorof a functionordocumentingthebehaviorof a classlike a playerorKarenborder, whichwemighttake a lookatlater.
Andsoconventionallyunderneathmain, you'llhavetriplequotationmarksandthen a descriptionofwhatitisthatthisfunctiondoes.
Andoftentimes, you'llalsoseethisasanopportunitytotalkaboutwhatthetypesoftheargumentsshouldbe, whatthereturntypeofthefunctionisifthefunctionisreturningsomethingandjusthelpstodocumentthebehaviorofthefunction, andthen a wholebunchoftoolsthathavetheabilitytoactuallyreadthatDocstringandusethedocStringinordertoinformsomeonewho's usingthefunction, howitisthatthefunctionactuallyworks.
DoesitsdockstringsortofUnderneaththefunctionsignature, we'reasking a languagelikeJava, itwouldbeplacedabovethefunction.
Yeah, I canseethemotivationbecauseitmeanswhenyou'reparsingthefunction, thedoctoringisactuallypartofthefunctionandnotjustrandomly a pendantaboveit, butitfeels a littleweirdgiventheseconventionstohereandjustbe a littleneater.
Givemesomewhitespacebeforeyournextcommentso I couldjustunderstandthatthisisrelatingtothecodebelow.
ForDjangoflasks, recommendedmethodisnolongertouse a mainfunction.
Youshouldactuallyberunning a programcalledFlasktoinitiateexecutionoftheserver, butyouwillseethatinolderversionsofflasks.
And I thinktherewasoneotherquestionyoubeenscrollingupjust a littlebetter.
Yeah, canwegobackinthequestions?
Oh, andbadIgniteasks.
Whynot a separatetestfile?
So I thinkHolden's cominearlier.
Youcouldabsolutelyfactoroutanytestto a separatefile, However, if I werewriting a prettysmalllibrary, forinstance, see a safetyzonelibraryjustkeepeverythingtogetherbecauseitkeepsthingssimple.
So I couldimaginemaybeyoumakeoutcomeandin, um, forinstance, whereitcanonlybeoneof a fixednumberofpossiblevalues, andsoyoucanguaranteethatwillalwaysbeoneortheother.
So I mightimaginemaybejustlikehaving a variablecalledlikewhothewinneris.
Andthewinnerissettoeithertheplayerwhowantitorifthereisnowinnerthanitcouldbesenttonone, whichisjust a defaultpythonvaluerepresentingtheabsenceof a value.
And I couldimagineifresultsoutwinnerisequaltoNanaandthattellsyouthatthegameis a drawbecausethereisnowinner.
Soyoucanimagine a numberofpossiblewaysyoucouldgoabouttryingtoarchitectthat.
Ifyouweretouse a variable, uhcallednotoutcome, butcalledone, youcouldsaythatresult, youcouldcheckwiththeresultthatoneequalsequalstrueorfitequalsfalseorifitissomeotherstate.
Itcouldbenone.
Whichgivesyou 1/3 optionaswell.
I thinkit's inthespiritofwhatyou'resayingnow.
Youmentionedhimbefore, and I don't thinkwecandothatinPythonperse.
There's a youcondonetheirclasses, youcanextendit.
I guessthat's probablymorecomplicated.
Andinfact I don't eventhinkthisneedstobeturnerynowthat I lookatanythinginteresting, binary, justtrueorfalse.
Well, I think, Well, I don't knowenoughaboutthegame, but I imaginethegamecouldbewon a draworstillinprogress, whichiswhythey'renotmightnotbeanoutcomeyet.
I thinkwecoulddosomethinglike, uh, let's say, Howcouldwedothisone?
Wecouldhave a variablecalledoneandsaiditequaltoanyoldvalue, whetherit's oneorevenone, forinstance.
Andthenwecouldhavedraw, equals, drawjust a stringrepresentationofit.
Andtheninmyothercode, correctmeif I'm wrong, I coulddownhereif I scrolldowntowhereweleftoffattheverybottom, I couldsaysomethinglike, ifresultthoughtoutcomeequalsequalsKarenBoard 0.1 actuallycheckasthoughitis a constant.
I thinkbothwouldworkactual, umhimself, probablymoredimensionaltousethesame.
But I thinkyoucanstillgetawaywithKarenBoardhere 0.1 Soit's a littlesloppy, butatleastinthisway, you'renotcomparingagainst a hardcodedstringthatyou'llchangeforgrammaticalpurposesorifyouinternationalizethegame.
Andinpython, it's a bitcuriousbecauseifyouwanttoinitialize a classorspecificallyanobjectofthatclassclasseslikecalledlike a blueprintormoldoutofwhichyoucanmakemultiplecopiesofit.
Oneormore.
Karenboards.
YouseethisfunctioninPython?
Quitecommonly.
Doyouwanttospeaktowhatthisis?
Thisisbeingusedfor?
Yeah.
Sothisiswhatwewouldcalllike a classconstructor.
Basically, thisis a functionthatwillrunthatwillcreatewhatwecallaninstanceof a caromboard.
Sothisclassisdefining a blueprintofwhatitmeanstocreateonesuchboard, andthat's gonnasigninagain.
Wait a minute.
Function, accident.
AndwhenwesayinMaine, Dupuy, youmayrecallweusedCaromBoardandinCapital C, Capital B andtheninparentheses.
Wepassedinthecoinsandtheplayersthatwasimplicitlycallingthisinnitmethodtosay, Let's create a newboard.
I seewehavesomekindofdictionaryhereofcointypesthatwecouldseeifwedivedintothatconfigfile.
Mostlikelytoseewhatwe'revalidatinghere.
Youlook, you'relooking a sconce.
Yeah, ifcointypesisactually a dictionary.
I don't knowwhetheritis.
I'm assumingitisbecausewe'recallingdotkeys.
And I actuallythinkthedarkiesisprobablynotnecessaryherethatifyouwanttocheckifcoinisthekeyinside, thedictionarycouldcommitthedonkeys.
That's truebecauseKeysisgoingtoreturn a listofthekeysinthedictionary, whichisjust a redundantoperation.
Ifyoucanalreadydoitbywayoftheendoperator, that's a goodpoint, Allright, sowe'recheckingsometypesjusttomakesurethattheuserispassedintherightvariables, itwouldseem, Yeah, it's worth a wholesomeandthatit's a littlebitmore.
Thiswillwork.
Youcanusethetype, functionandfuntogetthetypeof a particularvariableonthecheckofplayersis, infact, a list.
It's a littlebitmoreplatonicandmorerecommendedinpythontouseactually a differentfunction, whichexactlyisinstance, Um, methodeveryfunctionandthat's goingtoe.
Yeah, syntaxlikethatwillsay, ifplayersisaninstanceoflist, whichiseffectivelydoing a verysimilarthing, it's morerecommendedfor a coupleofreasons, butoneistodealwiththepossibilityofclassesthatareinheritingfromotherclasses.
Soyoucouldimagine, forinstance, if I hadtofind a classcalledbook, forexample, and I hadtofind a newclasscalledhardcoverbookthatheis a typeofbook, like a specifictypeofbook.
Andnow I have a hardcoverbook, and I wanttochecktoseeifitisinfact, a book.
If I justchecked.
Ifthetypeisequaltobook, it's notgoingtomatchup.
Butif I checkifit's aninstanceof a bookthat I'llget a resultthenext, solongstoryshort, it's usuallypreferabletousetheseinstanceoverjustcheckingiftypeisequaltosomething, actually, backuptotheline 36 here.
I'm guessingif, uh, they'recurrentlycheckingtoseeifcoinisin a, youknow, a sortofcollection.
Andwewerejustcoincidentallytalkingaboutthisoveremailwithsomeofthestaffbecause I wastryingtodesignsomethinginvolvingtypesjustthisweekend.
And, youknow, I actuallypreferthisonfurtherthoughtcauseone.
Itwouldbeweird.
A presumptionistosubclasslistclass, andclearlythat's a primitivetypebuiltintothelanguage.
Youcanuseitaspartofyourownclass, butitshouldreallybetuckedinIsaninstanceVariable, I thinknotjustextendedondhe, too, when I'm writingcode, especiallyformaincodelikethis.
Like I don't wantyoutobeabletosubclasssomethingnecessarilylikeThat's not a feature I wantprovide.
I don't knowifthat's gonnabreakmyowncode.
Andso I wouldn't leastincaseslikethisif I knowitshouldbe a list.
I wouldarguethatitshouldbe a list, nomatterwhat, but I doagreethatthecodewouldbreakespeciallydownhere.
Forinstance, ifweenhanceplayertohaveitsownsubtypesthen I'm gonnahavetogobackanddothisso I couldbeconvincedthatwaythat's hereiswell.
AndEllenoneasked, Whynotuse a trycatchblockhereinreferencetothevariousraiseerrors.
Youcould, becausethepresumptionis, I think, lateronthatitwillbetakenforgrantedthatplayersis a list.
Thatplayeris a player, andjustbadthingswillhappenifyoutrytotreatthoseastheyinwaysthatthey'renot.
Thisis a downside.
I thinkofpythoninanylooselytypedlanguageandlanguageslikeJavaand C and C PlusPlus.
I actuallythinkthisisannoyingfeatureof a lotoflanguages, likePython, whereyouhavetoorshoulddothiskindofcheckingifyoureallywant a rightdefensivecodeoranargumentcouldbemade.
Butitwouldbenicetojustdefinethisintheconstructorbecauseofallthefunctions I meantocareabouttheconstructors, kindoflike a mainentrypointandgivingthemthere.
Um, ifyoumaybewanttowriteitinto a thingorwhatnot, butsothis, I presume, isfromwhat 50 iflookslikepartof a Webprogrammingproblem.
SoifthisisusingsequelAlchemy, whichisthelibraryviawhichyoucanexecutesequelCurry's on a databaseDeviExecuteprobablyreturnedsomekindofclassthatspecificsequel.
Alchemy.
Youcanprobablyifyou'restoringthatin a variablecalledbookjustcastorconvertbookto a dictionary, and I wannamakingthisupjustoffthetopofmyhead.
ThestolenWell, I'm justgonnaarbitrarilyaddedThioSamArtsprogramHeather, I thinkyoucouldprobablydosomethinglikethistoconvertwhateverthatstructureisto a bookthatshouldmostexperience.
Typescriptis a typedversionofJavascript, anditjustmakesitreallyeasytowriteJavaScriptcodethatisfreeofpotentialtypeareasbecauseitis a stronglytypedversionofdramascript.
Heardgoodthings.
YoushouldtakeitAllright, Well, let's let's moveonshortly, I think, toanotherproject, butoverall, I thinkwe'reseeing a goodamountofcommenting.
There's stillsomeroomforimprovement.
I thinkweseesomeprettycleancode, butsomeinconsistencieswithcommentingcapitalizationonwithsinglequotesversusdoublequotesandthensomeactualdesignopportunitiesforimprovement, thingslikestatemanagementandactuallyrepresentingthingsandanthemainfunctionaswell.
Yeah, thegamestatebeingsortof a stringto I thinkitgoesbacktoourpriorBrian's priorpointaboutusingan e number, atleastyourpointaboutusingphonynumbersusingstaticvariables.
I thinkwecouldhavedonesomethinglikenotyetbeganinallcaps, and I would'veprobablybetterdesignministeringto.
Niceaside, I'm justkindofthinkingaheadhere.
Thisiskindofinterestingbecause I'm seeing a doublenegative, sotospeak.
Ifitisnotthecasethatinputturnsequalsequalsnone.
I thinkwhatyoucoulddoisactuallydistillthat a littlemorepythonycl e asjustthis, becausethatwillreturntrueifitisanythingotherthannone, solongaswedon't needtodistinguishbetweennineandVeraCorrect.
Assumingthat's somekindofoffinputturns, I don't knowwhatdatatypethat's gonnapay.
I don't eithersoitcouldjustbethatitwasoptional.
Soifit's anythingotherthanwhatisthedefaultvalue?
Actually, lookslikeit's supposedtobe a addict.
Yes, thatshouldwork.
Fine.
Okay.
I'llbringusovertothe, um, otherscreen.
Youwanttosay a couplehellosaswegetreadyforyournextstoryaboutthat, Bytheway, Uh, 23 please.
Sowehave a drawdotCS 50 i EthicalesoherewejustdrawthatCSetcdotio.
Whatyou'rewelcometousetouseitinclassisfordrawingontouchscreensandshowyforthoseunfamiliar, especiallyoutsidethe U.
S.
Whatistictactoe?
Yeah, ticktacktoeis a gamewherebywe'regonnahave a threebythreegridthat's basicallyjust a ninesquaresarrangedin a threebythreegradedtheirtwoplayers, a player X and a player.
Oh, andthealternatetakingturnsdrawingeitheran X oran O, whicheveroneoftheminoneoftheninesquares.
Andthegoalistogetthreein a row.
Yougetthreein a rowin a verticalline, getthreein a rowin a horizontalline, oryoucangetthreein a rowalong a diagonalon.
Sothegoalistotryandgetthreein a row, andthefunnythingiswithtictactoe.
Andsoherewe'reimporting a functioncalledMake D temper.
Make a temporarydirectory, whichiswherewe'regonnastorethatsessioninformation, andthenthere's someconfiguration.
Andthisisactuallyproblematicinsomecontextbecauseifyourunflaskdebuggingmodeandthereforeitrestartsaftereveryrequest, I believeyouwillget a differenttemporarydirectory.
We'verunintothisproblembefore, rememberbefore.
So I thinkthisisactuallyfineinproductioncodewheretheserversrunningfor a longtime.
Butifyou'reusingflasksdebuggingmodewhereit's supposedtorestartitselfaftereveryrequestjusttogiveyou a cleanslate, I believeyouwillendupseeingyoursessionfilesendupindifferencefoldersonthefilesystem, andthereforeyoumightbelosingsomeofyourstate.
Sojust f.
Y I youcanprobablyomitthis, andwhatwehavestartedtodoforclasspurposesisletflaskusethedefault, whichiscorecalledflaskunderscoresession.