Hey there friends. So a while ago, I wrote well actually several years ago. I wrote a blog post called a newspaper code structure where I described the way that I like to structure my code to basically make it. I don't know easier for me to parse as I come into a new file and the idea is that anytime I have some sort of block of code that returns some value or whether that be a function or a module where your exporting values and stuff.
I always,Like to do the the thing that it returns or the exports at the very top of the file and the reason for this is in a newspaper article and they make it they write it so that they add just kind of a high level first and then they slowly fill in with details and the reason they do that is so or at least maybe they used to do that this way is so that you could clip the article at any point to size it for where it needs to be and it would still be coherent to make sense.
And in the same way I like to make my code so that it makes sense.Reading from the top down and if you need additional details then you can dive into the function there. And so what it ended up looking like is you'd have a function and like one of the first couple lines would be a return statement and then all of the guts of the function would be in a other functions that are below the return statement.
This is actually like a thing that you can do. You can define functions below a return statement and they will get hoisted the declaration and the definition will get hoisted above the return statement. So it technically actually works. So I did.The first for a long time but I eventually stopped doing this and the reason is because I I was bothered that I couldn't put the exports and the return statement at the very very first at the very very top because any time like so the the hoisting functionality I'm talking about that works for function declarations, but it will not work for arrow functions, it won't work for variable declarations.
So, I'd have to just put everything in enough function if I needed to use any variables and so what ended up happening.Was I'd have a couple of variables that I define at the top and then I never returned statement and then I'd have all the other functions or in a module I'd have you have to put all the import statements at the top.
Well, you don't have to those get hoisted too but it just looks funny if you don't. So I put all those at the top and then I have some variable declarations and stuff and then my exports and so what I ended up with was a return statement and the exports that were just like in the middle of all the code.
So now I just put everything at the bottom and it's easier to find. So, that's that's why I made that change. This is an answer to somebody in Discord. I hope you're having a great day. Bye.