Prototyping & Refactoring C# Code For Google Sheets
April 21, 2024
• 371 views
I'm playing with some code in C# for google APIs - come hang out!
View Transcript
all right I'm trying this again this is probably the third or fourth or fifth attempt and I'm trying to see why my applications are crashing but this is so far the best attempt I'm just checking a couple things here still yeah I restarted my computer because I tried streaming a few times and it would get like three seconds in something like that and then I would look over and everything's frozen and um not really sure what's up with that so um cool I'm going to be doing some programming today so I figured I might as well try streaming a little bit of it I am working on some stuff to help organize uh some content for myself so for a little bit of background the the stuff I do outside of work like do a lot of content creation and uh something in particular that
takes up a lot of time that's it's like simple stuff but it's just like keeping organized with content and short form videos are one type of content that takes up uh a lot of time for me so what I'm trying to do is just write some code to help uh automatically organize things into spreadsheets um I do a lot of stuff on on Google Drive uh just because I wanted it backed up I don't want to have to worry about it and uh for collaborations and stuff it's a little bit easier for me to just have things in one spot so with all that said I'm going to jump over to visual studio here um let's see should be this one here cool so that should be all my code on the screen I do have chat pulled up on the side I realized that
I'm using restream and they actually have a dedicated like chat window I can check out so that's pretty cool um I haven't used it before but it seems like it's telling me all the details that I think I need to know so that's cool and yeah so let's just dive into it feel free to ask stuff in the chat it's a little bit out of my peripheral but maybe what I can do is pull it over that's a lot of chat isn't it let me make that a little smaller I'm going to put it behind the window that's in the top right I guess it's going to be hidden that's a terrible idea okay well I'm still learning how to stream so that's okay I'll keep it over here and I'll try to watch if stuff pops up it's in my left peripheral vision though
so okay what I'm working on though is let me back up a little bit here in some of this code the Google sheet service class that I'm trying to use is kind of crappy to work with so I've been finding so I'm just I have all this code in one file this is how I end up prototyping stuff before I pull it all out but the sheet service so I'll just jump into it the API that this class has is pretty crappy in my opinion at least for how I want to work with stuff I find that it's not very obvious um so they have a whole bunch of stuff on here oh it's not going to show me all the source that's okay um but like navigating let's kind of rewind a little bit looking up files and folders and stuff in Google Drive
is just a pain in the butt I think if you're used to like you know working with the normal file system on your computer computer you want to give it a file path and like we know that folders don't have extensions but files do but in Google Drive it's just kind of like not really like that everything is I don't know how it's stored all behind the scenes but everything has an identifier so we can conceptualize the you know the file folder hierarchy uh we know that files are of certain types but they do a lot of stuff with like inferring the file type from the mime data so for example when you have a file with MIM data like that it's a JPEG or that it could be a document like a PDF or something like it uses that to infer the data like
the type of the file so it doesn't need an extension and you can as a result have files in Google Drive with like no extensions but it still knows that it's like an Excel sheet kind of thing so it's just a bit weird to work with and I think one of the challenges that comes up from that is that you have things like these constructs that we're used to like I want to go open a file at this path and you can't just do that in Google Google Drive so if I uh let me find the code for it sorry there's too much this is what happens when you start prototyping a little bit too far and you need to start pulling some stuff out but um I want to jump over to this code here one sec see it's already all over I already
pulled some copying stuff out what I'm doing in this video by the way is I want to get to showing you how I'm coming up with some helper methods that I want to reuse this is one of them I've actually made a video about this already and a blog post but this was a helper method that I created so that um you can see it's an extension method so you have the this keyword on this parameter and the static at the front but uh the way that this works is that it makes it seem like the drive service lets you look up file and files and folders their paths so for me this is how I want to be able to go do that kind of stuff so I wrote this helper method but now one of the things that I want to do is
with Google Sheets so if I Collapse this um trying to figure out where I left off I'm pretty rattled from all the the starting and stopping of the stream so things are a little bit disorganized here but it's it's essentially this code here so what I'm doing is I wrote this code that will go up update a spreadsheet row and in my opinion this is like a little bit too it's not obvious what this code is doing I feel and because of that if I want to go call I have to go write another spot in my my my code that I want to go update a spreadsheet row it's just not obvious like I would go copy and paste this and start having all this kind of crappy code scattered around so I am trying to pull it into a class that I'm creating
that's just called a basic sheet and a basic sheet starts to make assumptions about the spreadsheet that we're working with because spreadsheets can be you know I know they're just a whole bunch of cells but um whether or not you have like disjoint data in there like a basic spreadsheet to me is you have a fixed set of columns you have data in the rows and you don't have like disjoint data where you have a bunch of gaps between other Colum so you can start making assumptions that it's really just like a basic table and that's the idea here so I wrote some helper methods already but what I want to do is start pulling that code that we were just looking at I've already lost it but I think it was right here I want to start pulling this code into a helper method
so I just copied all of that I'm going to go into here I don't know what I want to call it yet um something like it's like co-pilot is trying to predict what I want to do uh I want to call it something like update row contiguous a sync and I'm going to explain this in just a second but the idea is that the data that we have like I want to update in my spreadsheet a given row and I know based on my assumptions right it's basically a single row in a table I don't have to worry about all these disjoint cells and stuff it's literally bunch of columns with defined headers and then each row is like an entry in it right so cancellation token try to make sure I always got these put on and I'm just going to copy and paste
that data into here so this data is all not applicable anymore but let's see what we got to work with so I have the sheets service so I got that here we have the spreadsheet ID so get rid of that now we need to know like um there's a couple things that are hardcoded in here right now so this is the sheet name and if I back up a little bit for why this is needed here the API that exists already through Google's API that they provide the way that you would go update a given uh sheet right you need to go back to their main class so this sheet service it has something called a spreadsheets resource then you ask for the values like so it's another property on it and then you can ask to go call an update but what's weird about
this to me is that you can like they have a mix of what feels like objectoriented and not so I can go get I can go find and have a reference to a spreadsheet and I can't call update on that spreadsheet I can go find and get a reference to a sheet within the spreadsheet right like the different sort of pages that you have in there but I can't call update I have to go back and like basically use this this root class here and to me it's just kind of awkward because if I'm passing around an object that's a sheet that I can go work with right now I can do some operations with it but not all and it just feels very clunky so uh what I was doing was passing around this B basic sheet object that I had that I created
that had some nice helper methods on it but as soon as I wanted to go do an update I couldn't so I wanted to go like if we scroll back up this basic sheet class now not only it started with just this sheet being passed in now it needs a reference to its parent spreadsheet because this doesn't have like a back pointer to this and neither of these have any back pointer to the sheet service so if any update we have to use this thing it just feels very clunky but what I'm doing is putting all of that into this basic sheet class so to create a basic sheet you give it all these things and then it should feel much easier to go use and this isn't like a totally clean API like I'm exposing out those two things again to the outside just
because I don't know yet how I want this all to go look but it's just a starting point Okay so now I've kind of explained why we have to go back to this root part but the the things that we need to be able to pass in I need to know what you want in terms of the values here so the different cell values across the row I need to know what row you want to go update and we have to be careful too because row IDs start at one but the way it works in code is that they are indexed right so if you have an index of zero you actually want that to be Row one right so got to be careful off by one errors biggest uh most common problem in programming right and then we have the name of the the
spreadsheet is or the the sheet within the spreadsheet but we don't need that passed in because we're in a basic sheet class that I've created we already know what that is so if I ask for the sheet oh I made it a property so sheet dot is it just name title come on now there's got to be something oh I think it's in properties title okay um what we're doing is building out this syntax to go address a cell right so it would look something like sheet my goodness cheat name then you use an exclamation mark and then you give it like the the range that you would type into like your into Excel or Google sheet so if you wanted to go from like a 32 over to um whatever h32 right like that would be one row from columns a to H this
is how you'd have to specify it because you need to give it the sheet name because this API if you just look here right we're passing in a spreadsheet ID but it doesn't know what sheet to go update so you have to tell it in this range part so that's what we're building on line 463 here okay so the things that we need passed in are going to be a Target row Index right we don't have that and then I need to give it the values that we want to have passed in so probably how I would do this is like um yeah so Target row index and then what I want to do is something like I read only list of objects just have row data and then here what I'm going to do is just put that doesn't like it why not oh
it doesn't want it to be oh man this is silly I can't give it a readon list it has to be a just I list yeah okay see this seems weird to me because we're basically telling the person that's calling this you need to give me a list that I can mutate which is wrong like I don't personally I don't want to mutate any of the data that you're passing in but the API that they're using here I list is mutable so kind of kind of silly I don't like that but what I could do is make it a read only one passed in and then I could I could uh basically make a new list but that's just like totally Overkill no one wants that for performance reasons so kind of like got to give and take a little bit when you're doing this
stuff but at this point I just want to double check we're passing in the data for the cells we already have access to the spreadsheet ID we have access to the title of the sheet that we want to work with and we needed the target row index passed in but what we don't have this is the part that I was I figured I was going to have to write an algorithm while I was streaming and I wasn't quite ready so this will be fun um and actually this is the kind of thing that I am very bad at so so um it might be kind of cool for you guys to see like I'm uncomfortable doing this kind of stuff and I'm going to be doing it live so to explain um what I need to do is know which uh like letters for the
cells that we want to work with right it's not so complicated so if you I'm missing another piece of data that I'll explain in just a second but if you had say this list of data that was passed in if that was five different elements let's say right if you were starting from the beginning you would want to do sell like let's pretend the target row index is three right you would go A3 B3 C3 D3 I how many did I say um and then E3 right like if it were five things passed in for this row data so I need to be able to increment the letters now in my case I don't want to go into like the double digit letters and stuff like I'm going to I'm not releasing this to the public for other people to consume it's just kind of
like I'm using it um so I'm going to go from A to Z or Z I guess I'm living in the US now I have to say Z so we'll go from A to Z but I probably want the ability to provide an offset so in starting column index thank you co-pilot now I have to go figure out the start and the end value here and and maybe this is actually pretty easy um cuz I can cheat a little bit but we can do something like so I need to do a Char start column letter okay thank you co-pilot for making my life so easy uh I the reason I said I was going to cheat a little bit is because I was going to do some casting and use a character I know the starting character at position zero was to be a right
so if you add zero onto a and cast that to a Char again you're going to get a um and I'm just going to press enter and see if co-pilot can figure out that I want to get the end character now yeah I think that's pretty close um I can probably simplify this a little bit right I don't need that and let's see I just want to double check this because it's it's like an off by one thing I don't know why it has this on here if we had one thing in okay no that makes sense if we had one item in the row data right if we had one item in the row data I don't need to have an end column of B right so that will oops that that minus one is accounting for that if I had two things in
the row data it means that I have to have column A is the start right because we say column uh say the starting index is is zero right so this would be a this would also be a it's the same variable and then if we had two elements in here it would be 2 - 1 so one added on to a would give us B so a would be the starting cell and B would be the ending one so we get two so I think that works and that means that I can put them in here and you're going to start to see how ridiculous this is to go read so I'm going to see about doing a bit of readability refactoring here because uh it's all on one line right but that's kind of kind of crap so to start an easy way is
just to say target range right this is still a terrible line I don't want to look at this it's awful um now what I might do just to Spruce it up a little bit is something like I haven't really played around with this yet so like this might be okay for readability in my opinion um this is awful but like whatever it's uh it's a oneliner you need to have this on here and there's different options I should I should be clear right you don't have to use raw you can do user enter or some of these other things but I'm just using raw for now the point is like this line looks pretty pretty ugly but this is a pretty pretty helpful method now so I think that I'm happy with that now what that means is I can go back to where it
was called right there's a lot of code in here so I have it like I was saying at the beginning of this stream I'm prototyping something right now so I'm just rapidly creating like interfaces and classes dropping them into one file but like I've been doing this for a little bit this morning and I absolutely have to go clean this up so this is the basic sheet Factory that's not what I wanted to see I want to go to the basic sheet oh my my goodness sorry we were just there so I want to go to the video destination and the context again if you're joining the context is that I'm trying to do some some helper code for working with some of my uh my content for social media to to organize videos because I keep track of stuff in spreadsheets and on Google
Drive so this is the code that we were basically refactoring out to go reuse so what I'm going to do is uh we have the sheet passed in and now we can use this awesome and we have a Target row index the column that we want to start at is B right so what index is B that's index one because index zero would be column A now we go to the row data which nope co-pilot you're failing me it's going to be this data here pull that what else do do we need cancellation token and we're done cool I don't really need configure weight false I just uh because I'm not building a UI application but I am in a habit of always doing it just so I don't ever forget and I think if I do that there we go it's a little bit
better um I kind of like doing this though personal preference now could I pull this variable out or this list out right into a a new variable sure I could go do that um I don't really care at this point though this is feeling okay so I'm feeling okay about that what else has to happen here so oh there's another spot reason I started refactoring this in the first place is there was a second spot that I needed to do some updates to and it's not in here so it's not the video destination it's the video source cuz I'm reorganizing videos so I would I was moving the video so that was copied elsewhere now I'm I'm saying hey look I'm done I want to go delete it so I should be able to go delete it that's what all this is going to do
and I can walk through that in just a sec I wanted to paste this stuff in here I don't have the target row index so I'm going to have to find a way to track that but have it at this point in time and this is kind of be uh neat so start it one okay so anyway this code up here if you're curious what this does we like I was saying earlier on this stream you might have just joined as well but uh the way that the drive API works is that we usually cannot just give it a file path we have to be able to refer to things by their IDs that's kind of challenging because I think a lot of the time we're used to thinking about things with file paths right like if you're working on your desktop or laptop computer
you got stuff in a folder you know the path to it but that's not what we have here so um we have to be thinking about that when you're working with Google Drive so I made a helper API that basically allows us to work with file paths because that's how my brain works I don't want to have to readjust my way of thinking to work with an API I'd rather put um a layer in between then I can translate kind of do it once right pay the price and then I can think about it how I like like to think about it so this is an example of where it's not a good API like it would be nice for me to have a delete method like a delete extension method where I can give it a file path and all that it would do
behind the scenes is this kind of thing it would go look for it and then passing the result into here so I mean we could go try doing that actually that might be kind of neat so I'm going to jump this is just an extension method so we could go do let's see and by the way this is the kind of stuff like I'm doing this for my own projects I know that I use Google Sheets a lot and Google Drive a lot for um for Content Creation in particular so this is a bit of me exploring around and playing like if you were doing this kind of stuff at work I would say like if you don't you don't need this don't go waste the time doing it right like there's there's definitely tradeoffs but you don't want to go down a rabbit hole
of just like oh I'm going to go build a you know 50 different apis I'm never going to use but part of this is like I'm creating content I'm I'm trying to practice using some of these so that I can speak about them better and I'm building some stuff for some internal tools that are going to help me so sometimes I'm doing stuff and I'm like I wouldn't necessarily like recommend you always do that but it's just how I do it so um I want to back up a little bit here because I have a bit of a pattern I don't like throwing exceptions so I have my own kind of stuff going on here but do I need to return anything I don't know so one sec let's see it's going to be something like this we actually want this whole same thing might
as well take all of that this is the return type I'm not sure about yet so I'll explain this in just a moment but this is the part that I'm not sure if I have a return type yet but anyway let's see do I have all my stuff matched not all copath return the value sure okay so we have drive service that's going to replace this and technically we want to call this up front so oh co-pilot was about to do it there we go cool is that right I just have to like start typing something and press Tab and it like it knows what I'm trying to do so I don't know if this returns does return a string okay I mean we could I don't know what that string is supposed to be the result object okay so let's return that okay um
and I need a name but let me let me explain what's going on here because this is kind of wild um I mentioned I don't like throwing exceptions and I will do basically whatever I can to write code to try and prevent that but there's going to be situations where I'm interacting with external Services things I don't have control over and even if they say like oh this API can throw these oh my God that's a good yawn I guess I'm still tired even if these API say like I only throw this type of exception like I don't know if that's always true like I have trust issues right so I like to be defensive when I'm coding against Integrations and that's because an exception and some integration should not be critical malfunctioning behavior in my application like almost all of the time I don't
want to say that as a rule I don't like using absolutes right but most of the time if someone else's service is causing a problem like in in the scope or the context of their service I don't want that to destroy what I got going on so instead of trying to pretend like I can catch every single possible exception cuz they could miss one in their documentation what I do is I wrap some of this call-in code in a helper method I've created which is literally it's just a try catch it's just a TR catch behind the scenes and it lets me write this kind of syntax where I can say that I have a method and then I'm going to safely get a result or an exception so it's a try catch but the other thing that it does is that it has uh
I didn't copy it properly but I have a return type which is like the result of trying something so I probably could use a better name I kind of just like started using this to see if it would work and it started working really well for me and then never change the name so the idea that happens here is that when I wrap stuff with a safely call it will try to get me the result or an exception so what do they call them discriminate unions it's like we don't have that in C this is basically like the one of Library uh we don't have that as like a first class thing in C but this is my result type object that I've made and this is a helper method that when I wrap stuff in it basically gives me that functionality for free so
that means if the drive API throws an exception or something and I'm not handling it properly in here so I could still put try catches in here if I need to like a file notot kind of thing or you lose internet connection whatever I could go handle those things gracefully in here but this is my catch all right if something goes wrong then I'm not going to blow up everything else outside of here because I shouldn't need to but I I also name these things kind of like how Microsoft has built-in try methods they usually do like try something and then you output the result but I don't need to Output the result if I'm using this and the other benefit is say you have like a tri parse method right if you have a triar parse method it won't throw exceptions but it also
doesn't tell you why it couldn't parse it just says false so I like these result types because I can use an exception I can say like something went wrong or this is invalid I can put that into an exception object without throwing it so I think it lets me pass more context around I don't know why I'm so tired today I slept in pretty good I I haven't had caffeine yet and if you've been following anything that I've been posting in my Vlogs I'm actually doing like a caffeine not a detox but I have a caffeine problem in general so I am trying to reduce the amount of caffeine I have in a day because it was as high like as high as over a gram of caffeine in a day for for years and like that's obviously problematic so now I'm paying the the
consequences of trying to wean myself off of caffeine so I'm down to 400 milligrams in a day which is still a lot but that's a huge reduction but I'm also trying to not have caffeine rate upon waking and I uh I notice it delete file a sync what did I call this one for path okay I think something like this will do the trick mostly um but what's not done well here is I'll show you some other cool things about this if this works I should be able to do a it doesn't let me that's right I need to pass it in so forget I said that but we need to check this so the source file result success is not true because we have a Boolean flag that lets us check that we would just return it we return the error co-pilot does not
know that but can I also just return this technically I could go to an error anyway but now this is confused okay so let me walk you through What's Happening Here I wrap it in this safely call that means you basically have a try catch and I can get a tried X return type it's just a result type around this whole thing first thing I try to do is go find the file of that path if I find it sorry if I don't find it return an error right it could be file not found whatever but it's not going to crash you can just check to see um what's kind of interesting about this one is like I'm pretty sure the built-in system iio stuff if you say delete a file and it's not there I don't know if it's this file not found or
if it's just like sure like it's not there that's the that's the result you wanted right you wanted the file to not be there like thumbs up you're good to go so I can't recall what the behavior is but that might be something kind of interesting um almost like a TR State thing but anyway once we have it we basically can go call the delete part here and that's really all that there is for this method that means now I have a nice helper method if I go back to here uh I can just say Drive I can give it the path which was here sorry one sec we go cancellation token configure weight coming together right it's a little bit more clean now all of that work just to get this like yeah kind of kind of silly maybe but um I feel like
this is definitely more readable but the reality is like am I ever going to write code again that's going to delete stuff based on a path from Google Drive the answer is I know that I'm going to so I I know that I'm I'm doing a bit of like uh looking ahead to know like that's an investment in some of my code that'll be coming up so I like to pause for this kind of stuff because I I know that I'm working on a person personal hobby project for this right and I like trying to make things relatable for work the the tricky thing is like sometimes I might be doing things or giving advice it's like context dependent actually everything is context dependent so if you see me going and doing this refactoring and I'm kind of setting things up like I want you
to keep in mind that like that could or could not be a good idea where you're working right if you're not sure like I would just say have conversations about it what you don't want to be doing at work is just wasting time on stuff that's not a priority because you might think that there's value in it but if your team your product owner whoever else if they don't find that there's also value in it especially compared to your other priorities like then it's not a good use of your time so if you think that it is you should go communicate that if you're just off going and coding random things cuz you're like oh this is definitely going to be of value like I said if no one else agrees with you it's going to like you're going to feel awkward about it because
you're going to be trying to say afterwards well I did all of this like isn't this helpful and someone might say sure it's helpful but like at what cost now we couldn't go do these other things cuz you were off doing whatever you were doing so I just I urge you because there's a lot of different advice about this that people post about I just urge you to not go Rogue and go make changes I think that's like the most simple way I can put it um if you find like the only like if your mindset is the only way I can get the stuff done that I want is that I have to not tell anyone and go do it I would say well you might be the problem like you might be the problem right you might say well my my product owner
doesn't listen to me my team doesn't listen to me like I don't know like you might need to work on your communication I'm not saying that they don't right I'm not saying that but if you're not getting the Buy in that you think that you need to do stuff therefore you have to go behind their backs you probably want to think about this a little bit more like your communication and collaboration skills may need to come up so that you don't have to go Rogue to go do stuff and I think people don't want to hear that but like I think it's true so now that we've gotten this far we can delete the file that I've now copied I didn't show you the copying part but that gets copied now we can delete the original um I could have used a move but the
reason I didn't want to use a move is that I'm kind of thinking in like a transactional way I need to do a couple of things before I move this file because if this fails anywhere in between I need the file to move back so I'd rather take the overhead of using a bit of extra space you'll copy it an extra API call like okay now go delete it but at least it's a little bit safer for what I'm doing okay so gets copied now we delete the original excellent and then I needed to be able to track some data into the sheet that I'm working in and I think I'm missing some information about that because it's not just the source video data that I have to work with I'm trying to figure out what part of the code I wrote finds that because
I wrote it earlier today but I moved a lot of stuff around I think it's in the video destination part so let me collapse this again I think the video destination finds that Target row and that means okay I I think I know what that means Target row index is found only at this point that means that it's not going to be on the source video data because Source video data ends up getting turned into transact video data which ends up getting return uh converted into result video data so the only thing that can store this this information so far at this point if I continue this pattern is is this so I need to have something else added on to here now that's passed in but it means that this and I don't need these interfaces I actually let me explain that in just
a moment because I think that's a kind of a cool cool one to go over uh video source so when I go to completed its results there we go I'm just going to call it video data to keep it simple that means if I go into this this API is now incorrect I wanted video data let me just get this back to sort of like compiling and then I want to go explain the interfaces because I think it's kind of neat um video data source no it's transact okay and now I can say video data Target row index excellent we did it great success okay save that oh cool there's some comments coming in sorry these are a little delayed in uh in the chat um the one of one of the comments is in a language I can't read so I apologize um cool
let me now another one just rolled in yeah yeah let me answer these hi what can you do if your PO tries tries every solution in the world except for the one you know is the correct answer um okay Sergio so this is It's a communication thing right um so let's let's walk I don't have all the context for your situation right and I need to be careful when we talk through these kinds of things I do this uh even with people that I Mentor at work right every every situation has multiple different perspectives into it so I need to be careful that when you are telling me something I need to acknowledge and also say back to you like this is one side of the story right I'm not trying to be against you I just want to be very clear when we talk
about these types of things that there are different perspectives right you are experiencing one of these in this scenario your product owner and other people on the team will have different perspectives as well so let's call that out just to begin with so that you don't feel like I'm like coming after you or something like that right and I also don't just want to side up with you because that's not going to be helpful I want to try to get to the root of what's Happening Here so what can you do if your PO tries every solution in the world except for the one you know is the correct answer so if I back up from this it sounds like when you're working with your product owner they are approaching solving problems or going down paths like saying hey team let's go in this direction
and it seems to be not things that you are aligned with now what I don't know is like what process is in place to be able to solicit the ideas right so I don't know how the PO is doing that uh I don't know the uh the ways that you are presenting those ideas I don't know how those conversations are going so maybe you're presenting them and so youve had the opportunity to share but at the end of that the PO is not getting the value out of that right so there's a couple other details you can continue to add them to the chat if you want so that I'm not going off the rails here explaining it but ultimately I'd say first thing you need to make sure you have the opportunity to be able to discuss those ideas with the team and your
PO so that you have a chance to be heard obviously right if you're not getting a chance to be heard you will always feel frustrated by this let me switch my camera over too by the way one sec feel like I'm talking in code but here we go this is me um so having the chance to be in front of the PO is important and your teammates because this is going to tie into some of the next part but like it's all about like not okay it's not all about this but a big part of it is being able to sell your ideas right you need to be in a position where your idea can be conveyed to someone and they can understand the value of it the reason I wanted to back up and say it's not all about that is because it's very
possible and more often than not our ideas are not the best ideas even though we feel that way generally what happens is we have ideas that could be good but not best and other people also have good ideas but not best and when we come together and talk about those things that's where we come up with again maybe not the best but a better version of those ideas right we can take bits and pieces we can have better understanding from different perspectives and move forward on that so where am I going with this get in front of the PO get in front of your team right if you have ideas about how things should be working whether they're implementation Direction strategy whatever it happens to be one of the best things that you can do is get buyin from other people on the team and
I say this not because it's like um it's not about like being manipulative right you're not like trying to like sneak in on the team and be like hey I got this good idea and like can I get your vote like not not necessarily like that I'm obviously being a little bit vicious here but the the idea is not to like try and manipulate people decid with you because part of it is you need to vet whether or not your idea is good in the first place and this is hard because like I said we're usually like man I got this good idea like I'm pretty confident this is the way to go but like how do you know you might have data but do you have all the data I'm not saying your team has all the data but a good way to go
about things is getting feedback from people on the team so that might mean talking with someone more senior a peer someone who's kind of working in the same area or has seen some things before and saying hey like I got some information some some details about this I got some thoughts what do you think about this right having a small conversation picking their brain doing that with one or two people and then going cool like now I might be in a position where I can articulate this better right I've had this conversation with a couple people seen things a bit different I don't know this is different on every team like design doc like one pager whatever that happens to be um if you have meetings where you can just bring this stuff up but however that works in your team and if it doesn't
work maybe come up with some new ideas you can propose but finding a way to capture those thoughts and this is where the the selling part comes in you want to be able to articulate the value of what you're proposing to the target audience if the target audience in this case is the PO because now you've kind of gotten some feedback from your peers Target a audience is the PO how do you convince the PO that this is a good idea and the goal again is not at the end of the the goal at the end of the day is not to say hey look I was right we picked my idea Victory right the goal at the end of the day is hey our business is doing better and our customers are happy that's it like there is no you in that equation right
you are part of the business the business is going to do better and our customers are happy if that means that your idea was selected great that's cool if your idea was not selected that's okay too but you should feel comfortable leaving that and saying hey I understand why the business went in this direction so when you need to sell ideas to the PO again it's not to be able to say hey look I won it's to be able to say product owner I need to understand the things that you value and prioritize this is also on the uh the product owner and I would say your engineering manager to be able to convey the value of the business to the engineers because if there's misalignment there that causes a lot of friction right that's happens a lot with tech debt I'd say like Engineers
are very much like hey like we got to fix this we got to fix this and sometimes product owners are like no no we don't and people go well we can't leave the code like this and someone will say the code's been like that for 10 years and no one's complained so yeah we can like it literally has not been a problem so context but moral the story is communication I think is what it comes down to uh the context is important let me know if you have any more thoughts or questions on that like if you have other details and you're like hey like this might help maybe we can steer it back add it to the chat I'm happy to kind of go back to it okay um configure a weight uh significance on performance okay so configure weight false this is a
really messy one I don't even know if I'm going to be able to explain it properly so I apologize let me go back to the code it's funny I bought this Elgato stream deck and I it's sitting beside me and I don't know what buttons to press so I'm just like kind of flopping around here trying to switch stuff I got to get better at the streaming thing but that'll come so it should be this one here cool so you see this type of thing with configure await okay what is configure await mean why do we do it well configure await what it does is allows you especially with false by the way so configure a wait allows you to tell the scheduler once you are done awaiting and given context back so we can continue execution what thread should I be on the sounds
kind of weird if you have configured if you omit it when you resume it will be whatever thread started this call right so if you're running about to run line 261 and you were on thread a if you didn't have this as soon as this has been awaited and come back and you can keep executing you'll be back on thread a now configure weight false allows you to say I don't care what thread resumes the work after if that means that a different thread that's freed up from theuer can go do it that's fine so where this comes up a lot and by the way that might not be fully accurate I'm just trying to give you some some things to kind of consider because if you want to go read about this more please do I recommend it because async away can get a
little bit uh a little bit complex by a little bit I mean a lot of bit um as soon as you start diving into things but where this comes up a lot is especially with user interface applications so Wind forms WPF Maui like anything where you're dealing with a user interface this becomes very critical I'm not saying it's the only place but it becomes very critical there because there is auler that has to figure out things like the main thread for user interface updates if you have only been programming in uh web applications for example this might not be obvious um but when you're doing user interface applications there is one main thread that's responsible for painting and updating the user interface and this is just a pattern that's been used for basically forever I don't know all the details behind why but I think
it has to do with essentially listening for like operating system updates and the way that a lot of that can work so things like getting click events and keyboard events I don't know how that has not evolved more over time but historically I believe that's where it comes from like this message pump and from there you have this one thread for your main thread if you want to go do async stuff now what happens is if you had a button to click right so you click a button Let's Pretend This is an event handler for a button okay if you click the button you might want to go do some work right asynchronously if you didn't have configure weight so let's pretend this is gone on this line here it would mean that once this came back line 260 would start on the main thread
because if you had main thread here you would also have main thread here okay and sometimes this is really important for user interface applications because if this code was about to go update the user interface you would really want to make sure that this was still running on the main thread because if not like I was saying you might not know this if you haven't worked in user interface applications but it would say like a cross thread exception like it would crash your program so you need to make sure that it comes back on your main thread for a user interface update if it was still more background work you might not care so oops let me put that back if you put configure weight in you're saying I don't care what thread picks up the work after just like start going so this can
be really helpful if you truly don't care what thread is picking this up so a lot of the time uh when we're dealing with uh you'll you'll see the advice around this is like if you are building Library code then try to use configure weight and the reason they say that is because Library code could be consumed by a user interface application and you can you can get more Effectiveness out of that by not kind of saying oh go keep doing this on the main thread it's like just let me do this work on whatever thread is available to do it so the schedu has more freedom right but you don't want that freedom always in a user interface application so you need to make sure that you're running user interface updates on the right thread so I hope that helps a little bit it's
a little bit confusing um even the the C course I put out on dome train I have to start plugging more of my stuff right but I have a deep dive course on dome train for C and I talk about asyn co8 I don't think I go into the configur weight stuff in detail because it's like it becomes it's not just like a service level thing you have to really get into like understanding why so um in asp.net core applications I think the the way that the scheduling works anyway is that it's not going to force resuming on the same thread it just kind of picks any thread I believe um so like there is no Advantage as far as I understand there's no advantage to having configure await false in an application like this but like I said I get in the habit of
doing it because if I go refactor stuff out into a sharable library it's already done I don't have to go oh crap let me go find all of these async calls and put configure A8 false on them so I just kind of saved my saw for that okay um at this point I don't have the details I don't think for what I want to put here this is going to be marking the completed one I have to think about my spreadsheet schema and I don't want to necessarily just pull it all up on stream CU I don't want all my my priv details showing um but I I have a column I just don't know which one it is and this is going to be an interesting one too because I need to say what column I want to start at actually this will be
fine so I think all that I need to do in this one is update one single cell and I don't know which column so I have this column that's like something like last last updated time or something like that and what I'm going to need to do is figure out what index that is it's not one it might be something like five or something like that and then I would want to do um so you I should be clear here almost always I use UTC when I'm building stuff but um and the reason for that is because you don't know what time zone you're in so kind of just normalize to UTC uh especially if you're dealing with like web applications and different uh geographies however the difference here is that what I'm doing for my own application is like I'm only using Google Sheets
because it's a really convenient way for me to like not go open up a database I forgot I was going to go back and talk about the interfaces let me explain this one and then we're going to talk about the interfaces because it's a good segue um I don't want UTC though because I want to work in my local time and I'm not in UTC so that's why I'm doing it this way um I want hours minutes and seconds as well so I have this cell basically that tracks whether or not this work has been done I have to go find out which position it is so I'll go do that later but I'm just going to write in when I finish doing this work pretty simple but I have to come back to this at this point the workflow that I was trying to
build is done because I have deleted a file that I copied which was earlier in the workflow and this cell I was actually using to see if there's no entry there then I know that I need to go run this code so now I can say mark this one is done and this is really like a flag in a spreadsheet that says you've done this work already you don't have to revisit it again okay let's talk about these interfaces before I forget one more time so what came up earlier while I was streaming here was I said these are kind of kind of dumb kind of Overkill kind of pointless now but I wanted to talk about where they came from uh I don't need to be in code I want to talk with my hands a little bit so let me go back to
here you can see my pretty face so um the idea was that I've been talking about how I have stuff in Google Drive right I have some a Google sheet to track stuff I have files in Google Drive um and when I went to go write this code I said I know that I need to go write code that will go work with Google Drive Google Sheets um what what are you working on today hey well welcome um yeah so I mentioned a little bit earlier if you just joined obviously you wouldn't have got it but I'm just talking about building a a a tool for myself to help with social media content organiz ation because in particular for short form videos I use Google Sheets Google Drive for this kind of stuff it's pretty tedious for me there's a lot of moving stuff around
and I'm just writing a program that's going to help me do that automatically so I can basically put the files in the right spot to start with Mark them in a spreadsheet and then it will go move them to where they need to be so it's like an auto organizing thing the particular details about why I'm doing that I'm not really including here it's not really important but I'm spending time explaining the Google Sheets and Google drive apis and how I'm trying to navigate those to make them a little bit more clean so hopefully that helps but if you have more questions about what's going on in the Stream just let me know and I wanted to talk about the fact that I mean those are the current sources of data that I have but I don't think that I want them to be the
the storage and organization mechanism indefinitely like I am trying to plan and think about different ways to move away from those things because there's some other Integrations that become very manual for me to go do with respect to my content so the challenge is like yes Google Sheets and Google Drive have been awesome because I can do it for my phone I can do whatever I need to do it's like it's human readable right I can make updates I can type stuff in I don't have to go connect to a database and go you know do queries and stuff like that it's just super easy as a user and it seems kind of funny right because like if I'm Building Systems like why would I not go use a database it's because it wasn't a system but now that it's starting to become a system
I have this situation where I have all of this information in in Google Drive and if I want to start doing more Integrations with things and better organization I may want to move away from that so the reason that I started creating interfaces in the code was I was thinking do I need to start planning for basically like a a data source or a data destination that's not going to be Google Drive and Google Sheets so for example um I'm using Google Sheets right now for some of the metadata about the shorts but what if I wanted to move that to mongod DB or a SQL database like I was thinking if I go to write this code I should probably consider that it could have a different type of destination now the challenge that I noticed right away so I started kind of I
put the interfaces in place and I was like all of the data that I need to work with is so specific to Google Sheets and Google Drive and I don't even know how to build this yet I'm I'm basically jumping the gun to trying to put like an interface in place um because it's not going to have the right pieces on it so for example the the concept you saw me or un unless you just joined you didn't see this but I had to find and track a row ID that I want to go update and that was done earlier in the process but the concept of that row ID to go update makes literally no sense if I want to go move to a different data source right it just doesn't make sense or if you have something like a starting source that is
Google Sheets and Google Drive and an ending like destination that would be I'm just going to make this up maybe I want to even store the videos in mongodb as well I'm whatever right pick anything you want but it's not Google Drive and Google Sheets now I have these two things going on I need to make sure that like the way I would want to design this is that they don't care about where the source is right they they they shouldn't care about the other pieces but I'm not in position where I can go build a system to be swappable components yet and that's really what I wanted to get to is I think in the future I want to be able to swap out the components here but I don't know enough about the system I'm building to have swappable components so that's why
I started with the interfaces and quickly was like it's not going to be a good fit just get it working for now I can always refactor it later okay I I think I think that's all I wanted to go over for today cuz I just wanted to get that part working um so I'm not planning on streaming anymore for today just because like I still got to eat breakfast like maybe that's why I'm yawning I just kind of woke up and started doing this um for sure and by the way before I end the stream or whatever does anyone else have questions the chat and stuff's a little bit delayed but I'll hang out here for just a moment and let anyone ask uh if you want to if you want to ask anything else about either what you saw or just C or software
engineering or your career like let me know cuz I'm happy to hang around a little bit longer but the content that I wanted to go over is already done so just let me know but I'll kind of I'll be quiet and stare at the camera and you let me know if there's anything else you want to hear I still see a few people hanging on to the stream here so let me know oh sure okay so one question can learning C itself be enough to apply at Microsoft I'm starting your course on awesome well I hope you enjoy the course thank you for for checking that out um I would say like this is a it's a tricky question right I like Microsoft obviously is very heavy into c um but there's a bit of a loaded thing that you use there and it says
sorry you said like is it enough to apply at Microsoft and I would say it's actually not even required to apply at Microsoft which is why this question is tricky to answer so the a lot of the time I think people hyperfocus on languages or text stacks and I think can be very helpful by the way this is going to be very generic advice and there's going to be situations where this absolutely doesn't apply I can't it's impossible to give Universal advice that's accurate so I I need to give that disclaimer right my experience has been that with smaller companies with less budget where um say I'll give you an example 10 people at a company they hire one more right that's 10% of their Workforce right they're adding 10% of their Workforce with one person it makes a huge difference for that person to
be up and running as fast as possible so it's a lot more challenging for a small company to be able to afford ramping people up in technology and things like that it's not that they can't do it or that they shouldn't but like from a business perspective it's very challenging to be able to support that maybe they have a lot of investment money and they can afford to do it cool but if you're like self-funded maybe you're still trying to get uh you know you're still trying to get the like revenue from users and be profitable if you put yourself in that situation like we know we need to add a developer onto the team you're going to be picky about trying to find someone who can just hit the ground running and and get into it so I think especially for smaller companies it
makes a much bigger difference if you are ra into the Tex stack again not a requirement but I would just imagine from their perspective it's easier to bring someone on that has that versus sure we're going to spend three months ramping you up in a language you've never used okay so disclaimer it's not all companies certainly when I was hiring people at the startup I was working at before if you didn't know C you knew python Java like C++ like if you could program that's really all I cared about because on my team in particular I would I would spend time mentoring people in languages and stuff so um you know we could accommodate it but that's kind of start of that I know you're focused on Microsoft so let's talk about that for a sec um the two teams that I've been on at
Microsoft neither of them I have done hiring for because I have been part of the hiring of the team expansion so they were like we're going to scale this team we need an engineering manager so they would hire the people and the engineering manager me so I didn't do the hiring but what I can tell you is most if not all of the people I actually think it I might be able to say all of the people that were hired on to my teams as part of me being hired none of them knew C this is at Microsoft across two different teams so what does that mean um doesn't mean that they couldn't learn it doesn't mean they can't program it just means that they didn't need to have that skill and that's because uh and I wasn't in those interviews but the people that
were interviewing were able to gauge look this person has enough um like technical depth right they have experience in programming languages that are not totally random so they should be able to apply those skills into C they know that there's a ramp up period and the space we're in so like sure they can demonstrate these technical skills in these languages we can spend the time ramping them up so that's really how it panned out um that's a big belief of mine too is like you don't need to know a particular language we can spend the time teaching you um like it's really about mindset I would say as a bigger thing so if you're not coachable you're not open to to learning things like that becomes a challenge because then if you don't have the skill set how do we expect to teach you so
to to answer your question a little bit more more succinctly I think it's very helpful to have a C background because odds are you'll probably be using C you do want to check the jobs that you're applying for so I get of course like someone who works at Microsoft people are always like hey like can you refer me like like what what where can I like what teams like Can you hire me on this team like what teams are hiring like I'm not hiring and the only spot that I tell people to go cuz it's true is the careers page right check the job postings there watch for different job postings but check to see what kind of skills you're looking for C is going to be helpful there's no doubt right so I would say like and thank you again for doing my courses
I do appreciate that uh I think it will be helpful is it mandatory no it's just not because we've seen time and time again that if you know a programming language you can get ramped up in another one so um a lot of the concepts right so uh the World Ventures right the concepts that you would be learning from these things if you were if I'll give you another example I don't know your background so if C was your first programming language then I think you're doing the right stuff if you're like I already know Java I already know python I've done some C++ or whatever combination of these things right if you're like I know how to program I understand objectoriented programming I would say like if you're proficient in a language that's really what you're going to need in the first place to
kind of get by the technical part okay so it is your first language so yeah if that's your first language then I think you're like I said I think you're doing the right stuff then right the fact that you picked c as the first one and Microsoft is aligned with C because it's their language I think that's great now did it have to be C it didn't have to be in order to be able to have a chance at Microsoft just I think that's what I'm trying to draw um some perspective around so I do think it helps just not required um let me does that help answer your question I realize there's also like a ridiculous delay with the stream and stuff so sorry so awesome okay well I'm glad that helps cool um great I think I think that's it for the stream
then um so thanks for the questions I appreciate it uh I am going to be streaming again on Monday night uh Pacific time so 9:30 Pacific uh that's what I've been doing for the past few weeks this one was a little bit unique I just wanted to program this morning and I have to record YouTube videos today so I figured let's get comfortable in front of the camera before making some tutorials and uh yeah I hope this was kind of fun so thanks again and if you can join me Monday that'll be awesome it'll be the same same idea but I'm probably not doing code I'll be doing more of an AMA so uh if you didn't get a a chance to ask questions here Monday's your chance um if you want to submit questions and stuff ahead of time you know add comments onto
any post you want find me on Twitter LinkedIn Instagram whatever send me send me uh messages and let me know thank you so much I will see you Monday hopefully take
Frequently Asked Questions
What is the purpose of the helper methods you are creating for Google Sheets?
I'm creating helper methods to simplify the process of interacting with Google Sheets. These methods will allow me to update rows and manage data more intuitively, making it easier to work with the spreadsheet without getting bogged down by the complexities of the Google Sheets API.
Why do you find the Google Sheets API difficult to work with?
I find the Google Sheets API challenging because it doesn't operate like a traditional file system. Instead of using file paths, everything is identified by unique IDs, which can make it cumbersome to navigate and manage files and folders.
How do you handle exceptions when working with external APIs in your code?
I prefer to wrap my API calls in a helper method that uses a try-catch mechanism. This way, I can handle exceptions gracefully without crashing my application. It allows me to return a result indicating success or failure, along with any relevant error messages, without throwing exceptions that could disrupt the flow of my program.
These FAQs were generated by AI from the video transcript.