Show notes
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 theway that I like to structure my code to basically make it. I don't knoweasier for me to parse as I come into a new file and the idea is thatanytime I have some sort of block of code that returns some value orwhether that be a function or a module where your exporting values andstuff.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 andthey make it they write it so that they add just kind of a high level firstand then they slowly fill in with details and the reason they do that is soor at least maybe they used to do that this way is so that you could clipthe article at any point to size it for where it needs to be and it wouldstill 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 intothe function there. And so what it ended up looking like is you'd have afunction and like one of the first couple lines would be a return statementand then all of the guts of the function would be in a other functions thatare 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 thedefinition will get hoisted above the return statement. So it technicallyactually works. So I did.The first for a long time but I eventually stoppeddoing this and the reason is because I I was bothered that I couldn't putthe exports and the return statement at the very very first at the veryvery top because any time like so the the hoisting functionality I'mtalking about that works for function declarations, but it will not workfor 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 ofvariables that I define at the top and then I never returned statement andthen I'd have all the other functions or in a module I'd have you have toput 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 variabledeclarations and stuff and then my exports and so what I ended up with wasa return statement and the exports that were just like in the middle of allthe 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 inDiscord. I hope you're having a great day. Bye.
