Whenever I need a struct, I flip a coin to decide if it should be above or below the one Iβm currently writing.
Order? I write them as I need them⦠is my code chaos, yes!
Enums/Structs first, but those 2 are mixed, and any impl for them will be directly after the definition of the type itsef. Free functions last.
I like to write them in blocks of concerns: ie there should be the minimum amount of jumping around the file when reading them. If there are a lot of these separate blocks in a single file, that is a good indication that it has grown enough and it is time to separate them into different files. But inside the blocks it would be usually struct/enums (no implicit order since they are just sum/product types), impl blocks, free functions (that are usually common functionality between the impl blocks).
I place them in that order, enums, structs, functions.