I don’t have any hard rules for things beyond whatever makes things easier to read. And I will move things around to get to the goal as I see fit (sometimes this can change over time - especially if you come back to something after a few months).
Generally speaking I would start with more global types at the top, though I might have some types next to the functions when they are only used by the function. And for functions I would start with main followed by functions main uses in rough order that they appear. With functions used by other functions below that functions - sometimes below others if I care more about the flow of higher functions more. Whatever I find makes it easier to read from top to bottom basically. I do the same with types, define the main ones first, then followed by types they use or types you will want to be aware of next. I don’t care what the type is - I don’t group enums together - they are all just types to me and it is often better to mix up their order based on how important they are rather than what type they technically are.
I really dislike how so many languages force you to do the reverse of this and declare things before you use them. IMO that is like reading a book starting at the last chapter and means you often have to skip over loads of things to figure out where the start is. Much better to have the most important part at the top of the file.
I don’t have any hard rules for things beyond whatever makes things easier to read. And I will move things around to get to the goal as I see fit (sometimes this can change over time - especially if you come back to something after a few months).
Generally speaking I would start with more global types at the top, though I might have some types next to the functions when they are only used by the function. And for functions I would start with main followed by functions main uses in rough order that they appear. With functions used by other functions below that functions - sometimes below others if I care more about the flow of higher functions more. Whatever I find makes it easier to read from top to bottom basically. I do the same with types, define the main ones first, then followed by types they use or types you will want to be aware of next. I don’t care what the type is - I don’t group enums together - they are all just types to me and it is often better to mix up their order based on how important they are rather than what type they technically are.
I really dislike how so many languages force you to do the reverse of this and declare things before you use them. IMO that is like reading a book starting at the last chapter and means you often have to skip over loads of things to figure out where the start is. Much better to have the most important part at the top of the file.