“Turn All Your Enums Into Bytes Now!” | Code Cop #014

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody I'm Nick and welcome to another episode of Code cop the series where we go over questionable advice given usually on places like LinkedIn Twitter or blogs and we try to turn it into good advice however today's advice is really really hard to turn into something good I think it's irredeemable on every single level and it actually made me genuinely mad because well it is quite frankly terrible advice and holy see Sharp how many people actually said yeah that's a good advice so in this video I want to bring that into your attention because please don't follow this if you like of content and you want to see more make sure you subscribe for more training check out my courses on don't train.com okay so what is the advice and why am I being crazy today well it's because I saw this so cop tip convert enams to Tiny int or bite now why is Tiny int used here and not the word bite I'll explain in a second but as you can see what the person is showing here is that you can actually make an enam appear like it's extending a bite and that basically changes its type and the obvious outcome of this is that now these numbers here the numbers of the enams represent a bite and not an integer even though you can still cast them back and forth to those types because they can be converted however this means that the size of the inum value it is not four bytes it is one byte because well an integer in a 64-bit system is 32 bits while a bite is I'm not going to explain memory in this video It Doesn't doesn't matter what matters is the advice given here that you should not use the default of an integer instead you should go ahead and optimize your inms by making them be bytes now let's take a look at the text accompanying this image because context matters so the text is this C tip convert enams to bite the default data type for enams when creating a table is int which may not be the most efficient option so immediately you turn this C tip into a SQL Server tip because now we're talking about tables and databases which is not presented in here at all other than the fact you use tiny in for bite which is only one way of representing numbers in SQL Server you have many many many other databases that can work with inam and different data types and you just use one so what the hell at least explain that you're doing this over here because this is a database thing and not really a c shop thing and then in continues that most inms only contain a few values storing them into integer columns waste space as each in column reserves seted two bits sure yes okay so what you're saying is that you've reached that level of optimization of your SQL Server where everything containing a string and bytes and everything has proper limits proper indexes proper everything the everything is optimized so perfectly that you're like oh I need to squeeze some more space and where do you land oh I'm going to turn my integers into bytes so what you're saying as well because that's the type of level of optimization you're going for is that on every column that you're storing a number you're starting with a bite then you have alerts to let you know you're reaching the limit of 255 and then you go ahead and you increase it to a short and then you go from a short to an integer and then come on in C bite is an immutable value type that accepts values in the range of 0 to what do you mean immutable value type value type are the value itself like why does this bother me so much SQL server has a matching type the tiny int data type and this allows for more efficient storage of inam values so you're saying that by using a bite for an inum which by the way I should point out is a very uncommon type you don't really see many many many many many many many many inms you will save three bytes per usage on what your gigabytes of store like what are you storing just inms what is happening how is this real advice and what infuriates me is not just the content is also the reaction the oh my God I did not expect it let's take a look at some comments but wow that's too depressing why don't I just brighten the mood a bit by letting you know we just launched a brand new course on D train called from Zero to Hero kubernetes for developers expert educator dun Clark comes back after his doer for developers course to teach us how to use kubernetes and oh my God is that course fantastic it is actually how I refresh my memory in kubernetes and I learned quite a few more things done takes you from knowing nothing about kubernetes all the way into actually being able to run and deploy things in production so I highly recommend you check that course and the first to hand of you can use discount code Cube 20 a checkout for 20% off don't miss this opportunity these do go very quickly now back to misery wow storing an integer just for a small range of 0 to 5 away bothered me I can guarantee you that I can just walk into any of your codebase or any of your database and I will find so so much waste of memory you can't even one one fix I will find one fix on anything in your code that fixing that will make more of a difference on a running time of a year for your application than you ever wasting three bytes for that bite debate then another glorious one every bit counts well yeah if you're sending people to mass probably but even then they're running python for that helicopter don't they so I don't think that even for that every bit counts like we we have we'll be fine guys we have memory but this one by far is my favorite because it reads okay so this is a comment right and the reply is absolutely utilizing the tiny int data type in SQL server for inam values is indeed a smart smart optimization it not only conserves storage space but also enhances efficiency especially when dealing with inam that Encompass a limited range of values this approach aligns perfectly with the principle of using the most for the hand now if you're paying attention this certainly sounds a bit robotic so I'm curious what I'm going to do is I'm going to copy paste all this text and then I'm going to go to chat gvt and I'm going to say write me a reply for a linked post that has this content and I'm going to just paste the text let's see what happens absolutely spot on inam times with limited value types indeed benefit greatly from being stored like tell me how this does not read the exact same way I can 100% guarantee you that this person and by the way from what I've seen many many people do this they come to chat GPT they just post the text and generate depes to drive engagement and I'm also very very certain that most of the posts themselves are AI generated holy is LinkedIn a terrible place to get advice seriously don't get any of your advice on LinkedIn and by the way do you know who also doesn't do this Microsoft like you can go in their code bases like the net runtime itself the SDK or so on the CLI and you will see that they don't do this like you have things like build platform for the CLI and yeah okay this is not something that needs to be optimized like very tightly but even then couldn't they just use a bite here yeah they could well they didn't couldn't they use a bite let's say here couldn't they use a bite here here here here here everywhere yeah they didn't do that and they didn't do it because it's just it's dumb yeah if something is like absolutely vital and emergency level of performance critical then maybe you'll find it maybe some Json seral izer has it for example but please please please please don't do this this is the most infuriated I've been in this series and actually Haven seen other post from that profile I think I'm going to be more infuriated in the future and thank you for sending this by the way this is coming from a suggestion from you so if you have posts like this please message me on LinkedIn or email me or whatever and I will put this into a video because we have to start calling these things out publicly we cannot just have advice like this being seen by starters because they're going to just start writing bad code but what do you think what do you think about this advice am I on the wrong here am I on the right please let me know in the comments down below well that's all I have for you for this video thank you very much for watching and as always keep coding
Info
Channel: Nick Chapsas
Views: 33,933
Rating: undefined out of 5
Keywords: Elfocrash, elfo, coding, .netcore, dot net, core, C#, how to code, tutorial, development, software engineering, microsoft, microsoft mvp, .net core, nick chapsas, chapsas, dotnet, .net, code cop, Turn All Your Enums Into Bytes Now, code cop nicik, code cop nick chapsas
Id: 1gWzE9SIGkQ
Channel Id: undefined
Length: 8min 43sec (523 seconds)
Published: Mon Mar 18 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.