Actually, we'readjustingourviewhere a littlebitinrealtimesothatwecanactuallyseenotonlythecommentsniceandwide, butalsoourfollowershere.
Sosayyed 055 aswell.
ThankyouverymuchforthefollowLitato G and D Manda.
Oh, andwehave a few, actually.
AndseeMissSweden.
Hugh, thankyouverymuchforthefollows.
Wereallyshouldjustsayhellotopeople's numbers.
Yeah, maybeitmightbe a littleeasiertopronounceyou, butYeah.
Sowehave a bunchofawesomeprojecttoday.
AndalsothankstoBrianforjoiningusforthefirsttime.
Absolutely.
Andmanymoregoingforward.
Whydon't we?
Whydon't wediverightintoourfirstproductroll?
Sure.
Soifyou'renewtothestream, weviaColtonsolicitedsomecodethatfolkshadworkedonotherforpersonalprojectsorotherwiseby a Googleform a fewweeksago.
Andwegot a numberofsubmissionspython, html, c andotherlanguages.
AndsowhatBrianand I thoughtwewoulddotodaywithColtonhereisjustprovidesomefeedback, muchlikeourteachingfellowshereoncampusWould, basedonthedesignthing, efficiency, thequalityofthecodethatwe'reseeingandcertainlytakeallthiswith a grainofsalt.
Sowehavethemainfunctionthere, Soitseemslikewellupatthetopbeforethemainfunctionthere, includingStandardOut H, whichyoumightbefamiliarwith a fewchickens.
50.
Weusethatin a lotofseeprogramsandthenthere, includingpicksmapdoteach, whichlookslikeit's probablytheheaderfileforthelibrarythatNoahhascreatedhere, andthat's gonnagivehimaccesstosomeofthetypesthatwe'regoingtoseeinjust a moment, probablyinsomeofthefunctions.
Meanwhile, soinsidethemainfunctionwe'redefining a somethingoftypepicksWMAPimage.
Sonotanimagethat's builtindeceased's probablyhavesomesortofdefinitionthatwilltake a lookatjustthemomenton.
We'refighting a pointertoitcalledImage, andthenwe'rerunning a functionthatlookslikehe's definedcalledpicksWMAPImageopen.
I presumethisisgonnabesomefilepathtotheimagethatwe'regoingtotryandopen, andwe'regonnastoresomesortofdataaboutitinsideofwhat's pointedtobythePointerimage.
So I'm a littlenervousandwewouldn't knowreallyuntilwediveintothecode.
Butbecauseimagesdeclaredis a pointer.
Asperthisasteriskrighthere, a pointerto a picksmappedimage.
I'm a littlenervousthatweretheninthesamplecode, gettingtheaddressofthepointerunlessthisimageisactuallygonnado a lotofourmemoryallocationforusandthenchangewhatisatwhatpointchangedthecontentsofthatpointeritselfasopposedtowhatit's pointingit.
Butwe'llsee.
Yeah, that's a goodplace.
Isappointedto a pointer, whichfeels a little a littleworrisome.
Butmaybeit's correct.
Yeah, allright.
Andthendownhere, Doyouwanttofightonforwhat's goingon a littlefurtherwiththeseprints?
Imagegetheight, eachofwhichistakingthatpointer a pointerto a pixelimage.
Andpresumablythosefunctionsareabletotakethatimageandsomehowwhereinsidethedatastoredwithintheimagegetaccesstothewidthandtheheightofthatimageandmaybe a couplepointsyear.
Ifyou'vebeentakingCS 50 youmightknowthatinrecentyearsweactuallyintroducestudents 2% I forintegerwellpercent D fordecimalintoJuriesalmostidentical, anditisinfact, withthecontextofprintdepth.
It's a littledifferentifyou'reusingscanningforactuallygettinguserinput.
Butthat's otherwise.
Thesamethingispercent I and I thinkit's worthnoting.
Forthoseofyouwhohaveheardaboutorfamiliarwithobjectorientedprogramming, thisis a convention.
Allright, sojust a fewmorelineshere, let's seeifwecangleanwhat's goingonhere.
Maybe, Allright, soitlookslikewe'redefining a variableof a newtype.
Wesawthetypepicksthatimagebefore.
Andnowwehavepicksmatte r B R g b, whichwasprobablyred, greenblue, standinginplacefor a singlepixelthathas a bunchofcolorvalues.
Andnowwe'vegotthisfunctionpicksWMAPimageGetpixel.
Lookslikeittakesfourarguments.
Oneistheimagethatwe'retryingtogetthepixelfrom, andthenwehavetwonumbersand I'm assumingthoseairlikean X and Y coordinateofwhereintheimagewewanttotryandextract a pixelfrom.
Wesaiditequaltoanendtothenchecktoseeifthatresultisnegativeone, becausethatwouldmeanthatthecoordinatessuppliedornotintheboundsoftheimageonbasedonthenextthreelines, itlookslikepixelisprobably a structureofsomekindbecausewe'reusingthisdotnotationtosaypixelhas a wholebunchofpropertieswithinit a red, greenandblueproperty.
Andthedotnotationandseeishowyouaccess a memberofinstructandgetaccesstoyou.
Justtheredvalueofthepixel, thegreenvalueoftheexcellentvaluethatexultlookslikethoseairintegersbecausewe'reprintingthemoutusingpercent D.
Um, andthenwe'recreating a newpixelagain.
Creating a newpicsmapareRGB, andthistime, ratherthanreadingitfromtheimageweknowit's instruct.
Weknowithasmemberscalledred, greenandblue, sowecouldalsocreate a pixeljustbydefiningwhatwewantthered, greenandbluevaluestobeforourselves.
Wewanttodecidewhatwewant.
ThepixelscolortobeThishas a redvalueof 50 greenof 1 50 blueof 200 whichisprobablygonnabe a greenishbluecolor, I wouldguess.
Andthenwhereitlookslikewe'resettingthepixel, we'recalling a functioncalledpicksWMAPimagesetpixel, whichfalls a similarformattogetpixel.
Youcanpassin a verylargedatastructuretoanotherfunctionisinput, butyoudoitbywayof a singlevalue.
It's a dress, soit's notwastetimecopyinganentirestructureyoucanimaginethesamethingappliesto, like, pickpicks, MattImagegetwithtwoimages, pointer.
Inthiscase, youwillbethesameexactthing.
Nowyouwannabecareful.
TherearetechniquesthatwekindofsortofshowingCS 50 whereyoucandeclarevariablesorparameterstofunctionsisbeingconstantconstantbecausethedangerinpassingandsomethingas a dresslikethisisthatthatmeansthefunctionyou'recallingtheoreticallycouldchangethecontents.
Soyoutrytoatleastput a barrierofdefensebetweenyouandsomeaccidentalcode.
Itwastheconstant, a fairlyrecentscythingHasitbeenwithseasince, Liketheseven?
Andsoitprobablymakessensetostartbytaking a lookatpicksnappedouteach, I'd say, Justseesortofwhat's insideofthislibrary, andthenwecantake a lookattheimplementationandseehowitactuallygoesaboutachievingthosethings.
I likethatidea.
I mean, we'retalkingtoseeSwiftyabouttheideaofabstraction, whichiskindofwhat a headerfileis.
Ifyouhave a compileravailabletoyou, Weaken, simplytestthisout.
So I'vegoneaheadandopenedupsandbox.
Let's see a 50 dotio.
I'm gonnagoaheadandcreate a filecalledTestdotSee, forinstance.
Andnowmygotoprogram, Anytime I'm doingsomethinginseaislike, oh, gimmeandincludesstandardioandthenintomainavoidandthendosomethinglikeprint F.
Butwe'lljustcomebacktothat.
But I thinkthegistofwhat I'm tryingtodohereis I justwanttodeclare a typeofmyownandlet's justtypedeclaresomethinglikeitendstobecalledDavid's type, andthiswouldbethatthework.
That's fine.
That's fine.
Youknow, Whatwewanttodoiswewant a typedupthatstruckbeforewedefinedthestructurewastofind a structurelike a coordinatepointorsomethingliketypedobstructpointandjusttypedoutatthepoint, whichistheequivalentofwhatnoisdoingandthendownbelowdefinedstruckpointandsay a struckpointhasanindexinnit?
Entwined, forinstance, sounfamiliartypetoughingsomethingisjust a wayoftakingonetypein, givingitanothernametoit, andsothatmakesiteasytorefertosomething, usuallyby a simplername.
Frankly, if I wanttoreusethisdatatypeandif I have a dotheaderheaderfileatallFrankly, I reallywantedtobepartoftheheaderfilebecause I wanttomakesurethatthisheaderfileworksindependentevenofmy C code.
Whenitcomestomytypesdeclaration.
Right.
IfpicksupimagehasmembersthatwewanttomakesureIfyou'reincludingthisheaderfilethatyouknowwhatthemembersof a picksmapimageare, whichiswhattheydosuccessfullywithpicks, mapRGBtellusintheheaderfilethattheRGBpixelhas a redand a greenthan a bluecomponenttothem.
Sonamely, wehaveinto 30 tounderscore t theunderscore t justmeansit's a typeandthetypeisgoingtobe a 32 bitintegerwhere 32 bitinsecureismostofoursystemsbydefault.
Sothisisjust a wayofbeingabsolutelysure, tellingthesystemthatratherthanjustuseyourdefaultvalueofintowhichmightbein 32 todefinitelyuse a 32 bitinteger, whichisimportantifyou'redoingsomethinglikereadingandwritingimagesbecauseyoureallycareabouttherebeing a certainnumberofpixelsin a certainplace, becausethespecificationsforwhattheimagefileformatmeansprobablyprescribesthenumberofbitsthatcertainvaluesneedtobeliketheArcticandthevalues.
I thinkit's reasonablycommonthio, unfortunatelythat I think I think, folks, I think, knowwhatdidanawesomejobofwriting.
Greatcleancoachisinverygreatidentifyyournames, but I thinknomatterhowgoodyouridentifiernames, and I thinkitwasevenAndresthisbefore, wedon't necessarilyknowthewhyorthatwemightbeabletoinferthathow.
Butthewhy I thinkisimportantnothingthatnecessarilycomesacrossYeah, despitehowcleanyourcommentingoryoursymbolsare.
I don't recalloffhandsothatanytimeyouseesomething, beginwith a hashtagagain.
See, that's whatwewouldcall a preprocessordirective.
Sowhenyoucompile a C programmingundergoes a numberofdifferentsteps, ofwhichtheveryfirststepbeforetheactualcompilationiscalledpreprocessingonDad.
It's interesting.
SothisIt's verycommonifyouhave a largerprogramthatmultiplefilesmightincludethesameheaderfile, andsofaraseachofthemdependonit.
Soitlookslikewhatwe'reseeingbothforthefirsttime.
Hashfragmentonesliterallyisjust a hinttothecompiler, assumingitsupportsit, thatitshouldonlycompilethisfileonce.
Itshouldnotcopyandpasteitscontentseffectivelyeverytimeyouseeincludeleadpickpicksmappedout H includepicks, mapdot h andsoforthandmultiplefire.
Kindofsimilartolikethehashifanddeaf.
Indeed.
Soyoumighthaveseenthisinsomeofthecity's files.
If I openupthesandboxhere, justhave a littlescratchpad.
Youmightseesomethinglike, uh, whatwesay.
Ifend f fu, thenwesaydeaffu.
Thenyouputyourcodeandthenwhatisit?
AndNBSevidence.
And, uh, andif I'm notdead, I'm notpresent.
Seeifdeath I actuallydon't rememberourownOh, andifandifandifandsointhisway, tooIt's kindof a hackwherebyiffuisnotdefinedand I thinkyoudothepoundsignOh, yes, ofcourse.
Yeah, AndactuallyseeAndrestimedinwith a similaranswertowhatpregnantonceis.
And I think I'vebeentypingtoomuchpython.
Letmeactuallycorrectmyself.
Itshouldbehashed.
Fine.
Nothalfdeaf.
I wasaccidentallydefiningfightonfunctionthere.
Okay, Otherthoughtsthatjumpoutatyouhere.
It's storing a widthand a height, andit's alsostoring a maximumcolorvalue, whichisinterestingbecause I rememberintheheaderfiletherewasalso a functionfor, like, getmaximumcolorvaluestheirstoryoutthere, too.
Butyouhavecyclesdespairthesedays, and I thinkit's muchbetterpracticetocodedefensively.
Otherthoughtsthatjumpoutatyouhere, um, taking a lookatpicksWMAPimageopennowandseeingthat, Okay, itdoesindeed.
Take a pointer, toe a pointer.
SothisisoneofthequestionsthatwehadearlierintheoriginalexamplecodeofAllright, wedefined a pointerto a picksupimage, andthenwe'repassing a pointtoitastheargument, andsoherewouldprobablybe a placewhere I wouldagainliketoseesomedocumentationofhowitisthatthisactuallyworks.
Butitseemslike, Okay, ifthefilepaththatwepassinisnoby a line 52 therethatwe'retakingthepointertothepicsWMAPimageandsettingthatequaltozeroornoandreturning.
Butthatbehavioratleast I haven't seenitdocumentedanywhereyetondhe.
Whetheritwasin a commentheresomewhereelsemightbehelpful.
Yeah.
I mean, what I presumeishappeningisthatthere's gonnabememorybeingallocatedinheresomehowthat's actuallystoringsomevalueatthatpoint, right?
Whichiswhy, if I keepscrollingandscrollingscrollingokay, thesecommentsAllright, soweappreciatethecommentshere, butatsomepoint, theyneedtobeattachedtotheactualcode.
Seemstobeassigningtoimage, reallyknowwhichiswhat's happeninghere, eventhoughhe's notdoingitsymbolically, becauseifimageis a pointerto a pointerthanstarimageitselfis a pointer, soyoucouldjustwritethisasnull.
Andfrankly, youprobablyshould.
Itleavestomakecleartotheuserthatthisisnotthenumberzero, butit's indeed a nopointer.
Thisjustbecame, I think, thecurlybraceinTexasthatdefininganarraythatcontainsonlyzeroelementsisthatthewayofdefininganarraythathasmultiplethingswiththesamevalueelementsthatarezerothatarezero.
Yeah.
Sothisis a fancywayofjustclearingoutallofthememory.
Itseemsjustbytaking a guessatitthatwhereandyou'vegotanarrayofwhat's calledpixels, buteachreallythreeelementsinthispixelsarerighttogetherlooklikethey'recombiningtoformonepixel.
Butdefinitelythecalculationofwheretheredpixelsshouldgois a calculationyoucoulddoonceinthegreenpixelisjustoneoffsetfromnotinthebluepixelstooffsetfromthatpoint.